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

CLASS: TemplateManager #. More...

Public Member Functions

def __init__ (self, include=1, max_include=5, precompile=1, comments=1, gettext=0, debug=0)
 
def prepare (self, file)
 
def update (self, template)
 
def DEB (self, str)
 PRIVATE METHODS #. More...
 
def lock_file (self, file, lock)
 
def compile (self, file)
 
def is_precompiled (self, file)
 
def load_precompiled (self, file)
 
def save_precompiled (self, template)
 

Detailed Description

CLASS: TemplateManager #.

Class that manages compilation and precompilation of templates.

     You should use this class whenever you work with templates
     that are stored in a file. The class can create a compiled
     template and transparently manage its precompilation. It also
     keeps the precompiled templates up-to-date by modification times
     comparisons. 

Constructor & Destructor Documentation

◆ __init__()

def htmltmpl.TemplateManager.__init__ (   self,
  include = 1,
  max_include = 5,
  precompile = 1,
  comments = 1,
  gettext = 0,
  debug = 0 
)
Constructor.

    @header
    __init__(include=1, max_include=5, precompile=1, comments=1,
     gettext=0, debug=0)
    
    @param include Enable or disable included templates.
    This optional parameter can be used to enable or disable
    <em>TMPL_INCLUDE</em> inclusion of templates. Disabling of
    inclusion can improve performance a bit. The inclusion is
    enabled by default.
      
    @param max_include Maximum depth of nested inclusions.
    This optional parameter can be used to specify maximum depth of
    nested <em>TMPL_INCLUDE</em> inclusions. It defaults to 5.
    This setting prevents infinite recursive inclusions.
    
    @param precompile Enable or disable precompilation of templates.
    This optional parameter can be used to enable or disable
    creation and usage of precompiled templates.
      
    A precompiled template is saved to the same directory in
    which the main template file is located. You need write
    permissions to that directory.

    Precompilation provides a significant performance boost because
    it's not necessary to parse the templates over and over again.
    The boost is especially noticeable when templates that include
    other templates are used.
    
    Comparison of modification times of the main template and all
    included templates is used to ensure that the precompiled
    templates are up-to-date. Templates are also recompiled if the
    htmltmpl module is updated.

    The <em>TemplateError</em>exception is raised when the precompiled
    template cannot be saved. Precompilation is enabled by default.

    Precompilation is available only on UNIX and Windows platforms,
    because proper file locking which is necessary to ensure
    multitask safe behaviour is platform specific and is not
    implemented for other platforms. Attempts to enable precompilation
    on the other platforms result in raise of the
    <em>TemplateError</em> exception.
    
    @param comments Enable or disable template comments.
    This optional parameter can be used to enable or disable
    template comments.
    Disabling of the comments can improve performance a bit.
    Comments are enabled by default.
    
    @param gettext Enable or disable gettext support.

    @param debug Enable or disable debugging messages.
    This optional parameter is a flag that can be used to enable
    or disable debugging messages which are printed to the standard
    error output. The debugging messages are disabled by default.

Member Function Documentation

◆ compile()

def htmltmpl.TemplateManager.compile (   self,
  file 
)
Compile the template.
    @hidden

◆ DEB()

def htmltmpl.TemplateManager.DEB (   self,
  str 
)

PRIVATE METHODS #.

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

◆ is_precompiled()

def htmltmpl.TemplateManager.is_precompiled (   self,
  file 
)
Return true if the template is already precompiled on the disk.
    This method doesn't check whether the compiled template is
    uptodate.
    @hidden

◆ load_precompiled()

def htmltmpl.TemplateManager.load_precompiled (   self,
  file 
)
Load precompiled template from disk.

    Remove the precompiled template file and recompile it
    if the file contains corrupted or unpicklable data.
    
    @hidden

◆ lock_file()

def htmltmpl.TemplateManager.lock_file (   self,
  file,
  lock 
)
Provide platform independent file locking.
    @hidden

◆ prepare()

def htmltmpl.TemplateManager.prepare (   self,
  file 
)
Preprocess, parse, tokenize and compile the template.
    
    If precompilation is enabled then this method tries to load
    a precompiled form of the template from the same directory
    in which the template source file is located. If it succeeds,
    then it compares modification times stored in the precompiled
    form to modification times of source files of the template,
    including source files of all templates included via the
    <em>TMPL_INCLUDE</em> statements. If any of the modification times
    differs, then the template is recompiled and the precompiled
    form updated.
    
    If precompilation is disabled, then this method parses and
    compiles the template.
    
    @header prepare(file)
    
    @return Compiled template.
    The methods returns an instance of the <em>Template</em> class
    which is a compiled form of the template. This instance can be
    used as input for the <em>TemplateProcessor</em>.
    
    @param file Path to the template file to prepare.
    The method looks for the template file in current directory
    if the parameter is a relative path. All included templates must
    be placed in subdirectory <strong>'inc'</strong> of the 
    directory in which the main template file is located.

◆ save_precompiled()

def htmltmpl.TemplateManager.save_precompiled (   self,
  template 
)
Save compiled template to disk in precompiled form.
    
    Associated metadata is also saved. It includes: filename of the
    main template file, modification time of the main template file,
    modification times of all included templates and version of the
    htmltmpl module which compiled the template.
    
    The method removes a file which is saved only partially because
    of some error.
    
    @hidden

◆ update()

def htmltmpl.TemplateManager.update (   self,
  template 
)
Update (recompile) a compiled template.

    This method recompiles a template compiled from a file.
    If precompilation is enabled then the precompiled form saved on
    disk is also updated.
    
    @header update(template)
    
    @return Recompiled template.
    It's ensured that the returned template is up-to-date.
    
    @param template A compiled template.
    This parameter should be an instance of the <em>Template</em>
    class, created either by the <em>TemplateManager</em> or by the
    <em>TemplateCompiler</em>. The instance must represent a template
    compiled from a file on disk.

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