SUIT Framework

Scripting Using Integrated Templates

Docs - parse

12/27/2015: SUIT Framework is no longer actively maintained.

Available Since: SUIT (2.0.0)

Generate the tree from the tokens and string. The tree will show how the string has been broken up and how to transform it.

Syntax dict suit.parse ( dict rules, dict pos, str string [, dict config ] )
Parameters
rules

The rules used to break up the string.

pos

A list of the positions of the various open and close strings.

string

The string to break up.

config

Specifics on how the function should work. (Optional. Default: see defaultconfig)

Return Value

{
    "closed": true // Shown if this node has been closed.
    "contents":
    [
        "string",
        {
            "closed": true
            "contents": ["etc."],
            "create": " condition=\"var\"", // The contents of the create rule if applicable.
            "createrule": "[if condition=\"var\"]", // The whole create rule statement if applicable.
            "rule": "[if]" // The type of rule
        },
        "etc."
    ] // This node's branches.
}

Examples
Basic Usage
Template
Hello, <strong>[var]username[/var]</strong>!
PHP
<?php
require 'suit.class.php';
require 'templating.class.php';
$suit = new SUIT();
$templating = new Templating($suit);
$templating->var->username = 'Brandon';
$tokens = $suit->tokens($templating->rules, $template);
$tree = $suit->parse($templating->rules, $tokens, $template);
/*
Result: array
(
    'closed' => true,
    'contents' => array
    (
        'Hello, <strong>',
        array
        (
            'closed' => true,
            'contents' => array('username'),
            'rule' => '[var]'
        ),
        '</strong>!'
    )
)
*/
?>
Python
import suit
from rulebox import templating
templating.var.username = 'Brandon'
tokens = suit.tokens(templating.rules, template)
tree = suit.parse(templating.rules, tokens, template)
# Result: {
#     'closed': True,
#     'contents':
#     [
#         'Hello, <strong>',
#         {
#             'closed': True,
#             'contents': ['username'],
#             'rule': '[var]'
#         },
#         '</strong>!'
#     ]
# }
See Also