Changes between Version 12 and Version 13 of LibdodoTplProcessor
- Timestamp:
- 09/16/2009 09:31:44 AM (12 months ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
LibdodoTplProcessor
v12 v13 2 2 3 3 Template 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. 8 6 9 7 == syntax == … … 11 9 === template language blocks === 12 10 Each 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. 15 14 * 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: 24 19 {{{ 25 20 <(for $c in $array)> <(print $c)> <(rof)> 26 21 }}} 27 22 * 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]]{{{ 37 28 <(> 38 29 <(print a=, $a, b=, $b)> … … 43 34 a == b 44 35 <(fi)> 45 <)> 46 }}} 47 36 <)> 37 }}} 48 38 * 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 }}} 60 46 61 47 === variables === 62 48 Names of the variables begin with {{{'$'}}} sign. 63 64 For example: 49 [[BR]]For example: 65 50 {{{ 66 51 $var 67 52 $1var 68 53 }}} 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: 73 56 1. string 74 57 2. array … … 76 59 4. array of hashes 77 60 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: 81 63 1. first symbol of string: 82 64 {{{ … … 100 82 }}} 101 83 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: 104 86 1. element named 'one' of second element in array of hashes(variable 'variable' has value 'one'): 105 87 {{{ … … 113 95 === namespaces === 114 96 Variables have scope of visibility in the statement block. 115 116 For example: 97 [[BR]]For example: 117 98 {{{ 118 99 <(for $b in $arr2)> … … 136 117 ==== ns ==== 137 118 {{{'ns'}}} statement explicitly defines namespace scope. 138 139 For example: 119 [[BR]]For example: 140 120 {{{ 141 121 <(assign a = test1)> … … 151 131 ==== include ==== 152 132 {{{'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: 159 136 {{{ 160 137 <(include $template)> … … 165 142 ==== if ==== 166 143 {{{'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: 177 149 {{{ 178 150 <(if $a == $b)> … … 201 173 ==== for ==== 202 174 {{{'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: 205 176 * Iterate obtaining values of elements: 206 177 {{{ … … 208 179 }}} 209 180 * 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. 212 182 {{{ 213 183 <(for $key => $value in $hash)><(rof)> 214 184 }}} 215 185 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: 223 190 {{{ 224 191 <(for $value in $array)> … … 240 207 241 208 ==== print ==== 242 243 209 {{{'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: 248 212 {{{ 249 213 <(print $array.{0}.{$key})>
