Markup Templates
inyoka.markup.templates
This module implements the templating language for the Wiki. It’s a very simple language with some syntax elements taken from both Python and PHP.
The following syntax elements exist:
<@ for $author in $authors @>
* <@ $author @>
<@ endfor @>
<@ if $author == current_page @>
* '''$author'''
<@ else @>
* [:$author:]
<@ endif @>
The start tags (<@
) delete one leading newline.
- copyright:
2007-2024 by the Inyoka Team, see AUTHORS for more details.
- license:
BSD, see LICENSE for more details.
- class inyoka.markup.templates.Cmp(op, left, right)
- class inyoka.markup.templates.Context(items=())
Creates a context of values out of a list of tuples in the form
(key, value)
.Example:
[('foo.0', 1), ('foo.1', 2), ('foo.2.a', 1), ('foo.2.b', 2), ('bar', 23), ('baz', "blub")]
Converts internally to:
{'foo': Value([1, 2, Value({'a': Value(1), 'b': Value(2)})]), 'bar': Value(23), 'baz': Value("blub")}
- pop()
- push()
- class inyoka.markup.templates.Lexer
Tokenize template code.
- _tokenize(code)
- rules = {'root': ((re.compile('\\n?<@'), 'tag_begin', 'tag'), (re.compile('^##.*?(\\n|$)(m)'), None, None)), 'tag': ((re.compile('@>'), 'tag_end', 1), (re.compile('(?m)#.*?$', re.MULTILINE), None, None), (re.compile('\\s+'), None, None), (re.compile('\\d+(\\.\\d*)?'), 'number', None), (re.compile('(?s)(\'([^\'\\\\]*(?:\\\\.[^\'\\\\]*)*)\'|"([^"\\\\]*(?:\\\\.[^"\\\\]*)*)")', re.DOTALL), 'string', None), (re.compile('(<=?|>=?|=>|[!=]?=)|[()\\[\\]&.,*%/+-]'), 'operator', None), (re.compile('\\$[^\\W\\d][^\\W]*'), 'variable', None))}
- tokenize(code)
- class inyoka.markup.templates.Parser(code)
Parse template code.
- parse()
- parse_add()
- parse_and()
- parse_binary_function()
- parse_cmp()
- parse_concat()
- parse_convert()
- parse_div()
- parse_expr()
- parse_for()
- parse_getitem(node)
- parse_if()
- parse_mod()
- parse_mul()
- parse_neg()
- parse_or()
- parse_postfix(node)
- parse_primary()
- parse_sub()
- parse_test()
- subparse(test, drop_needle=True)
- exception inyoka.markup.templates.TemplateSyntaxError(message)
Helper for the parser. Translates into a node in the parsing process.
- get_node()
- class inyoka.markup.templates.Value(value)
- evaluate(context)
- property is_array
- property is_number
- property is_object
- property is_string
- inyoka.markup.templates.expand_page_template(template, context, macro_behavior=False)
A helper for the template macro and wiki-parser.
- inyoka.markup.templates.process(source, context=())
Parse and evaluate a template.
- inyoka.markup.templates.rule(regexp, tokentype=None, enter=None, leave=None)
- inyoka.markup.templates.ruleset(*args)