SUIT Framework

Scripting Using Integrated Templates

Docs - tokens

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

Available Since: SUIT (2.0.0)

Generate the tokens from the string. Tokens contain the different open and close strings and their positions.

Syntax list suit.tokens ( dict rules, str string [, dict config ] )
Parameters
rules

The rules containing the strings to search for.

string

The string to find the strings in.

config

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

Return Value

A list of dicts with the following format:

Key Description
bounds dict
Key Description
start int: Where the string starts.
end int: Where the string ends.
string str: The located string.
type str: The type, options being open, close, or flat.
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);
/*
Result: array
(
    array
    (
        'bounds' => array
        (
            'end' => 20,
            'start' => 15
        ),
        'string' => '[var]',
        'type' => 'open'
    ),
    array
    (
        'bounds' => array
        (
            'end' => 34,
            'start' => 28
        ),
        'string' => '[/var]',
        'type' => 'close'
    )
)
*/
?>
Python
import suit
from rulebox import templating
templating.var.username = 'Brandon'
tokens = suit.tokens(templating.rules, template)
# Result: [
#     {
#         'bounds':
#         {
#             'end': 20,
#             'start': 15
#         },
#         'string': '[var]',
#         'type': 'open'
#     },
#     {
#         'bounds':
#         {
#             'end': 34,
#             'start': 28
#         },
#         'string': '[/var]',
#         'type': 'close'
#     }
# ]
See Also