File: main_sample.py

package info (click to toggle)
mkdocs-macros-plugin 1.4.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 336 kB
  • sloc: python: 1,235; makefile: 4
file content (56 lines) | stat: -rw-r--r-- 1,277 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# --------------------------------------------
# This is a test file and example of how functions file should be defined
# By default it should be called 'main.py'
# Or in a file of a properly defined python package called 'main'.
# It is actually used by module_reader.py
# --------------------------------------------

def define_env(env):
    """
    This is the hook for declaring variables, macros and filters (new form)
    """
    env.variables['baz'] = "John Doe"

    @env.macro
    def bar(x):
        return (2.3 * x) + 7



    # If you wish, you can  declare a macro with a different name:
    def f(x):
        return x * x

    f = env.macro(f, 'barbaz')


    # define a filter
    @env.filter
    def reverse(x):
        "Reverse a string (and uppercase)"
        return x.upper()[::-1]



def declare_variables(variables, macro):
    """
    This is the hook for the functions (OLD FORM)
    Prefer define_env

    - variables: the dictionary that contains the variables
    - macro: a decorator function, to declare a macro.
    """

    variables['baz'] = "John Doe"

    @macro
    def bar(x):
        return (2.3 * x) + 7



    # If you wish, you can  declare a macro with a different name:
    def f(x):
        return x * x

    f = macro(f, 'barbaz')