Tayra

Template. Script. Distribute

interfaces – Interfaces for language extension

Tayra uses pluggdapps component system, and heavily based on plugins. The lexer and parser are just a glue logic over a very sophisticated plugin framework which does most of the language level heavy lifting. This modules contains all the interface specifications that matters to tayra language implementation.

Module contents

class tayra.interfaces.ITayraTags[source]

Bases: pluggdapps.plugin.Interface

Interface specification to translate template tags to HTML tags. Plugins implementing this interface is defined under tayra.tags package. It is possible for developers to implement their own plugins to translate template tags just by configuring tayra.compiler.TTLCompiler plugin.

handle(mach, tagname, tokens, styles, attributes, content)[source]

Called during runtime, translates tayra tag into HTML tags. Returns html string.

mach,
Stackmachine.
tagname,
Name of the tag.
tokens,
List of tokens inside tag specification.
styles,
List of CSS style parameters applicable on the tag.
attributes
List of HTML attributes.
content,
Descendants of this tag in plain string.
class tayra.interfaces.ITayraExpression[source]

Bases: pluggdapps.plugin.Interface

Interface specification to handle expressions within template script. IMPORTANT : Plugins implementing this interface should have its name prefixed with ‘TayraExpression’. For instance a plugin implementing python expression evaluation will look like, ExpressionPy, and in the template script this plugin can be referred as,:

${-py <python-expression>}
eval(mach, text, globals_, locals_)[source]

Evaluate text expression in the context of globals_ and locals_. Return evaluated expression converted to a string. This string will be substituted in the place where the expression is refered.

mach,
is stack-machine instance.
filter(mach, name, text)[source]

Inside the template script, filtering is applied on the expression result using the following syntax,:

${ ... | <filters> }

Stack machine mach will parse <filter> spec and call this method along with evaluated text.

mach,
is stack-machine instance.
name,
name of the filter.
text
text, result of expression substitution, to be filtered.

If filter name is successfully applied return filterted text, else return None.

class tayra.interfaces.ITayraFilterBlock[source]

Bases: pluggdapps.plugin.Interface

Interface specification for filter blocks to handle blocks of template code that does not follow indentation rules, can potentially have a separate syntax to themself and they can take part in multi-pass compilation.

generate(igen, node, result, *args, **kwargs)[source]

Will be called during the generate phase, traversing AST. Can optionally return a value which will then be passed to tailpass.

igen,
object to generate instructions.
node
Passes the FilterBlock node instance. Refer to the class documentation to learn more about the node defintion.
result,
Result from headpass2().
headpass1(igen, node)[source]

Will be called during the headpass phase 1, traversing AST. Can optionally return a value which will then be passed to headpass2.

igen,
object to generate instructions.
node
Passes the FilterBlock node instance. Refer to the class documentation to learn more about the node defintion.
headpass2(igen, node, result)[source]

Will be called during the headpass phase 2, traversing AST. Can optionally return a value which will then be passed to generate.

igen,
object to generate instructions.
node
Passes the FilterBlock node instance. Refer to the class documentation to learn more about the node defintion.
result,
Result from headpass1().
tailpass(igen, node, result)[source]

Will be called during the tailpass phase, traversing AST. Can optionally return a value which will then be passed to tailpass.

igen,
object to generate instructions.
node
Passes the FilterBlock node instance. Refer to the class documentation to learn more about the node defintion.
result,
Result from headpass2().

Table Of Contents

Related Topics

This Page