webkit  2cdf99a9e3038c7e01b3c37e8ad903ecbe5eecf1
https://github.com/WebKit/webkit
Public Member Functions | List of all members
htmltmpl.TemplateProcessor Class Reference

Public Member Functions

def __init__ (self, html_escape=1, magic_vars=1, global_vars=0, debug=0)
 
def set (self, var, value)
 
def reset (self, keep_data=0)
 
def process (self, template, part=None)
 
def DEB (self, str)
 PRIVATE METHODS #. More...
 
def find_value (self, var, loop_name, loop_pass, loop_total, global_override=None)
 
def magic_var (self, var, loop_pass, loop_total)
 
def escape (self, str, override="")
 
def is_ordinary_var (self, var)
 

Detailed Description

Fill the template with data and process it.

    This class provides actual processing of a compiled template.
    Use it to set template variables and loops and then obtain
    result of the processing.

Constructor & Destructor Documentation

◆ __init__()

def htmltmpl.TemplateProcessor.__init__ (   self,
  html_escape = 1,
  magic_vars = 1,
  global_vars = 0,
  debug = 0 
)
Constructor.

    @header __init__(html_escape=1, magic_vars=1, global_vars=0,
             debug=0)

    @param html_escape Enable or disable HTML escaping of variables.
    This optional parameter is a flag that can be used to enable or
    disable automatic HTML escaping of variables.
    All variables are by default automatically HTML escaped. 
    The escaping process substitutes HTML brackets, ampersands and
    double quotes with appropriate HTML entities.
    
    @param magic_vars Enable or disable loop magic variables.
    This parameter can be used to enable or disable
    "magic" context variables, that are automatically defined inside
    loops. Magic variables are enabled by default.

    Refer to the language specification for description of these
    magic variables.
      
    @param global_vars Globally activate global lookup of variables.
    This optional parameter is a flag that can be used to specify
    whether variables which cannot be found in the current scope
    should be automatically looked up in enclosing scopes.

    Automatic global lookup is disabled by default. Global lookup
    can be overriden on a per-variable basis by the
    <strong>GLOBAL</strong> parameter of a <strong>TMPL_VAR</strong>
    statement.

    @param debug Enable or disable debugging messages.

Member Function Documentation

◆ DEB()

def htmltmpl.TemplateProcessor.DEB (   self,
  str 
)

PRIVATE METHODS #.

Print debugging message to stderr if debugging is enabled.
    @hidden

◆ escape()

def htmltmpl.TemplateProcessor.escape (   self,
  str,
  override = "" 
)
Escape a string either by HTML escaping or by URL escaping.
    @hidden

◆ find_value()

def htmltmpl.TemplateProcessor.find_value (   self,
  var,
  loop_name,
  loop_pass,
  loop_total,
  global_override = None 
)
Search the self._vars data structure to find variable var
    located in currently processed pass of a loop which
    is currently being processed. If the variable is an ordinary
    variable, then return it.
    
    If the variable is an identificator of a loop, then 
    return the total number of times this loop will
    be executed.
    
    Return an empty string, if the variable is not
    found at all.

    @hidden

◆ is_ordinary_var()

def htmltmpl.TemplateProcessor.is_ordinary_var (   self,
  var 
)
Return true if var is a scalar. (not a reference to loop)
    @hidden

◆ magic_var()

def htmltmpl.TemplateProcessor.magic_var (   self,
  var,
  loop_pass,
  loop_total 
)
Resolve and return value of a magic variable.
    Raise an exception if the magic variable is not recognized.

    @hidden

◆ process()

def htmltmpl.TemplateProcessor.process (   self,
  template,
  part = None 
)
Process a compiled template. Return the result as string.

    This method actually processes a template and returns
    the result.

    @header process(template, part=None)
    @return Result of the processing as string.

    @param template A compiled template.
    Value of this parameter must be an instance of the
    <em>Template</em> class created either by the
    <em>TemplateManager</em> or by the <em>TemplateCompiler</em>.

    @param part The part of a multipart template to process.
    This parameter can be used only together with a multipart
    template. It specifies the number of the part to process.
    It must be greater than zero, because the parts are numbered
    from one.

    The parts must be processed in the right order. You
    cannot process a part which precedes an already processed part.

    If this parameter is not specified, then the whole template
    is processed, or all remaining parts are processed.

◆ reset()

def htmltmpl.TemplateProcessor.reset (   self,
  keep_data = 0 
)
Reset the template data.

    This method resets the data contained in the template processor
    instance. The template processor instance can be used to process
    any number of templates, but this method must be called after
    a template is processed to reuse the instance,

    @header reset(keep_data=0)
    @return No return value.

    @param keep_data Do not reset the template data.
    Use this flag if you do not want the template data to be erased.
    This way you can reuse the data contained in the instance of
    the <em>TemplateProcessor</em>.

◆ set()

def htmltmpl.TemplateProcessor.set (   self,
  var,
  value 
)
Associate a value with top-level template variable or loop.

    A template identifier can represent either an ordinary variable
    (string) or a loop.

    To assign a value to a string identifier pass a scalar
    as the 'value' parameter. This scalar will be automatically
    converted to string.

    To assign a value to a loop identifier pass a list of mappings as
    the 'value' parameter. The engine iterates over this list and
    assigns values from the mappings to variables in a template loop
    block if a key in the mapping corresponds to a name of a variable
    in the loop block. The number of mappings contained in this list
    is equal to number of times the loop block is repeated in the
    output.
      
    @header set(var, value)
    @return No return value.

    @param var Name of template variable or loop.
    @param value The value to associate.

The documentation for this class was generated from the following file: