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:
  1. 2007-2024 by the Inyoka Team, see AUTHORS for more details.

license:

BSD, see LICENSE for more details.

class inyoka.markup.templates.Add(left, right)
operation(b, /)

Same as a + b.

class inyoka.markup.templates.And(left, right)
evaluate(context)
class inyoka.markup.templates.Bin(left, right)
evaluate(context)
operation = None
class inyoka.markup.templates.BinaryFunction(left, right, func)
evaluate(context)
class inyoka.markup.templates.Cmp(op, left, right)
class inyoka.markup.templates.Compound(nodes)
stream_markup(context)
class inyoka.markup.templates.Concat(left, right)
operation(b, /)

Same as a & b.

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.ConverterFunction(expr, func)
evaluate(context)
class inyoka.markup.templates.Data(markup)
stream_markup(context)
class inyoka.markup.templates.Div(left, right)
operation(b, /)

Same as a / b.

class inyoka.markup.templates.Expr
evaluate(context)
stream_markup(context)
class inyoka.markup.templates.For(var, seq, body)
stream_markup(context)
class inyoka.markup.templates.GetItem(expr, item)
evaluate(context)
class inyoka.markup.templates.If(tests, else_body)
stream_markup(context)
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.Mod(left, right)
operation(b, /)

Same as a % b.

class inyoka.markup.templates.Mul(left, right)
operation(b, /)

Same as a * b.

class inyoka.markup.templates.Neg(expr)
evaluate(context)
class inyoka.markup.templates.Node
stream_markup(context)
to_markup(context)
class inyoka.markup.templates.Or(left, right)
evaluate(context)
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)
class inyoka.markup.templates.Sub(left, right)
operation(b, /)

Same as a - b.

class inyoka.markup.templates.Template(body)
stream_markup(context)
exception inyoka.markup.templates.TemplateSyntaxError(message)

Helper for the parser. Translates into a node in the parsing process.

get_node()
class inyoka.markup.templates.TestFunction(expr, func, negated)
evaluate(context)
class inyoka.markup.templates.Value(value)
evaluate(context)
property is_array
property is_number
property is_object
property is_string
class inyoka.markup.templates.Var(name)
evaluate(context)
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)