Changes between Version 12 and Version 13 of LibdodoTplProcessor

Show
Ignore:
Timestamp:
09/16/2009 09:31:44 AM (12 months ago)
Author:
niam
Comment:

formating

Legend:

Unmodified
Added
Removed
Modified
  • LibdodoTplProcessor

    v12 v13  
    22 
    33Template processor supports simple but yet enough powerful language. 
    4  
    5 It supports includes, variables, conditional statements, loops, namespaces, etc. 
    6  
    7 The primary goal of the template processor is to separate application code from its presentation. 
     4[[BR]]It supports includes, variables, conditional statements, loops, namespaces, etc. 
     5[[BR]]The primary goal of the template processor is to separate application code from its presentation. 
    86 
    97== syntax == 
     
    119=== template language blocks === 
    1210Each part of template that the processor will parse is enclosed into special open and close statements. 
    13 Text outside the template blocks is not being parsed and is being sent to the output without any modifications. 
    14 Text in statements block is always treated as text if it is not a variable. Spaces are trimmed out in the beginning and in the end of the text block. If text area is enclosed with quotes or double quotes the quotes are being removed from the output and text inside is being pushed to the output without any further modifications. 
     11[[BR]]Text outside the template blocks is not being parsed and is being sent to the output without any modifications. 
     12[[BR]]Text in statements block is always treated as text if it is not a variable. Spaces are trimmed out in the beginning and in the end of the text block. 
     13[[BR]]If text area is enclosed with quotes or double quotes the quotes are being removed from the output and text inside is being pushed to the output without any further modifications. 
    1514 * Processing block 
    16  
    17    Processor assumes that some language statement is enclosed in this block 
    18  
    19    {{{<(}}} - open statement 
    20  
    21    {{{)>}}} - close statement 
    22     
    23    For example: 
     15   [[BR]]Processor assumes that some language statement is enclosed in this block 
     16   [[BR]]{{{<(}}} - open statement 
     17   [[BR]]{{{)>}}} - close statement 
     18   [[BR]]For example: 
    2419   {{{ 
    2520   <(for $c in $array)> <(print $c)> <(rof)> 
    2621   }}} 
    2722 * Non-parsed block 
    28  
    29    Processor does not parse the block enclosed with these statements and sends to the output as-is 
    30  
    31    {{{<(>}}} - beginning of the non-parsing area 
    32  
    33    {{{<)>}}} - end of the non-parsing area 
    34  
    35    For example: 
    36    {{{ 
     23   [[BR]]Processor does not parse the block enclosed with these statements and sends to the output as-is 
     24   [[BR]]{{{<(>}}} - beginning of the non-parsing area 
     25   [[BR]]{{{<)>}}} - end of the non-parsing area 
     26   [[BR]]For example: 
     27   [[BR]]{{{ 
    3728   <(> 
    3829        <(print a=, $a,  b=, $b)> 
     
    4334                a == b 
    4435        <(fi)> 
    45    <)> 
    46    }}} 
    47  
     36    <)> 
     37    }}} 
    4838 * Comment block 
    49  
    50    Comment block is thrown out from the processor output 
    51  
    52    {{{<(*}}} - beginning of the comment 
    53  
    54    {{{*)>}}} - end of the comment 
    55  
    56    For example: 
    57    {{{ 
    58    <(* comment here *)> 
    59    }}} 
     39  [[BR]]Comment block is thrown out from the processor output 
     40  [[BR]]{{{<(*}}} - beginning of the comment 
     41  [[BR]]{{{*)>}}} - end of the comment 
     42  [[BR]]For example: 
     43  {{{ 
     44  <(* comment here *)> 
     45  }}} 
    6046 
    6147=== variables === 
    6248Names of the variables begin with {{{'$'}}} sign. 
    63  
    64 For example: 
     49[[BR]]For example: 
    6550{{{ 
    6651$var 
    6752$1var 
    6853}}} 
    69  
    70 Variable is resolved only within the processor statement and if it is not enclosed with any quotes. Text in the quotes is not being interpolated and variables are not being resolved in it. 
    71  
    72 Processor supports 4 types of variables: 
     54[[BR]]Variable is resolved only within the processor statement and if it is not enclosed with any quotes. Text in the quotes is not being interpolated and variables are not being resolved in it. 
     55[[BR]]Processor supports 4 types of variables: 
    7356 1. string 
    7457 2. array 
     
    7659 4. array of hashes 
    7760 
    78 Variable is iterative with {{{'for'}}} loop and variable member can be accessed directly with {{{'.'}}} operator. 
    79  
    80 For example: 
     61[[BR]]Variable is iterative with {{{'for'}}} loop and variable member can be accessed directly with {{{'.'}}} operator. 
     62[[BR]]For example: 
    8163 1. first symbol of string: 
    8264    {{{ 
     
    10082    }}} 
    10183 
    102 Variable can be used as a key to the member. In this case it must be enclosed in {{{'{}'}}} brackets. 
    103 For example: 
     84[[BR]]Variable can be used as a key to the member. In this case it must be enclosed in {{{'{}'}}} brackets. 
     85[[BR]]For example: 
    10486 1. element named 'one' of second element in array of hashes(variable 'variable' has value 'one'): 
    10587    {{{ 
     
    11395=== namespaces === 
    11496Variables have scope of visibility in the statement block. 
    115  
    116 For example: 
     97[[BR]]For example: 
    11798{{{ 
    11899<(for $b in $arr2)> 
     
    136117==== ns ==== 
    137118{{{'ns'}}} statement explicitly defines namespace scope. 
    138  
    139 For example: 
     119[[BR]]For example: 
    140120{{{ 
    141121<(assign a = test1)> 
     
    151131==== include ==== 
    152132{{{'include'}}} statement allows to load template from external file. 
    153  
    154 Included template file is processed and the contents of the processed template is inserted at the point of inclusion. 
    155  
    156 {{{'include'}}} takes string or variable as an argument. Path to template is relative to defined in tpl::processor object instance. 
    157  
    158 For example: 
     133[[BR]]Included template file is processed and the contents of the processed template is inserted at the point of inclusion. 
     134[[BR]]{{{'include'}}} takes string or variable as an argument. Path to template is relative to defined in tpl::processor object instance. 
     135[[BR]]For example: 
    159136{{{ 
    160137<(include $template)> 
     
    165142==== if ==== 
    166143{{{'if'}}} is a conditional statement that allows or discards processing of the template block. 
    167  
    168 {{{'else'}}} statement defines template block that is processed if conditional statement in {{{'if'}}} is '''false'''. 
    169  
    170 {{{'if'}}} allows to use only one comparison per block. There is no logical '''OR''' or '''AND'''. 
    171  
    172 Conditional statement for {{{'if'}}} allows using {{{'=='}}}, {{{'!'}}} and {{{'!='}}} to compare strings, and {{{'=='}}}, {{{'!='}}}, {{{'!'}}}, {{{'<='}}}, {{{'>='}}}, {{{'<'}}}, {{{'>'}}} to compare numeric values. 
    173  
    174 Unary operator {{{'!'}}} turns statement into '''false''' if statement is an empty string or zero for numeric or string that is equal to {{{'false'}}}. 
    175  
    176 For example: 
     144[[BR]]{{{'else'}}} statement defines template block that is processed if conditional statement in {{{'if'}}} is '''false'''. 
     145[[BR]]{{{'if'}}} allows to use only one comparison per block. There is no logical '''OR''' or '''AND'''. 
     146[[BR]]Conditional statement for {{{'if'}}} allows using {{{'=='}}}, {{{'!'}}} and {{{'!='}}} to compare strings, and {{{'=='}}}, {{{'!='}}}, {{{'!'}}}, {{{'<='}}}, {{{'>='}}}, {{{'<'}}}, {{{'>'}}} to compare numeric values. 
     147[[BR]]Unary operator {{{'!'}}} turns statement into '''false''' if statement is an empty string or zero for numeric or string that is equal to {{{'false'}}}. 
     148[[BR]]For example: 
    177149{{{ 
    178150<(if $a == $b)> 
     
    201173==== for ==== 
    202174{{{'for'}}} statement is used to iterate over string, array of objects or hash. 
    203  
    204 Template processor understands two kinds of {{{'for'}}} statements: 
     175[[BR]]Template processor understands two kinds of {{{'for'}}} statements: 
    205176 * Iterate obtaining values of elements: 
    206177   {{{ 
     
    208179   }}} 
    209180 * Iterate obtaining pairs of (key, value) 
    210  
    211    For hash '''key''' is a hash key, otherwise it is an index of element in array or string. 
     181   [[BR]]For hash '''key''' is a hash key, otherwise it is an index of element in array or string. 
    212182   {{{ 
    213183   <(for $key => $value in $hash)><(rof)> 
    214184   }}} 
    215185 
    216 {{{'break'}}} statement inside {{{'for'}}} block stops the current loop. If numeric value is specified for {{{'break'}}} statement, amount of loops specified as {{{'break'}}} argument would be stopped upwards. 
    217  
    218 {{{'continue'}}} statement inside {{{'for'}}} block starts new iteration of the loop. 
    219  
    220 Special variable {{{'$dodo.iterator'}}} stands as a counter for current loop. 
    221  
    222 For example: 
     186[[BR]]{{{'break'}}} statement inside {{{'for'}}} block stops the current loop. If numeric value is specified for {{{'break'}}} statement, amount of loops specified as {{{'break'}}} argument would be stopped upwards. 
     187[[BR]]{{{'continue'}}} statement inside {{{'for'}}} block starts new iteration of the loop. 
     188[[BR]]Special variable {{{'$dodo.iterator'}}} stands as a counter for current loop. 
     189[[BR]]For example: 
    223190{{{ 
    224191<(for $value in $array)> 
     
    240207 
    241208==== print ==== 
    242                  
    243209{{{'print'}}} statement pushes variable value to the output. 
    244  
    245 {{{'print'}}} accepts more than one argument. {{{'print'}}} arguments should be delimited with coma. 
    246  
    247 For example: 
     210[[BR]]{{{'print'}}} accepts more than one argument. {{{'print'}}} arguments should be delimited with coma. 
     211[[BR]]For example: 
    248212{{{ 
    249213<(print $array.{0}.{$key})>