diff options
Diffstat (limited to 'vendor/twig/twig/doc')
82 files changed, 0 insertions, 6942 deletions
diff --git a/vendor/twig/twig/doc/advanced.rst b/vendor/twig/twig/doc/advanced.rst deleted file mode 100644 index e1945ebb..00000000 --- a/vendor/twig/twig/doc/advanced.rst +++ /dev/null | |||
@@ -1,829 +0,0 @@ | |||
1 | Extending Twig | ||
2 | ============== | ||
3 | |||
4 | .. caution:: | ||
5 | |||
6 | This section describes how to extend Twig as of **Twig 1.12**. If you are | ||
7 | using an older version, read the :doc:`legacy<advanced_legacy>` chapter | ||
8 | instead. | ||
9 | |||
10 | Twig can be extended in many ways; you can add extra tags, filters, tests, | ||
11 | operators, global variables, and functions. You can even extend the parser | ||
12 | itself with node visitors. | ||
13 | |||
14 | .. note:: | ||
15 | |||
16 | The first section of this chapter describes how to extend Twig easily. If | ||
17 | you want to reuse your changes in different projects or if you want to | ||
18 | share them with others, you should then create an extension as described | ||
19 | in the following section. | ||
20 | |||
21 | .. caution:: | ||
22 | |||
23 | When extending Twig without creating an extension, Twig won't be able to | ||
24 | recompile your templates when the PHP code is updated. To see your changes | ||
25 | in real-time, either disable template caching or package your code into an | ||
26 | extension (see the next section of this chapter). | ||
27 | |||
28 | Before extending Twig, you must understand the differences between all the | ||
29 | different possible extension points and when to use them. | ||
30 | |||
31 | First, remember that Twig has two main language constructs: | ||
32 | |||
33 | * ``{{ }}``: used to print the result of an expression evaluation; | ||
34 | |||
35 | * ``{% %}``: used to execute statements. | ||
36 | |||
37 | To understand why Twig exposes so many extension points, let's see how to | ||
38 | implement a *Lorem ipsum* generator (it needs to know the number of words to | ||
39 | generate). | ||
40 | |||
41 | You can use a ``lipsum`` *tag*: | ||
42 | |||
43 | .. code-block:: jinja | ||
44 | |||
45 | {% lipsum 40 %} | ||
46 | |||
47 | That works, but using a tag for ``lipsum`` is not a good idea for at least | ||
48 | three main reasons: | ||
49 | |||
50 | * ``lipsum`` is not a language construct; | ||
51 | * The tag outputs something; | ||
52 | * The tag is not flexible as you cannot use it in an expression: | ||
53 | |||
54 | .. code-block:: jinja | ||
55 | |||
56 | {{ 'some text' ~ {% lipsum 40 %} ~ 'some more text' }} | ||
57 | |||
58 | In fact, you rarely need to create tags; and that's good news because tags are | ||
59 | the most complex extension point of Twig. | ||
60 | |||
61 | Now, let's use a ``lipsum`` *filter*: | ||
62 | |||
63 | .. code-block:: jinja | ||
64 | |||
65 | {{ 40|lipsum }} | ||
66 | |||
67 | Again, it works, but it looks weird. A filter transforms the passed value to | ||
68 | something else but here we use the value to indicate the number of words to | ||
69 | generate (so, ``40`` is an argument of the filter, not the value we want to | ||
70 | transform). | ||
71 | |||
72 | Next, let's use a ``lipsum`` *function*: | ||
73 | |||
74 | .. code-block:: jinja | ||
75 | |||
76 | {{ lipsum(40) }} | ||
77 | |||
78 | Here we go. For this specific example, the creation of a function is the | ||
79 | extension point to use. And you can use it anywhere an expression is accepted: | ||
80 | |||
81 | .. code-block:: jinja | ||
82 | |||
83 | {{ 'some text' ~ lipsum(40) ~ 'some more text' }} | ||
84 | |||
85 | {% set lipsum = lipsum(40) %} | ||
86 | |||
87 | Last but not the least, you can also use a *global* object with a method able | ||
88 | to generate lorem ipsum text: | ||
89 | |||
90 | .. code-block:: jinja | ||
91 | |||
92 | {{ text.lipsum(40) }} | ||
93 | |||
94 | As a rule of thumb, use functions for frequently used features and global | ||
95 | objects for everything else. | ||
96 | |||
97 | Keep in mind the following when you want to extend Twig: | ||
98 | |||
99 | ========== ========================== ========== ========================= | ||
100 | What? Implementation difficulty? How often? When? | ||
101 | ========== ========================== ========== ========================= | ||
102 | *macro* trivial frequent Content generation | ||
103 | *global* trivial frequent Helper object | ||
104 | *function* trivial frequent Content generation | ||
105 | *filter* trivial frequent Value transformation | ||
106 | *tag* complex rare DSL language construct | ||
107 | *test* trivial rare Boolean decision | ||
108 | *operator* trivial rare Values transformation | ||
109 | ========== ========================== ========== ========================= | ||
110 | |||
111 | Globals | ||
112 | ------- | ||
113 | |||
114 | A global variable is like any other template variable, except that it's | ||
115 | available in all templates and macros:: | ||
116 | |||
117 | $twig = new Twig_Environment($loader); | ||
118 | $twig->addGlobal('text', new Text()); | ||
119 | |||
120 | You can then use the ``text`` variable anywhere in a template: | ||
121 | |||
122 | .. code-block:: jinja | ||
123 | |||
124 | {{ text.lipsum(40) }} | ||
125 | |||
126 | Filters | ||
127 | ------- | ||
128 | |||
129 | Creating a filter is as simple as associating a name with a PHP callable:: | ||
130 | |||
131 | // an anonymous function | ||
132 | $filter = new Twig_SimpleFilter('rot13', function ($string) { | ||
133 | return str_rot13($string); | ||
134 | }); | ||
135 | |||
136 | // or a simple PHP function | ||
137 | $filter = new Twig_SimpleFilter('rot13', 'str_rot13'); | ||
138 | |||
139 | // or a class method | ||
140 | $filter = new Twig_SimpleFilter('rot13', array('SomeClass', 'rot13Filter')); | ||
141 | |||
142 | The first argument passed to the ``Twig_SimpleFilter`` constructor is the name | ||
143 | of the filter you will use in templates and the second one is the PHP callable | ||
144 | to associate with it. | ||
145 | |||
146 | Then, add the filter to your Twig environment:: | ||
147 | |||
148 | $twig = new Twig_Environment($loader); | ||
149 | $twig->addFilter($filter); | ||
150 | |||
151 | And here is how to use it in a template: | ||
152 | |||
153 | .. code-block:: jinja | ||
154 | |||
155 | {{ 'Twig'|rot13 }} | ||
156 | |||
157 | {# will output Gjvt #} | ||
158 | |||
159 | When called by Twig, the PHP callable receives the left side of the filter | ||
160 | (before the pipe ``|``) as the first argument and the extra arguments passed | ||
161 | to the filter (within parentheses ``()``) as extra arguments. | ||
162 | |||
163 | For instance, the following code: | ||
164 | |||
165 | .. code-block:: jinja | ||
166 | |||
167 | {{ 'TWIG'|lower }} | ||
168 | {{ now|date('d/m/Y') }} | ||
169 | |||
170 | is compiled to something like the following:: | ||
171 | |||
172 | <?php echo strtolower('TWIG') ?> | ||
173 | <?php echo twig_date_format_filter($now, 'd/m/Y') ?> | ||
174 | |||
175 | The ``Twig_SimpleFilter`` class takes an array of options as its last | ||
176 | argument:: | ||
177 | |||
178 | $filter = new Twig_SimpleFilter('rot13', 'str_rot13', $options); | ||
179 | |||
180 | Environment aware Filters | ||
181 | ~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
182 | |||
183 | If you want to access the current environment instance in your filter, set the | ||
184 | ``needs_environment`` option to ``true``; Twig will pass the current | ||
185 | environment as the first argument to the filter call:: | ||
186 | |||
187 | $filter = new Twig_SimpleFilter('rot13', function (Twig_Environment $env, $string) { | ||
188 | // get the current charset for instance | ||
189 | $charset = $env->getCharset(); | ||
190 | |||
191 | return str_rot13($string); | ||
192 | }, array('needs_environment' => true)); | ||
193 | |||
194 | Context aware Filters | ||
195 | ~~~~~~~~~~~~~~~~~~~~~ | ||
196 | |||
197 | If you want to access the current context in your filter, set the | ||
198 | ``needs_context`` option to ``true``; Twig will pass the current context as | ||
199 | the first argument to the filter call (or the second one if | ||
200 | ``needs_environment`` is also set to ``true``):: | ||
201 | |||
202 | $filter = new Twig_SimpleFilter('rot13', function ($context, $string) { | ||
203 | // ... | ||
204 | }, array('needs_context' => true)); | ||
205 | |||
206 | $filter = new Twig_SimpleFilter('rot13', function (Twig_Environment $env, $context, $string) { | ||
207 | // ... | ||
208 | }, array('needs_context' => true, 'needs_environment' => true)); | ||
209 | |||
210 | Automatic Escaping | ||
211 | ~~~~~~~~~~~~~~~~~~ | ||
212 | |||
213 | If automatic escaping is enabled, the output of the filter may be escaped | ||
214 | before printing. If your filter acts as an escaper (or explicitly outputs html | ||
215 | or JavaScript code), you will want the raw output to be printed. In such a | ||
216 | case, set the ``is_safe`` option:: | ||
217 | |||
218 | $filter = new Twig_SimpleFilter('nl2br', 'nl2br', array('is_safe' => array('html'))); | ||
219 | |||
220 | Some filters may need to work on input that is already escaped or safe, for | ||
221 | example when adding (safe) html tags to originally unsafe output. In such a | ||
222 | case, set the ``pre_escape`` option to escape the input data before it is run | ||
223 | through your filter:: | ||
224 | |||
225 | $filter = new Twig_SimpleFilter('somefilter', 'somefilter', array('pre_escape' => 'html', 'is_safe' => array('html'))); | ||
226 | |||
227 | Dynamic Filters | ||
228 | ~~~~~~~~~~~~~~~ | ||
229 | |||
230 | A filter name containing the special ``*`` character is a dynamic filter as | ||
231 | the ``*`` can be any string:: | ||
232 | |||
233 | $filter = new Twig_SimpleFilter('*_path', function ($name, $arguments) { | ||
234 | // ... | ||
235 | }); | ||
236 | |||
237 | The following filters will be matched by the above defined dynamic filter: | ||
238 | |||
239 | * ``product_path`` | ||
240 | * ``category_path`` | ||
241 | |||
242 | A dynamic filter can define more than one dynamic parts:: | ||
243 | |||
244 | $filter = new Twig_SimpleFilter('*_path_*', function ($name, $suffix, $arguments) { | ||
245 | // ... | ||
246 | }); | ||
247 | |||
248 | The filter will receive all dynamic part values before the normal filter | ||
249 | arguments, but after the environment and the context. For instance, a call to | ||
250 | ``'foo'|a_path_b()`` will result in the following arguments to be passed to | ||
251 | the filter: ``('a', 'b', 'foo')``. | ||
252 | |||
253 | Functions | ||
254 | --------- | ||
255 | |||
256 | Functions are defined in the exact same way as filters, but you need to create | ||
257 | an instance of ``Twig_SimpleFunction``:: | ||
258 | |||
259 | $twig = new Twig_Environment($loader); | ||
260 | $function = new Twig_SimpleFunction('function_name', function () { | ||
261 | // ... | ||
262 | }); | ||
263 | $twig->addFunction($function); | ||
264 | |||
265 | Functions support the same features as filters, except for the ``pre_escape`` | ||
266 | and ``preserves_safety`` options. | ||
267 | |||
268 | Tests | ||
269 | ----- | ||
270 | |||
271 | Tests are defined in the exact same way as filters and functions, but you need | ||
272 | to create an instance of ``Twig_SimpleTest``:: | ||
273 | |||
274 | $twig = new Twig_Environment($loader); | ||
275 | $test = new Twig_SimpleTest('test_name', function () { | ||
276 | // ... | ||
277 | }); | ||
278 | $twig->addTest($test); | ||
279 | |||
280 | Tests allow you to create custom application specific logic for evaluating | ||
281 | boolean conditions. As a simple, example let's create a Twig test that checks if | ||
282 | objects are 'red':: | ||
283 | |||
284 | $twig = new Twig_Environment($loader) | ||
285 | $test = new Twig_SimpleTest('red', function ($value) { | ||
286 | if (isset($value->color) && $value->color == 'red') { | ||
287 | return true; | ||
288 | } | ||
289 | if (isset($value->paint) && $value->paint == 'red') { | ||
290 | return true; | ||
291 | } | ||
292 | return false; | ||
293 | }); | ||
294 | $twig->addTest($test); | ||
295 | |||
296 | Test functions should always return true/false. | ||
297 | |||
298 | When creating tests you can use the ``node_class`` option to provide custom test | ||
299 | compilation. This is useful if your test can be compiled into PHP primitives. | ||
300 | This is used by many of the tests built into Twig:: | ||
301 | |||
302 | $twig = new Twig_Environment($loader) | ||
303 | $test = new Twig_SimpleTest( | ||
304 | 'odd', | ||
305 | null, | ||
306 | array('node_class' => 'Twig_Node_Expression_Test_Odd')); | ||
307 | $twig->addTest($test); | ||
308 | |||
309 | class Twig_Node_Expression_Test_Odd extends Twig_Node_Expression_Test | ||
310 | { | ||
311 | public function compile(Twig_Compiler $compiler) | ||
312 | { | ||
313 | $compiler | ||
314 | ->raw('(') | ||
315 | ->subcompile($this->getNode('node')) | ||
316 | ->raw(' % 2 == 1') | ||
317 | ->raw(')') | ||
318 | ; | ||
319 | } | ||
320 | } | ||
321 | |||
322 | The above example, shows how you can create tests that use a node class. The | ||
323 | node class has access to one sub-node called 'node'. This sub-node contains the | ||
324 | value that is being tested. When the ``odd`` filter is used in code like: | ||
325 | |||
326 | .. code-block:: jinja | ||
327 | |||
328 | {% if my_value is odd %} | ||
329 | |||
330 | The ``node`` sub-node will contain an expression of ``my_value``. Node based | ||
331 | tests also have access to the ``arguments`` node. This node will contain the | ||
332 | various other arguments that have been provided to your test. | ||
333 | |||
334 | Tags | ||
335 | ---- | ||
336 | |||
337 | One of the most exciting feature of a template engine like Twig is the | ||
338 | possibility to define new language constructs. This is also the most complex | ||
339 | feature as you need to understand how Twig's internals work. | ||
340 | |||
341 | Let's create a simple ``set`` tag that allows the definition of simple | ||
342 | variables from within a template. The tag can be used like follows: | ||
343 | |||
344 | .. code-block:: jinja | ||
345 | |||
346 | {% set name = "value" %} | ||
347 | |||
348 | {{ name }} | ||
349 | |||
350 | {# should output value #} | ||
351 | |||
352 | .. note:: | ||
353 | |||
354 | The ``set`` tag is part of the Core extension and as such is always | ||
355 | available. The built-in version is slightly more powerful and supports | ||
356 | multiple assignments by default (cf. the template designers chapter for | ||
357 | more information). | ||
358 | |||
359 | Three steps are needed to define a new tag: | ||
360 | |||
361 | * Defining a Token Parser class (responsible for parsing the template code); | ||
362 | |||
363 | * Defining a Node class (responsible for converting the parsed code to PHP); | ||
364 | |||
365 | * Registering the tag. | ||
366 | |||
367 | Registering a new tag | ||
368 | ~~~~~~~~~~~~~~~~~~~~~ | ||
369 | |||
370 | Adding a tag is as simple as calling the ``addTokenParser`` method on the | ||
371 | ``Twig_Environment`` instance:: | ||
372 | |||
373 | $twig = new Twig_Environment($loader); | ||
374 | $twig->addTokenParser(new Project_Set_TokenParser()); | ||
375 | |||
376 | Defining a Token Parser | ||
377 | ~~~~~~~~~~~~~~~~~~~~~~~ | ||
378 | |||
379 | Now, let's see the actual code of this class:: | ||
380 | |||
381 | class Project_Set_TokenParser extends Twig_TokenParser | ||
382 | { | ||
383 | public function parse(Twig_Token $token) | ||
384 | { | ||
385 | $parser = $this->parser; | ||
386 | $stream = $parser->getStream(); | ||
387 | |||
388 | $name = $stream->expect(Twig_Token::NAME_TYPE)->getValue(); | ||
389 | $stream->expect(Twig_Token::OPERATOR_TYPE, '='); | ||
390 | $value = $parser->getExpressionParser()->parseExpression(); | ||
391 | $stream->expect(Twig_Token::BLOCK_END_TYPE); | ||
392 | |||
393 | return new Project_Set_Node($name, $value, $token->getLine(), $this->getTag()); | ||
394 | } | ||
395 | |||
396 | public function getTag() | ||
397 | { | ||
398 | return 'set'; | ||
399 | } | ||
400 | } | ||
401 | |||
402 | The ``getTag()`` method must return the tag we want to parse, here ``set``. | ||
403 | |||
404 | The ``parse()`` method is invoked whenever the parser encounters a ``set`` | ||
405 | tag. It should return a ``Twig_Node`` instance that represents the node (the | ||
406 | ``Project_Set_Node`` calls creating is explained in the next section). | ||
407 | |||
408 | The parsing process is simplified thanks to a bunch of methods you can call | ||
409 | from the token stream (``$this->parser->getStream()``): | ||
410 | |||
411 | * ``getCurrent()``: Gets the current token in the stream. | ||
412 | |||
413 | * ``next()``: Moves to the next token in the stream, *but returns the old one*. | ||
414 | |||
415 | * ``test($type)``, ``test($value)`` or ``test($type, $value)``: Determines whether | ||
416 | the current token is of a particular type or value (or both). The value may be an | ||
417 | array of several possible values. | ||
418 | |||
419 | * ``expect($type[, $value[, $message]])``: If the current token isn't of the given | ||
420 | type/value a syntax error is thrown. Otherwise, if the type and value are correct, | ||
421 | the token is returned and the stream moves to the next token. | ||
422 | |||
423 | * ``look()``: Looks a the next token without consuming it. | ||
424 | |||
425 | Parsing expressions is done by calling the ``parseExpression()`` like we did for | ||
426 | the ``set`` tag. | ||
427 | |||
428 | .. tip:: | ||
429 | |||
430 | Reading the existing ``TokenParser`` classes is the best way to learn all | ||
431 | the nitty-gritty details of the parsing process. | ||
432 | |||
433 | Defining a Node | ||
434 | ~~~~~~~~~~~~~~~ | ||
435 | |||
436 | The ``Project_Set_Node`` class itself is rather simple:: | ||
437 | |||
438 | class Project_Set_Node extends Twig_Node | ||
439 | { | ||
440 | public function __construct($name, Twig_Node_Expression $value, $line, $tag = null) | ||
441 | { | ||
442 | parent::__construct(array('value' => $value), array('name' => $name), $line, $tag); | ||
443 | } | ||
444 | |||
445 | public function compile(Twig_Compiler $compiler) | ||
446 | { | ||
447 | $compiler | ||
448 | ->addDebugInfo($this) | ||
449 | ->write('$context[\''.$this->getAttribute('name').'\'] = ') | ||
450 | ->subcompile($this->getNode('value')) | ||
451 | ->raw(";\n") | ||
452 | ; | ||
453 | } | ||
454 | } | ||
455 | |||
456 | The compiler implements a fluid interface and provides methods that helps the | ||
457 | developer generate beautiful and readable PHP code: | ||
458 | |||
459 | * ``subcompile()``: Compiles a node. | ||
460 | |||
461 | * ``raw()``: Writes the given string as is. | ||
462 | |||
463 | * ``write()``: Writes the given string by adding indentation at the beginning | ||
464 | of each line. | ||
465 | |||
466 | * ``string()``: Writes a quoted string. | ||
467 | |||
468 | * ``repr()``: Writes a PHP representation of a given value (see | ||
469 | ``Twig_Node_For`` for a usage example). | ||
470 | |||
471 | * ``addDebugInfo()``: Adds the line of the original template file related to | ||
472 | the current node as a comment. | ||
473 | |||
474 | * ``indent()``: Indents the generated code (see ``Twig_Node_Block`` for a | ||
475 | usage example). | ||
476 | |||
477 | * ``outdent()``: Outdents the generated code (see ``Twig_Node_Block`` for a | ||
478 | usage example). | ||
479 | |||
480 | .. _creating_extensions: | ||
481 | |||
482 | Creating an Extension | ||
483 | --------------------- | ||
484 | |||
485 | The main motivation for writing an extension is to move often used code into a | ||
486 | reusable class like adding support for internationalization. An extension can | ||
487 | define tags, filters, tests, operators, global variables, functions, and node | ||
488 | visitors. | ||
489 | |||
490 | Creating an extension also makes for a better separation of code that is | ||
491 | executed at compilation time and code needed at runtime. As such, it makes | ||
492 | your code faster. | ||
493 | |||
494 | Most of the time, it is useful to create a single extension for your project, | ||
495 | to host all the specific tags and filters you want to add to Twig. | ||
496 | |||
497 | .. tip:: | ||
498 | |||
499 | When packaging your code into an extension, Twig is smart enough to | ||
500 | recompile your templates whenever you make a change to it (when | ||
501 | ``auto_reload`` is enabled). | ||
502 | |||
503 | .. note:: | ||
504 | |||
505 | Before writing your own extensions, have a look at the Twig official | ||
506 | extension repository: http://github.com/fabpot/Twig-extensions. | ||
507 | |||
508 | An extension is a class that implements the following interface:: | ||
509 | |||
510 | interface Twig_ExtensionInterface | ||
511 | { | ||
512 | /** | ||
513 | * Initializes the runtime environment. | ||
514 | * | ||
515 | * This is where you can load some file that contains filter functions for instance. | ||
516 | * | ||
517 | * @param Twig_Environment $environment The current Twig_Environment instance | ||
518 | */ | ||
519 | function initRuntime(Twig_Environment $environment); | ||
520 | |||
521 | /** | ||
522 | * Returns the token parser instances to add to the existing list. | ||
523 | * | ||
524 | * @return array An array of Twig_TokenParserInterface or Twig_TokenParserBrokerInterface instances | ||
525 | */ | ||
526 | function getTokenParsers(); | ||
527 | |||
528 | /** | ||
529 | * Returns the node visitor instances to add to the existing list. | ||
530 | * | ||
531 | * @return array An array of Twig_NodeVisitorInterface instances | ||
532 | */ | ||
533 | function getNodeVisitors(); | ||
534 | |||
535 | /** | ||
536 | * Returns a list of filters to add to the existing list. | ||
537 | * | ||
538 | * @return array An array of filters | ||
539 | */ | ||
540 | function getFilters(); | ||
541 | |||
542 | /** | ||
543 | * Returns a list of tests to add to the existing list. | ||
544 | * | ||
545 | * @return array An array of tests | ||
546 | */ | ||
547 | function getTests(); | ||
548 | |||
549 | /** | ||
550 | * Returns a list of functions to add to the existing list. | ||
551 | * | ||
552 | * @return array An array of functions | ||
553 | */ | ||
554 | function getFunctions(); | ||
555 | |||
556 | /** | ||
557 | * Returns a list of operators to add to the existing list. | ||
558 | * | ||
559 | * @return array An array of operators | ||
560 | */ | ||
561 | function getOperators(); | ||
562 | |||
563 | /** | ||
564 | * Returns a list of global variables to add to the existing list. | ||
565 | * | ||
566 | * @return array An array of global variables | ||
567 | */ | ||
568 | function getGlobals(); | ||
569 | |||
570 | /** | ||
571 | * Returns the name of the extension. | ||
572 | * | ||
573 | * @return string The extension name | ||
574 | */ | ||
575 | function getName(); | ||
576 | } | ||
577 | |||
578 | To keep your extension class clean and lean, it can inherit from the built-in | ||
579 | ``Twig_Extension`` class instead of implementing the whole interface. That | ||
580 | way, you just need to implement the ``getName()`` method as the | ||
581 | ``Twig_Extension`` provides empty implementations for all other methods. | ||
582 | |||
583 | The ``getName()`` method must return a unique identifier for your extension. | ||
584 | |||
585 | Now, with this information in mind, let's create the most basic extension | ||
586 | possible:: | ||
587 | |||
588 | class Project_Twig_Extension extends Twig_Extension | ||
589 | { | ||
590 | public function getName() | ||
591 | { | ||
592 | return 'project'; | ||
593 | } | ||
594 | } | ||
595 | |||
596 | .. note:: | ||
597 | |||
598 | Of course, this extension does nothing for now. We will customize it in | ||
599 | the next sections. | ||
600 | |||
601 | Twig does not care where you save your extension on the filesystem, as all | ||
602 | extensions must be registered explicitly to be available in your templates. | ||
603 | |||
604 | You can register an extension by using the ``addExtension()`` method on your | ||
605 | main ``Environment`` object:: | ||
606 | |||
607 | $twig = new Twig_Environment($loader); | ||
608 | $twig->addExtension(new Project_Twig_Extension()); | ||
609 | |||
610 | Of course, you need to first load the extension file by either using | ||
611 | ``require_once()`` or by using an autoloader (see `spl_autoload_register()`_). | ||
612 | |||
613 | .. tip:: | ||
614 | |||
615 | The bundled extensions are great examples of how extensions work. | ||
616 | |||
617 | Globals | ||
618 | ~~~~~~~ | ||
619 | |||
620 | Global variables can be registered in an extension via the ``getGlobals()`` | ||
621 | method:: | ||
622 | |||
623 | class Project_Twig_Extension extends Twig_Extension | ||
624 | { | ||
625 | public function getGlobals() | ||
626 | { | ||
627 | return array( | ||
628 | 'text' => new Text(), | ||
629 | ); | ||
630 | } | ||
631 | |||
632 | // ... | ||
633 | } | ||
634 | |||
635 | Functions | ||
636 | ~~~~~~~~~ | ||
637 | |||
638 | Functions can be registered in an extension via the ``getFunctions()`` | ||
639 | method:: | ||
640 | |||
641 | class Project_Twig_Extension extends Twig_Extension | ||
642 | { | ||
643 | public function getFunctions() | ||
644 | { | ||
645 | return array( | ||
646 | new Twig_SimpleFunction('lipsum', 'generate_lipsum'), | ||
647 | ); | ||
648 | } | ||
649 | |||
650 | // ... | ||
651 | } | ||
652 | |||
653 | Filters | ||
654 | ~~~~~~~ | ||
655 | |||
656 | To add a filter to an extension, you need to override the ``getFilters()`` | ||
657 | method. This method must return an array of filters to add to the Twig | ||
658 | environment:: | ||
659 | |||
660 | class Project_Twig_Extension extends Twig_Extension | ||
661 | { | ||
662 | public function getFilters() | ||
663 | { | ||
664 | return array( | ||
665 | new Twig_SimpleFilter('rot13', 'str_rot13'), | ||
666 | ); | ||
667 | } | ||
668 | |||
669 | // ... | ||
670 | } | ||
671 | |||
672 | Tags | ||
673 | ~~~~ | ||
674 | |||
675 | Adding a tag in an extension can be done by overriding the | ||
676 | ``getTokenParsers()`` method. This method must return an array of tags to add | ||
677 | to the Twig environment:: | ||
678 | |||
679 | class Project_Twig_Extension extends Twig_Extension | ||
680 | { | ||
681 | public function getTokenParsers() | ||
682 | { | ||
683 | return array(new Project_Set_TokenParser()); | ||
684 | } | ||
685 | |||
686 | // ... | ||
687 | } | ||
688 | |||
689 | In the above code, we have added a single new tag, defined by the | ||
690 | ``Project_Set_TokenParser`` class. The ``Project_Set_TokenParser`` class is | ||
691 | responsible for parsing the tag and compiling it to PHP. | ||
692 | |||
693 | Operators | ||
694 | ~~~~~~~~~ | ||
695 | |||
696 | The ``getOperators()`` methods allows to add new operators. Here is how to add | ||
697 | ``!``, ``||``, and ``&&`` operators:: | ||
698 | |||
699 | class Project_Twig_Extension extends Twig_Extension | ||
700 | { | ||
701 | public function getOperators() | ||
702 | { | ||
703 | return array( | ||
704 | array( | ||
705 | '!' => array('precedence' => 50, 'class' => 'Twig_Node_Expression_Unary_Not'), | ||
706 | ), | ||
707 | array( | ||
708 | '||' => array('precedence' => 10, 'class' => 'Twig_Node_Expression_Binary_Or', 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT), | ||
709 | '&&' => array('precedence' => 15, 'class' => 'Twig_Node_Expression_Binary_And', 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT), | ||
710 | ), | ||
711 | ); | ||
712 | } | ||
713 | |||
714 | // ... | ||
715 | } | ||
716 | |||
717 | Tests | ||
718 | ~~~~~ | ||
719 | |||
720 | The ``getTests()`` methods allows to add new test functions:: | ||
721 | |||
722 | class Project_Twig_Extension extends Twig_Extension | ||
723 | { | ||
724 | public function getTests() | ||
725 | { | ||
726 | return array( | ||
727 | new Twig_SimpleTest('even', 'twig_test_even'), | ||
728 | ); | ||
729 | } | ||
730 | |||
731 | // ... | ||
732 | } | ||
733 | |||
734 | Overloading | ||
735 | ----------- | ||
736 | |||
737 | To overload an already defined filter, test, operator, global variable, or | ||
738 | function, define it again **as late as possible**:: | ||
739 | |||
740 | $twig = new Twig_Environment($loader); | ||
741 | $twig->addFilter(new Twig_SimpleFilter('date', function ($timestamp, $format = 'F j, Y H:i') { | ||
742 | // do something different from the built-in date filter | ||
743 | })); | ||
744 | |||
745 | Here, we have overloaded the built-in ``date`` filter with a custom one. | ||
746 | |||
747 | That also works with an extension:: | ||
748 | |||
749 | class MyCoreExtension extends Twig_Extension | ||
750 | { | ||
751 | public function getFilters() | ||
752 | { | ||
753 | return array( | ||
754 | new Twig_SimpleFilter('date', array($this, 'dateFilter')), | ||
755 | ); | ||
756 | } | ||
757 | |||
758 | public function dateFilter($timestamp, $format = 'F j, Y H:i') | ||
759 | { | ||
760 | // do something different from the built-in date filter | ||
761 | } | ||
762 | |||
763 | public function getName() | ||
764 | { | ||
765 | return 'project'; | ||
766 | } | ||
767 | } | ||
768 | |||
769 | $twig = new Twig_Environment($loader); | ||
770 | $twig->addExtension(new MyCoreExtension()); | ||
771 | |||
772 | .. caution:: | ||
773 | |||
774 | Note that overloading the built-in Twig elements is not recommended as it | ||
775 | might be confusing. | ||
776 | |||
777 | Testing an Extension | ||
778 | -------------------- | ||
779 | |||
780 | Functional Tests | ||
781 | ~~~~~~~~~~~~~~~~ | ||
782 | |||
783 | You can create functional tests for extensions simply by creating the | ||
784 | following file structure in your test directory:: | ||
785 | |||
786 | Fixtures/ | ||
787 | filters/ | ||
788 | foo.test | ||
789 | bar.test | ||
790 | functions/ | ||
791 | foo.test | ||
792 | bar.test | ||
793 | tags/ | ||
794 | foo.test | ||
795 | bar.test | ||
796 | IntegrationTest.php | ||
797 | |||
798 | The ``IntegrationTest.php`` file should look like this:: | ||
799 | |||
800 | class Project_Tests_IntegrationTest extends Twig_Test_IntegrationTestCase | ||
801 | { | ||
802 | public function getExtensions() | ||
803 | { | ||
804 | return array( | ||
805 | new Project_Twig_Extension1(), | ||
806 | new Project_Twig_Extension2(), | ||
807 | ); | ||
808 | } | ||
809 | |||
810 | public function getFixturesDir() | ||
811 | { | ||
812 | return dirname(__FILE__).'/Fixtures/'; | ||
813 | } | ||
814 | } | ||
815 | |||
816 | Fixtures examples can be found within the Twig repository | ||
817 | `tests/Twig/Fixtures`_ directory. | ||
818 | |||
819 | Node Tests | ||
820 | ~~~~~~~~~~ | ||
821 | |||
822 | Testing the node visitors can be complex, so extend your test cases from | ||
823 | ``Twig_Test_NodeTestCase``. Examples can be found in the Twig repository | ||
824 | `tests/Twig/Node`_ directory. | ||
825 | |||
826 | .. _`spl_autoload_register()`: http://www.php.net/spl_autoload_register | ||
827 | .. _`rot13`: http://www.php.net/manual/en/function.str-rot13.php | ||
828 | .. _`tests/Twig/Fixtures`: https://github.com/fabpot/Twig/tree/master/test/Twig/Tests/Fixtures | ||
829 | .. _`tests/Twig/Node`: https://github.com/fabpot/Twig/tree/master/test/Twig/Tests/Node | ||
diff --git a/vendor/twig/twig/doc/advanced_legacy.rst b/vendor/twig/twig/doc/advanced_legacy.rst deleted file mode 100644 index 3d34f932..00000000 --- a/vendor/twig/twig/doc/advanced_legacy.rst +++ /dev/null | |||
@@ -1,887 +0,0 @@ | |||
1 | Extending Twig | ||
2 | ============== | ||
3 | |||
4 | .. caution:: | ||
5 | |||
6 | This section describes how to extends Twig for versions **older than | ||
7 | 1.12**. If you are using a newer version, read the :doc:`newer<advanced>` | ||
8 | chapter instead. | ||
9 | |||
10 | Twig can be extended in many ways; you can add extra tags, filters, tests, | ||
11 | operators, global variables, and functions. You can even extend the parser | ||
12 | itself with node visitors. | ||
13 | |||
14 | .. note:: | ||
15 | |||
16 | The first section of this chapter describes how to extend Twig easily. If | ||
17 | you want to reuse your changes in different projects or if you want to | ||
18 | share them with others, you should then create an extension as described | ||
19 | in the following section. | ||
20 | |||
21 | .. caution:: | ||
22 | |||
23 | When extending Twig by calling methods on the Twig environment instance, | ||
24 | Twig won't be able to recompile your templates when the PHP code is | ||
25 | updated. To see your changes in real-time, either disable template caching | ||
26 | or package your code into an extension (see the next section of this | ||
27 | chapter). | ||
28 | |||
29 | Before extending Twig, you must understand the differences between all the | ||
30 | different possible extension points and when to use them. | ||
31 | |||
32 | First, remember that Twig has two main language constructs: | ||
33 | |||
34 | * ``{{ }}``: used to print the result of an expression evaluation; | ||
35 | |||
36 | * ``{% %}``: used to execute statements. | ||
37 | |||
38 | To understand why Twig exposes so many extension points, let's see how to | ||
39 | implement a *Lorem ipsum* generator (it needs to know the number of words to | ||
40 | generate). | ||
41 | |||
42 | You can use a ``lipsum`` *tag*: | ||
43 | |||
44 | .. code-block:: jinja | ||
45 | |||
46 | {% lipsum 40 %} | ||
47 | |||
48 | That works, but using a tag for ``lipsum`` is not a good idea for at least | ||
49 | three main reasons: | ||
50 | |||
51 | * ``lipsum`` is not a language construct; | ||
52 | * The tag outputs something; | ||
53 | * The tag is not flexible as you cannot use it in an expression: | ||
54 | |||
55 | .. code-block:: jinja | ||
56 | |||
57 | {{ 'some text' ~ {% lipsum 40 %} ~ 'some more text' }} | ||
58 | |||
59 | In fact, you rarely need to create tags; and that's good news because tags are | ||
60 | the most complex extension point of Twig. | ||
61 | |||
62 | Now, let's use a ``lipsum`` *filter*: | ||
63 | |||
64 | .. code-block:: jinja | ||
65 | |||
66 | {{ 40|lipsum }} | ||
67 | |||
68 | Again, it works, but it looks weird. A filter transforms the passed value to | ||
69 | something else but here we use the value to indicate the number of words to | ||
70 | generate (so, ``40`` is an argument of the filter, not the value we want to | ||
71 | transform). | ||
72 | |||
73 | Next, let's use a ``lipsum`` *function*: | ||
74 | |||
75 | .. code-block:: jinja | ||
76 | |||
77 | {{ lipsum(40) }} | ||
78 | |||
79 | Here we go. For this specific example, the creation of a function is the | ||
80 | extension point to use. And you can use it anywhere an expression is accepted: | ||
81 | |||
82 | .. code-block:: jinja | ||
83 | |||
84 | {{ 'some text' ~ ipsum(40) ~ 'some more text' }} | ||
85 | |||
86 | {% set ipsum = ipsum(40) %} | ||
87 | |||
88 | Last but not the least, you can also use a *global* object with a method able | ||
89 | to generate lorem ipsum text: | ||
90 | |||
91 | .. code-block:: jinja | ||
92 | |||
93 | {{ text.lipsum(40) }} | ||
94 | |||
95 | As a rule of thumb, use functions for frequently used features and global | ||
96 | objects for everything else. | ||
97 | |||
98 | Keep in mind the following when you want to extend Twig: | ||
99 | |||
100 | ========== ========================== ========== ========================= | ||
101 | What? Implementation difficulty? How often? When? | ||
102 | ========== ========================== ========== ========================= | ||
103 | *macro* trivial frequent Content generation | ||
104 | *global* trivial frequent Helper object | ||
105 | *function* trivial frequent Content generation | ||
106 | *filter* trivial frequent Value transformation | ||
107 | *tag* complex rare DSL language construct | ||
108 | *test* trivial rare Boolean decision | ||
109 | *operator* trivial rare Values transformation | ||
110 | ========== ========================== ========== ========================= | ||
111 | |||
112 | Globals | ||
113 | ------- | ||
114 | |||
115 | A global variable is like any other template variable, except that it's | ||
116 | available in all templates and macros:: | ||
117 | |||
118 | $twig = new Twig_Environment($loader); | ||
119 | $twig->addGlobal('text', new Text()); | ||
120 | |||
121 | You can then use the ``text`` variable anywhere in a template: | ||
122 | |||
123 | .. code-block:: jinja | ||
124 | |||
125 | {{ text.lipsum(40) }} | ||
126 | |||
127 | Filters | ||
128 | ------- | ||
129 | |||
130 | A filter is a regular PHP function or an object method that takes the left | ||
131 | side of the filter (before the pipe ``|``) as first argument and the extra | ||
132 | arguments passed to the filter (within parentheses ``()``) as extra arguments. | ||
133 | |||
134 | Defining a filter is as easy as associating the filter name with a PHP | ||
135 | callable. For instance, let's say you have the following code in a template: | ||
136 | |||
137 | .. code-block:: jinja | ||
138 | |||
139 | {{ 'TWIG'|lower }} | ||
140 | |||
141 | When compiling this template to PHP, Twig looks for the PHP callable | ||
142 | associated with the ``lower`` filter. The ``lower`` filter is a built-in Twig | ||
143 | filter, and it is simply mapped to the PHP ``strtolower()`` function. After | ||
144 | compilation, the generated PHP code is roughly equivalent to: | ||
145 | |||
146 | .. code-block:: html+php | ||
147 | |||
148 | <?php echo strtolower('TWIG') ?> | ||
149 | |||
150 | As you can see, the ``'TWIG'`` string is passed as a first argument to the PHP | ||
151 | function. | ||
152 | |||
153 | A filter can also take extra arguments like in the following example: | ||
154 | |||
155 | .. code-block:: jinja | ||
156 | |||
157 | {{ now|date('d/m/Y') }} | ||
158 | |||
159 | In this case, the extra arguments are passed to the function after the main | ||
160 | argument, and the compiled code is equivalent to: | ||
161 | |||
162 | .. code-block:: html+php | ||
163 | |||
164 | <?php echo twig_date_format_filter($now, 'd/m/Y') ?> | ||
165 | |||
166 | Let's see how to create a new filter. | ||
167 | |||
168 | In this section, we will create a ``rot13`` filter, which should return the | ||
169 | `rot13`_ transformation of a string. Here is an example of its usage and the | ||
170 | expected output: | ||
171 | |||
172 | .. code-block:: jinja | ||
173 | |||
174 | {{ "Twig"|rot13 }} | ||
175 | |||
176 | {# should displays Gjvt #} | ||
177 | |||
178 | Adding a filter is as simple as calling the ``addFilter()`` method on the | ||
179 | ``Twig_Environment`` instance:: | ||
180 | |||
181 | $twig = new Twig_Environment($loader); | ||
182 | $twig->addFilter('rot13', new Twig_Filter_Function('str_rot13')); | ||
183 | |||
184 | The second argument of ``addFilter()`` is an instance of ``Twig_Filter``. | ||
185 | Here, we use ``Twig_Filter_Function`` as the filter is a PHP function. The | ||
186 | first argument passed to the ``Twig_Filter_Function`` constructor is the name | ||
187 | of the PHP function to call, here ``str_rot13``, a native PHP function. | ||
188 | |||
189 | Let's say I now want to be able to add a prefix before the converted string: | ||
190 | |||
191 | .. code-block:: jinja | ||
192 | |||
193 | {{ "Twig"|rot13('prefix_') }} | ||
194 | |||
195 | {# should displays prefix_Gjvt #} | ||
196 | |||
197 | As the PHP ``str_rot13()`` function does not support this requirement, let's | ||
198 | create a new PHP function:: | ||
199 | |||
200 | function project_compute_rot13($string, $prefix = '') | ||
201 | { | ||
202 | return $prefix.str_rot13($string); | ||
203 | } | ||
204 | |||
205 | As you can see, the ``prefix`` argument of the filter is passed as an extra | ||
206 | argument to the ``project_compute_rot13()`` function. | ||
207 | |||
208 | Adding this filter is as easy as before:: | ||
209 | |||
210 | $twig->addFilter('rot13', new Twig_Filter_Function('project_compute_rot13')); | ||
211 | |||
212 | For better encapsulation, a filter can also be defined as a static method of a | ||
213 | class. The ``Twig_Filter_Function`` class can also be used to register such | ||
214 | static methods as filters:: | ||
215 | |||
216 | $twig->addFilter('rot13', new Twig_Filter_Function('SomeClass::rot13Filter')); | ||
217 | |||
218 | .. tip:: | ||
219 | |||
220 | In an extension, you can also define a filter as a static method of the | ||
221 | extension class. | ||
222 | |||
223 | Environment aware Filters | ||
224 | ~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
225 | |||
226 | The ``Twig_Filter`` classes take options as their last argument. For instance, | ||
227 | if you want access to the current environment instance in your filter, set the | ||
228 | ``needs_environment`` option to ``true``:: | ||
229 | |||
230 | $filter = new Twig_Filter_Function('str_rot13', array('needs_environment' => true)); | ||
231 | |||
232 | Twig will then pass the current environment as the first argument to the | ||
233 | filter call:: | ||
234 | |||
235 | function twig_compute_rot13(Twig_Environment $env, $string) | ||
236 | { | ||
237 | // get the current charset for instance | ||
238 | $charset = $env->getCharset(); | ||
239 | |||
240 | return str_rot13($string); | ||
241 | } | ||
242 | |||
243 | Automatic Escaping | ||
244 | ~~~~~~~~~~~~~~~~~~ | ||
245 | |||
246 | If automatic escaping is enabled, the output of the filter may be escaped | ||
247 | before printing. If your filter acts as an escaper (or explicitly outputs html | ||
248 | or javascript code), you will want the raw output to be printed. In such a | ||
249 | case, set the ``is_safe`` option:: | ||
250 | |||
251 | $filter = new Twig_Filter_Function('nl2br', array('is_safe' => array('html'))); | ||
252 | |||
253 | Some filters may need to work on input that is already escaped or safe, for | ||
254 | example when adding (safe) html tags to originally unsafe output. In such a | ||
255 | case, set the ``pre_escape`` option to escape the input data before it is run | ||
256 | through your filter:: | ||
257 | |||
258 | $filter = new Twig_Filter_Function('somefilter', array('pre_escape' => 'html', 'is_safe' => array('html'))); | ||
259 | |||
260 | Dynamic Filters | ||
261 | ~~~~~~~~~~~~~~~ | ||
262 | |||
263 | .. versionadded:: 1.5 | ||
264 | Dynamic filters support was added in Twig 1.5. | ||
265 | |||
266 | A filter name containing the special ``*`` character is a dynamic filter as | ||
267 | the ``*`` can be any string:: | ||
268 | |||
269 | $twig->addFilter('*_path_*', new Twig_Filter_Function('twig_path')); | ||
270 | |||
271 | function twig_path($name, $arguments) | ||
272 | { | ||
273 | // ... | ||
274 | } | ||
275 | |||
276 | The following filters will be matched by the above defined dynamic filter: | ||
277 | |||
278 | * ``product_path`` | ||
279 | * ``category_path`` | ||
280 | |||
281 | A dynamic filter can define more than one dynamic parts:: | ||
282 | |||
283 | $twig->addFilter('*_path_*', new Twig_Filter_Function('twig_path')); | ||
284 | |||
285 | function twig_path($name, $suffix, $arguments) | ||
286 | { | ||
287 | // ... | ||
288 | } | ||
289 | |||
290 | The filter will receive all dynamic part values before the normal filters | ||
291 | arguments. For instance, a call to ``'foo'|a_path_b()`` will result in the | ||
292 | following PHP call: ``twig_path('a', 'b', 'foo')``. | ||
293 | |||
294 | Functions | ||
295 | --------- | ||
296 | |||
297 | A function is a regular PHP function or an object method that can be called from | ||
298 | templates. | ||
299 | |||
300 | .. code-block:: jinja | ||
301 | |||
302 | {{ constant("DATE_W3C") }} | ||
303 | |||
304 | When compiling this template to PHP, Twig looks for the PHP callable | ||
305 | associated with the ``constant`` function. The ``constant`` function is a built-in Twig | ||
306 | function, and it is simply mapped to the PHP ``constant()`` function. After | ||
307 | compilation, the generated PHP code is roughly equivalent to: | ||
308 | |||
309 | .. code-block:: html+php | ||
310 | |||
311 | <?php echo constant('DATE_W3C') ?> | ||
312 | |||
313 | Adding a function is similar to adding a filter. This can be done by calling the | ||
314 | ``addFunction()`` method on the ``Twig_Environment`` instance:: | ||
315 | |||
316 | $twig = new Twig_Environment($loader); | ||
317 | $twig->addFunction('functionName', new Twig_Function_Function('someFunction')); | ||
318 | |||
319 | You can also expose extension methods as functions in your templates:: | ||
320 | |||
321 | // $this is an object that implements Twig_ExtensionInterface. | ||
322 | $twig = new Twig_Environment($loader); | ||
323 | $twig->addFunction('otherFunction', new Twig_Function_Method($this, 'someMethod')); | ||
324 | |||
325 | Functions also support ``needs_environment`` and ``is_safe`` parameters. | ||
326 | |||
327 | Dynamic Functions | ||
328 | ~~~~~~~~~~~~~~~~~ | ||
329 | |||
330 | .. versionadded:: 1.5 | ||
331 | Dynamic functions support was added in Twig 1.5. | ||
332 | |||
333 | A function name containing the special ``*`` character is a dynamic function | ||
334 | as the ``*`` can be any string:: | ||
335 | |||
336 | $twig->addFunction('*_path', new Twig_Function_Function('twig_path')); | ||
337 | |||
338 | function twig_path($name, $arguments) | ||
339 | { | ||
340 | // ... | ||
341 | } | ||
342 | |||
343 | The following functions will be matched by the above defined dynamic function: | ||
344 | |||
345 | * ``product_path`` | ||
346 | * ``category_path`` | ||
347 | |||
348 | A dynamic function can define more than one dynamic parts:: | ||
349 | |||
350 | $twig->addFilter('*_path_*', new Twig_Filter_Function('twig_path')); | ||
351 | |||
352 | function twig_path($name, $suffix, $arguments) | ||
353 | { | ||
354 | // ... | ||
355 | } | ||
356 | |||
357 | The function will receive all dynamic part values before the normal functions | ||
358 | arguments. For instance, a call to ``a_path_b('foo')`` will result in the | ||
359 | following PHP call: ``twig_path('a', 'b', 'foo')``. | ||
360 | |||
361 | Tags | ||
362 | ---- | ||
363 | |||
364 | One of the most exciting feature of a template engine like Twig is the | ||
365 | possibility to define new language constructs. This is also the most complex | ||
366 | feature as you need to understand how Twig's internals work. | ||
367 | |||
368 | Let's create a simple ``set`` tag that allows the definition of simple | ||
369 | variables from within a template. The tag can be used like follows: | ||
370 | |||
371 | .. code-block:: jinja | ||
372 | |||
373 | {% set name = "value" %} | ||
374 | |||
375 | {{ name }} | ||
376 | |||
377 | {# should output value #} | ||
378 | |||
379 | .. note:: | ||
380 | |||
381 | The ``set`` tag is part of the Core extension and as such is always | ||
382 | available. The built-in version is slightly more powerful and supports | ||
383 | multiple assignments by default (cf. the template designers chapter for | ||
384 | more information). | ||
385 | |||
386 | Three steps are needed to define a new tag: | ||
387 | |||
388 | * Defining a Token Parser class (responsible for parsing the template code); | ||
389 | |||
390 | * Defining a Node class (responsible for converting the parsed code to PHP); | ||
391 | |||
392 | * Registering the tag. | ||
393 | |||
394 | Registering a new tag | ||
395 | ~~~~~~~~~~~~~~~~~~~~~ | ||
396 | |||
397 | Adding a tag is as simple as calling the ``addTokenParser`` method on the | ||
398 | ``Twig_Environment`` instance:: | ||
399 | |||
400 | $twig = new Twig_Environment($loader); | ||
401 | $twig->addTokenParser(new Project_Set_TokenParser()); | ||
402 | |||
403 | Defining a Token Parser | ||
404 | ~~~~~~~~~~~~~~~~~~~~~~~ | ||
405 | |||
406 | Now, let's see the actual code of this class:: | ||
407 | |||
408 | class Project_Set_TokenParser extends Twig_TokenParser | ||
409 | { | ||
410 | public function parse(Twig_Token $token) | ||
411 | { | ||
412 | $lineno = $token->getLine(); | ||
413 | $name = $this->parser->getStream()->expect(Twig_Token::NAME_TYPE)->getValue(); | ||
414 | $this->parser->getStream()->expect(Twig_Token::OPERATOR_TYPE, '='); | ||
415 | $value = $this->parser->getExpressionParser()->parseExpression(); | ||
416 | |||
417 | $this->parser->getStream()->expect(Twig_Token::BLOCK_END_TYPE); | ||
418 | |||
419 | return new Project_Set_Node($name, $value, $lineno, $this->getTag()); | ||
420 | } | ||
421 | |||
422 | public function getTag() | ||
423 | { | ||
424 | return 'set'; | ||
425 | } | ||
426 | } | ||
427 | |||
428 | The ``getTag()`` method must return the tag we want to parse, here ``set``. | ||
429 | |||
430 | The ``parse()`` method is invoked whenever the parser encounters a ``set`` | ||
431 | tag. It should return a ``Twig_Node`` instance that represents the node (the | ||
432 | ``Project_Set_Node`` calls creating is explained in the next section). | ||
433 | |||
434 | The parsing process is simplified thanks to a bunch of methods you can call | ||
435 | from the token stream (``$this->parser->getStream()``): | ||
436 | |||
437 | * ``getCurrent()``: Gets the current token in the stream. | ||
438 | |||
439 | * ``next()``: Moves to the next token in the stream, *but returns the old one*. | ||
440 | |||
441 | * ``test($type)``, ``test($value)`` or ``test($type, $value)``: Determines whether | ||
442 | the current token is of a particular type or value (or both). The value may be an | ||
443 | array of several possible values. | ||
444 | |||
445 | * ``expect($type[, $value[, $message]])``: If the current token isn't of the given | ||
446 | type/value a syntax error is thrown. Otherwise, if the type and value are correct, | ||
447 | the token is returned and the stream moves to the next token. | ||
448 | |||
449 | * ``look()``: Looks a the next token without consuming it. | ||
450 | |||
451 | Parsing expressions is done by calling the ``parseExpression()`` like we did for | ||
452 | the ``set`` tag. | ||
453 | |||
454 | .. tip:: | ||
455 | |||
456 | Reading the existing ``TokenParser`` classes is the best way to learn all | ||
457 | the nitty-gritty details of the parsing process. | ||
458 | |||
459 | Defining a Node | ||
460 | ~~~~~~~~~~~~~~~ | ||
461 | |||
462 | The ``Project_Set_Node`` class itself is rather simple:: | ||
463 | |||
464 | class Project_Set_Node extends Twig_Node | ||
465 | { | ||
466 | public function __construct($name, Twig_Node_Expression $value, $lineno, $tag = null) | ||
467 | { | ||
468 | parent::__construct(array('value' => $value), array('name' => $name), $lineno, $tag); | ||
469 | } | ||
470 | |||
471 | public function compile(Twig_Compiler $compiler) | ||
472 | { | ||
473 | $compiler | ||
474 | ->addDebugInfo($this) | ||
475 | ->write('$context[\''.$this->getAttribute('name').'\'] = ') | ||
476 | ->subcompile($this->getNode('value')) | ||
477 | ->raw(";\n") | ||
478 | ; | ||
479 | } | ||
480 | } | ||
481 | |||
482 | The compiler implements a fluid interface and provides methods that helps the | ||
483 | developer generate beautiful and readable PHP code: | ||
484 | |||
485 | * ``subcompile()``: Compiles a node. | ||
486 | |||
487 | * ``raw()``: Writes the given string as is. | ||
488 | |||
489 | * ``write()``: Writes the given string by adding indentation at the beginning | ||
490 | of each line. | ||
491 | |||
492 | * ``string()``: Writes a quoted string. | ||
493 | |||
494 | * ``repr()``: Writes a PHP representation of a given value (see | ||
495 | ``Twig_Node_For`` for a usage example). | ||
496 | |||
497 | * ``addDebugInfo()``: Adds the line of the original template file related to | ||
498 | the current node as a comment. | ||
499 | |||
500 | * ``indent()``: Indents the generated code (see ``Twig_Node_Block`` for a | ||
501 | usage example). | ||
502 | |||
503 | * ``outdent()``: Outdents the generated code (see ``Twig_Node_Block`` for a | ||
504 | usage example). | ||
505 | |||
506 | .. _creating_extensions: | ||
507 | |||
508 | Creating an Extension | ||
509 | --------------------- | ||
510 | |||
511 | The main motivation for writing an extension is to move often used code into a | ||
512 | reusable class like adding support for internationalization. An extension can | ||
513 | define tags, filters, tests, operators, global variables, functions, and node | ||
514 | visitors. | ||
515 | |||
516 | Creating an extension also makes for a better separation of code that is | ||
517 | executed at compilation time and code needed at runtime. As such, it makes | ||
518 | your code faster. | ||
519 | |||
520 | Most of the time, it is useful to create a single extension for your project, | ||
521 | to host all the specific tags and filters you want to add to Twig. | ||
522 | |||
523 | .. tip:: | ||
524 | |||
525 | When packaging your code into an extension, Twig is smart enough to | ||
526 | recompile your templates whenever you make a change to it (when the | ||
527 | ``auto_reload`` is enabled). | ||
528 | |||
529 | .. note:: | ||
530 | |||
531 | Before writing your own extensions, have a look at the Twig official | ||
532 | extension repository: http://github.com/fabpot/Twig-extensions. | ||
533 | |||
534 | An extension is a class that implements the following interface:: | ||
535 | |||
536 | interface Twig_ExtensionInterface | ||
537 | { | ||
538 | /** | ||
539 | * Initializes the runtime environment. | ||
540 | * | ||
541 | * This is where you can load some file that contains filter functions for instance. | ||
542 | * | ||
543 | * @param Twig_Environment $environment The current Twig_Environment instance | ||
544 | */ | ||
545 | function initRuntime(Twig_Environment $environment); | ||
546 | |||
547 | /** | ||
548 | * Returns the token parser instances to add to the existing list. | ||
549 | * | ||
550 | * @return array An array of Twig_TokenParserInterface or Twig_TokenParserBrokerInterface instances | ||
551 | */ | ||
552 | function getTokenParsers(); | ||
553 | |||
554 | /** | ||
555 | * Returns the node visitor instances to add to the existing list. | ||
556 | * | ||
557 | * @return array An array of Twig_NodeVisitorInterface instances | ||
558 | */ | ||
559 | function getNodeVisitors(); | ||
560 | |||
561 | /** | ||
562 | * Returns a list of filters to add to the existing list. | ||
563 | * | ||
564 | * @return array An array of filters | ||
565 | */ | ||
566 | function getFilters(); | ||
567 | |||
568 | /** | ||
569 | * Returns a list of tests to add to the existing list. | ||
570 | * | ||
571 | * @return array An array of tests | ||
572 | */ | ||
573 | function getTests(); | ||
574 | |||
575 | /** | ||
576 | * Returns a list of functions to add to the existing list. | ||
577 | * | ||
578 | * @return array An array of functions | ||
579 | */ | ||
580 | function getFunctions(); | ||
581 | |||
582 | /** | ||
583 | * Returns a list of operators to add to the existing list. | ||
584 | * | ||
585 | * @return array An array of operators | ||
586 | */ | ||
587 | function getOperators(); | ||
588 | |||
589 | /** | ||
590 | * Returns a list of global variables to add to the existing list. | ||
591 | * | ||
592 | * @return array An array of global variables | ||
593 | */ | ||
594 | function getGlobals(); | ||
595 | |||
596 | /** | ||
597 | * Returns the name of the extension. | ||
598 | * | ||
599 | * @return string The extension name | ||
600 | */ | ||
601 | function getName(); | ||
602 | } | ||
603 | |||
604 | To keep your extension class clean and lean, it can inherit from the built-in | ||
605 | ``Twig_Extension`` class instead of implementing the whole interface. That | ||
606 | way, you just need to implement the ``getName()`` method as the | ||
607 | ``Twig_Extension`` provides empty implementations for all other methods. | ||
608 | |||
609 | The ``getName()`` method must return a unique identifier for your extension. | ||
610 | |||
611 | Now, with this information in mind, let's create the most basic extension | ||
612 | possible:: | ||
613 | |||
614 | class Project_Twig_Extension extends Twig_Extension | ||
615 | { | ||
616 | public function getName() | ||
617 | { | ||
618 | return 'project'; | ||
619 | } | ||
620 | } | ||
621 | |||
622 | .. note:: | ||
623 | |||
624 | Of course, this extension does nothing for now. We will customize it in | ||
625 | the next sections. | ||
626 | |||
627 | Twig does not care where you save your extension on the filesystem, as all | ||
628 | extensions must be registered explicitly to be available in your templates. | ||
629 | |||
630 | You can register an extension by using the ``addExtension()`` method on your | ||
631 | main ``Environment`` object:: | ||
632 | |||
633 | $twig = new Twig_Environment($loader); | ||
634 | $twig->addExtension(new Project_Twig_Extension()); | ||
635 | |||
636 | Of course, you need to first load the extension file by either using | ||
637 | ``require_once()`` or by using an autoloader (see `spl_autoload_register()`_). | ||
638 | |||
639 | .. tip:: | ||
640 | |||
641 | The bundled extensions are great examples of how extensions work. | ||
642 | |||
643 | Globals | ||
644 | ~~~~~~~ | ||
645 | |||
646 | Global variables can be registered in an extension via the ``getGlobals()`` | ||
647 | method:: | ||
648 | |||
649 | class Project_Twig_Extension extends Twig_Extension | ||
650 | { | ||
651 | public function getGlobals() | ||
652 | { | ||
653 | return array( | ||
654 | 'text' => new Text(), | ||
655 | ); | ||
656 | } | ||
657 | |||
658 | // ... | ||
659 | } | ||
660 | |||
661 | Functions | ||
662 | ~~~~~~~~~ | ||
663 | |||
664 | Functions can be registered in an extension via the ``getFunctions()`` | ||
665 | method:: | ||
666 | |||
667 | class Project_Twig_Extension extends Twig_Extension | ||
668 | { | ||
669 | public function getFunctions() | ||
670 | { | ||
671 | return array( | ||
672 | 'lipsum' => new Twig_Function_Function('generate_lipsum'), | ||
673 | ); | ||
674 | } | ||
675 | |||
676 | // ... | ||
677 | } | ||
678 | |||
679 | Filters | ||
680 | ~~~~~~~ | ||
681 | |||
682 | To add a filter to an extension, you need to override the ``getFilters()`` | ||
683 | method. This method must return an array of filters to add to the Twig | ||
684 | environment:: | ||
685 | |||
686 | class Project_Twig_Extension extends Twig_Extension | ||
687 | { | ||
688 | public function getFilters() | ||
689 | { | ||
690 | return array( | ||
691 | 'rot13' => new Twig_Filter_Function('str_rot13'), | ||
692 | ); | ||
693 | } | ||
694 | |||
695 | // ... | ||
696 | } | ||
697 | |||
698 | As you can see in the above code, the ``getFilters()`` method returns an array | ||
699 | where keys are the name of the filters (``rot13``) and the values the | ||
700 | definition of the filter (``new Twig_Filter_Function('str_rot13')``). | ||
701 | |||
702 | As seen in the previous chapter, you can also define filters as static methods | ||
703 | on the extension class:: | ||
704 | |||
705 | $twig->addFilter('rot13', new Twig_Filter_Function('Project_Twig_Extension::rot13Filter')); | ||
706 | |||
707 | You can also use ``Twig_Filter_Method`` instead of ``Twig_Filter_Function`` | ||
708 | when defining a filter to use a method:: | ||
709 | |||
710 | class Project_Twig_Extension extends Twig_Extension | ||
711 | { | ||
712 | public function getFilters() | ||
713 | { | ||
714 | return array( | ||
715 | 'rot13' => new Twig_Filter_Method($this, 'rot13Filter'), | ||
716 | ); | ||
717 | } | ||
718 | |||
719 | public function rot13Filter($string) | ||
720 | { | ||
721 | return str_rot13($string); | ||
722 | } | ||
723 | |||
724 | // ... | ||
725 | } | ||
726 | |||
727 | The first argument of the ``Twig_Filter_Method`` constructor is always | ||
728 | ``$this``, the current extension object. The second one is the name of the | ||
729 | method to call. | ||
730 | |||
731 | Using methods for filters is a great way to package your filter without | ||
732 | polluting the global namespace. This also gives the developer more flexibility | ||
733 | at the cost of a small overhead. | ||
734 | |||
735 | Overriding default Filters | ||
736 | .......................... | ||
737 | |||
738 | If some default core filters do not suit your needs, you can easily override | ||
739 | them by creating your own extension. Just use the same names as the one you | ||
740 | want to override:: | ||
741 | |||
742 | class MyCoreExtension extends Twig_Extension | ||
743 | { | ||
744 | public function getFilters() | ||
745 | { | ||
746 | return array( | ||
747 | 'date' => new Twig_Filter_Method($this, 'dateFilter'), | ||
748 | // ... | ||
749 | ); | ||
750 | } | ||
751 | |||
752 | public function dateFilter($timestamp, $format = 'F j, Y H:i') | ||
753 | { | ||
754 | return '...'.twig_date_format_filter($timestamp, $format); | ||
755 | } | ||
756 | |||
757 | public function getName() | ||
758 | { | ||
759 | return 'project'; | ||
760 | } | ||
761 | } | ||
762 | |||
763 | Here, we override the ``date`` filter with a custom one. Using this extension | ||
764 | is as simple as registering the ``MyCoreExtension`` extension by calling the | ||
765 | ``addExtension()`` method on the environment instance:: | ||
766 | |||
767 | $twig = new Twig_Environment($loader); | ||
768 | $twig->addExtension(new MyCoreExtension()); | ||
769 | |||
770 | Tags | ||
771 | ~~~~ | ||
772 | |||
773 | Adding a tag in an extension can be done by overriding the | ||
774 | ``getTokenParsers()`` method. This method must return an array of tags to add | ||
775 | to the Twig environment:: | ||
776 | |||
777 | class Project_Twig_Extension extends Twig_Extension | ||
778 | { | ||
779 | public function getTokenParsers() | ||
780 | { | ||
781 | return array(new Project_Set_TokenParser()); | ||
782 | } | ||
783 | |||
784 | // ... | ||
785 | } | ||
786 | |||
787 | In the above code, we have added a single new tag, defined by the | ||
788 | ``Project_Set_TokenParser`` class. The ``Project_Set_TokenParser`` class is | ||
789 | responsible for parsing the tag and compiling it to PHP. | ||
790 | |||
791 | Operators | ||
792 | ~~~~~~~~~ | ||
793 | |||
794 | The ``getOperators()`` methods allows to add new operators. Here is how to add | ||
795 | ``!``, ``||``, and ``&&`` operators:: | ||
796 | |||
797 | class Project_Twig_Extension extends Twig_Extension | ||
798 | { | ||
799 | public function getOperators() | ||
800 | { | ||
801 | return array( | ||
802 | array( | ||
803 | '!' => array('precedence' => 50, 'class' => 'Twig_Node_Expression_Unary_Not'), | ||
804 | ), | ||
805 | array( | ||
806 | '||' => array('precedence' => 10, 'class' => 'Twig_Node_Expression_Binary_Or', 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT), | ||
807 | '&&' => array('precedence' => 15, 'class' => 'Twig_Node_Expression_Binary_And', 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT), | ||
808 | ), | ||
809 | ); | ||
810 | } | ||
811 | |||
812 | // ... | ||
813 | } | ||
814 | |||
815 | Tests | ||
816 | ~~~~~ | ||
817 | |||
818 | The ``getTests()`` methods allows to add new test functions:: | ||
819 | |||
820 | class Project_Twig_Extension extends Twig_Extension | ||
821 | { | ||
822 | public function getTests() | ||
823 | { | ||
824 | return array( | ||
825 | 'even' => new Twig_Test_Function('twig_test_even'), | ||
826 | ); | ||
827 | } | ||
828 | |||
829 | // ... | ||
830 | } | ||
831 | |||
832 | Testing an Extension | ||
833 | -------------------- | ||
834 | |||
835 | .. versionadded:: 1.10 | ||
836 | Support for functional tests was added in Twig 1.10. | ||
837 | |||
838 | Functional Tests | ||
839 | ~~~~~~~~~~~~~~~~ | ||
840 | |||
841 | You can create functional tests for extensions simply by creating the | ||
842 | following file structure in your test directory:: | ||
843 | |||
844 | Fixtures/ | ||
845 | filters/ | ||
846 | foo.test | ||
847 | bar.test | ||
848 | functions/ | ||
849 | foo.test | ||
850 | bar.test | ||
851 | tags/ | ||
852 | foo.test | ||
853 | bar.test | ||
854 | IntegrationTest.php | ||
855 | |||
856 | The ``IntegrationTest.php`` file should look like this:: | ||
857 | |||
858 | class Project_Tests_IntegrationTest extends Twig_Test_IntegrationTestCase | ||
859 | { | ||
860 | public function getExtensions() | ||
861 | { | ||
862 | return array( | ||
863 | new Project_Twig_Extension1(), | ||
864 | new Project_Twig_Extension2(), | ||
865 | ); | ||
866 | } | ||
867 | |||
868 | public function getFixturesDir() | ||
869 | { | ||
870 | return dirname(__FILE__).'/Fixtures/'; | ||
871 | } | ||
872 | } | ||
873 | |||
874 | Fixtures examples can be found within the Twig repository | ||
875 | `tests/Twig/Fixtures`_ directory. | ||
876 | |||
877 | Node Tests | ||
878 | ~~~~~~~~~~ | ||
879 | |||
880 | Testing the node visitors can be complex, so extend your test cases from | ||
881 | ``Twig_Test_NodeTestCase``. Examples can be found in the Twig repository | ||
882 | `tests/Twig/Node`_ directory. | ||
883 | |||
884 | .. _`spl_autoload_register()`: http://www.php.net/spl_autoload_register | ||
885 | .. _`rot13`: http://www.php.net/manual/en/function.str-rot13.php | ||
886 | .. _`tests/Twig/Fixtures`: https://github.com/fabpot/Twig/tree/master/test/Twig/Tests/Fixtures | ||
887 | .. _`tests/Twig/Node`: https://github.com/fabpot/Twig/tree/master/test/Twig/Tests/Node | ||
diff --git a/vendor/twig/twig/doc/api.rst b/vendor/twig/twig/doc/api.rst deleted file mode 100644 index cbccb0f7..00000000 --- a/vendor/twig/twig/doc/api.rst +++ /dev/null | |||
@@ -1,529 +0,0 @@ | |||
1 | Twig for Developers | ||
2 | =================== | ||
3 | |||
4 | This chapter describes the API to Twig and not the template language. It will | ||
5 | be most useful as reference to those implementing the template interface to | ||
6 | the application and not those who are creating Twig templates. | ||
7 | |||
8 | Basics | ||
9 | ------ | ||
10 | |||
11 | Twig uses a central object called the **environment** (of class | ||
12 | ``Twig_Environment``). Instances of this class are used to store the | ||
13 | configuration and extensions, and are used to load templates from the file | ||
14 | system or other locations. | ||
15 | |||
16 | Most applications will create one ``Twig_Environment`` object on application | ||
17 | initialization and use that to load templates. In some cases it's however | ||
18 | useful to have multiple environments side by side, if different configurations | ||
19 | are in use. | ||
20 | |||
21 | The simplest way to configure Twig to load templates for your application | ||
22 | looks roughly like this:: | ||
23 | |||
24 | require_once '/path/to/lib/Twig/Autoloader.php'; | ||
25 | Twig_Autoloader::register(); | ||
26 | |||
27 | $loader = new Twig_Loader_Filesystem('/path/to/templates'); | ||
28 | $twig = new Twig_Environment($loader, array( | ||
29 | 'cache' => '/path/to/compilation_cache', | ||
30 | )); | ||
31 | |||
32 | This will create a template environment with the default settings and a loader | ||
33 | that looks up the templates in the ``/path/to/templates/`` folder. Different | ||
34 | loaders are available and you can also write your own if you want to load | ||
35 | templates from a database or other resources. | ||
36 | |||
37 | .. note:: | ||
38 | |||
39 | Notice that the second argument of the environment is an array of options. | ||
40 | The ``cache`` option is a compilation cache directory, where Twig caches | ||
41 | the compiled templates to avoid the parsing phase for sub-sequent | ||
42 | requests. It is very different from the cache you might want to add for | ||
43 | the evaluated templates. For such a need, you can use any available PHP | ||
44 | cache library. | ||
45 | |||
46 | To load a template from this environment you just have to call the | ||
47 | ``loadTemplate()`` method which then returns a ``Twig_Template`` instance:: | ||
48 | |||
49 | $template = $twig->loadTemplate('index.html'); | ||
50 | |||
51 | To render the template with some variables, call the ``render()`` method:: | ||
52 | |||
53 | echo $template->render(array('the' => 'variables', 'go' => 'here')); | ||
54 | |||
55 | .. note:: | ||
56 | |||
57 | The ``display()`` method is a shortcut to output the template directly. | ||
58 | |||
59 | You can also load and render the template in one fell swoop:: | ||
60 | |||
61 | echo $twig->render('index.html', array('the' => 'variables', 'go' => 'here')); | ||
62 | |||
63 | .. _environment_options: | ||
64 | |||
65 | Environment Options | ||
66 | ------------------- | ||
67 | |||
68 | When creating a new ``Twig_Environment`` instance, you can pass an array of | ||
69 | options as the constructor second argument:: | ||
70 | |||
71 | $twig = new Twig_Environment($loader, array('debug' => true)); | ||
72 | |||
73 | The following options are available: | ||
74 | |||
75 | * ``debug``: When set to ``true``, the generated templates have a | ||
76 | ``__toString()`` method that you can use to display the generated nodes | ||
77 | (default to ``false``). | ||
78 | |||
79 | * ``charset``: The charset used by the templates (default to ``utf-8``). | ||
80 | |||
81 | * ``base_template_class``: The base template class to use for generated | ||
82 | templates (default to ``Twig_Template``). | ||
83 | |||
84 | * ``cache``: An absolute path where to store the compiled templates, or | ||
85 | ``false`` to disable caching (which is the default). | ||
86 | |||
87 | * ``auto_reload``: When developing with Twig, it's useful to recompile the | ||
88 | template whenever the source code changes. If you don't provide a value for | ||
89 | the ``auto_reload`` option, it will be determined automatically based on the | ||
90 | ``debug`` value. | ||
91 | |||
92 | * ``strict_variables``: If set to ``false``, Twig will silently ignore invalid | ||
93 | variables (variables and or attributes/methods that do not exist) and | ||
94 | replace them with a ``null`` value. When set to ``true``, Twig throws an | ||
95 | exception instead (default to ``false``). | ||
96 | |||
97 | * ``autoescape``: If set to ``true``, auto-escaping will be enabled by default | ||
98 | for all templates (default to ``true``). As of Twig 1.8, you can set the | ||
99 | escaping strategy to use (``html``, ``js``, ``false`` to disable). | ||
100 | As of Twig 1.9, you can set the escaping strategy to use (``css``, ``url``, | ||
101 | ``html_attr``, or a PHP callback that takes the template "filename" and must | ||
102 | return the escaping strategy to use -- the callback cannot be a function name | ||
103 | to avoid collision with built-in escaping strategies). | ||
104 | |||
105 | * ``optimizations``: A flag that indicates which optimizations to apply | ||
106 | (default to ``-1`` -- all optimizations are enabled; set it to ``0`` to | ||
107 | disable). | ||
108 | |||
109 | Loaders | ||
110 | ------- | ||
111 | |||
112 | Loaders are responsible for loading templates from a resource such as the file | ||
113 | system. | ||
114 | |||
115 | Compilation Cache | ||
116 | ~~~~~~~~~~~~~~~~~ | ||
117 | |||
118 | All template loaders can cache the compiled templates on the filesystem for | ||
119 | future reuse. It speeds up Twig a lot as templates are only compiled once; and | ||
120 | the performance boost is even larger if you use a PHP accelerator such as APC. | ||
121 | See the ``cache`` and ``auto_reload`` options of ``Twig_Environment`` above | ||
122 | for more information. | ||
123 | |||
124 | Built-in Loaders | ||
125 | ~~~~~~~~~~~~~~~~ | ||
126 | |||
127 | Here is a list of the built-in loaders Twig provides: | ||
128 | |||
129 | ``Twig_Loader_Filesystem`` | ||
130 | .......................... | ||
131 | |||
132 | .. versionadded:: 1.10 | ||
133 | The ``prependPath()`` and support for namespaces were added in Twig 1.10. | ||
134 | |||
135 | ``Twig_Loader_Filesystem`` loads templates from the file system. This loader | ||
136 | can find templates in folders on the file system and is the preferred way to | ||
137 | load them:: | ||
138 | |||
139 | $loader = new Twig_Loader_Filesystem($templateDir); | ||
140 | |||
141 | It can also look for templates in an array of directories:: | ||
142 | |||
143 | $loader = new Twig_Loader_Filesystem(array($templateDir1, $templateDir2)); | ||
144 | |||
145 | With such a configuration, Twig will first look for templates in | ||
146 | ``$templateDir1`` and if they do not exist, it will fallback to look for them | ||
147 | in the ``$templateDir2``. | ||
148 | |||
149 | You can add or prepend paths via the ``addPath()`` and ``prependPath()`` | ||
150 | methods:: | ||
151 | |||
152 | $loader->addPath($templateDir3); | ||
153 | $loader->prependPath($templateDir4); | ||
154 | |||
155 | The filesystem loader also supports namespaced templates. This allows to group | ||
156 | your templates under different namespaces which have their own template paths. | ||
157 | |||
158 | When using the ``setPaths()``, ``addPath()``, and ``prependPath()`` methods, | ||
159 | specify the namespace as the second argument (when not specified, these | ||
160 | methods act on the "main" namespace):: | ||
161 | |||
162 | $loader->addPath($templateDir, 'admin'); | ||
163 | |||
164 | Namespaced templates can be accessed via the special | ||
165 | ``@namespace_name/template_path`` notation:: | ||
166 | |||
167 | $twig->render('@admin/index.html', array()); | ||
168 | |||
169 | ``Twig_Loader_String`` | ||
170 | ...................... | ||
171 | |||
172 | ``Twig_Loader_String`` loads templates from strings. It's a dummy loader as | ||
173 | the template reference is the template source code:: | ||
174 | |||
175 | $loader = new Twig_Loader_String(); | ||
176 | $twig = new Twig_Environment($loader); | ||
177 | |||
178 | echo $twig->render('Hello {{ name }}!', array('name' => 'Fabien')); | ||
179 | |||
180 | This loader should only be used for unit testing as it has severe limitations: | ||
181 | several tags, like ``extends`` or ``include`` do not make sense to use as the | ||
182 | reference to the template is the template source code itself. | ||
183 | |||
184 | ``Twig_Loader_Array`` | ||
185 | ..................... | ||
186 | |||
187 | ``Twig_Loader_Array`` loads a template from a PHP array. It's passed an array | ||
188 | of strings bound to template names:: | ||
189 | |||
190 | $loader = new Twig_Loader_Array(array( | ||
191 | 'index.html' => 'Hello {{ name }}!', | ||
192 | )); | ||
193 | $twig = new Twig_Environment($loader); | ||
194 | |||
195 | echo $twig->render('index.html', array('name' => 'Fabien')); | ||
196 | |||
197 | This loader is very useful for unit testing. It can also be used for small | ||
198 | projects where storing all templates in a single PHP file might make sense. | ||
199 | |||
200 | .. tip:: | ||
201 | |||
202 | When using the ``Array`` or ``String`` loaders with a cache mechanism, you | ||
203 | should know that a new cache key is generated each time a template content | ||
204 | "changes" (the cache key being the source code of the template). If you | ||
205 | don't want to see your cache grows out of control, you need to take care | ||
206 | of clearing the old cache file by yourself. | ||
207 | |||
208 | ``Twig_Loader_Chain`` | ||
209 | ..................... | ||
210 | |||
211 | ``Twig_Loader_Chain`` delegates the loading of templates to other loaders:: | ||
212 | |||
213 | $loader1 = new Twig_Loader_Array(array( | ||
214 | 'base.html' => '{% block content %}{% endblock %}', | ||
215 | )); | ||
216 | $loader2 = new Twig_Loader_Array(array( | ||
217 | 'index.html' => '{% extends "base.twig" %}{% block content %}Hello {{ name }}{% endblock %}', | ||
218 | 'base.html' => 'Will never be loaded', | ||
219 | )); | ||
220 | |||
221 | $loader = new Twig_Loader_Chain(array($loader1, $loader2)); | ||
222 | |||
223 | $twig = new Twig_Environment($loader); | ||
224 | |||
225 | When looking for a template, Twig will try each loader in turn and it will | ||
226 | return as soon as the template is found. When rendering the ``index.html`` | ||
227 | template from the above example, Twig will load it with ``$loader2`` but the | ||
228 | ``base.html`` template will be loaded from ``$loader1``. | ||
229 | |||
230 | ``Twig_Loader_Chain`` accepts any loader that implements | ||
231 | ``Twig_LoaderInterface``. | ||
232 | |||
233 | .. note:: | ||
234 | |||
235 | You can also add loaders via the ``addLoader()`` method. | ||
236 | |||
237 | Create your own Loader | ||
238 | ~~~~~~~~~~~~~~~~~~~~~~ | ||
239 | |||
240 | All loaders implement the ``Twig_LoaderInterface``:: | ||
241 | |||
242 | interface Twig_LoaderInterface | ||
243 | { | ||
244 | /** | ||
245 | * Gets the source code of a template, given its name. | ||
246 | * | ||
247 | * @param string $name string The name of the template to load | ||
248 | * | ||
249 | * @return string The template source code | ||
250 | */ | ||
251 | function getSource($name); | ||
252 | |||
253 | /** | ||
254 | * Gets the cache key to use for the cache for a given template name. | ||
255 | * | ||
256 | * @param string $name string The name of the template to load | ||
257 | * | ||
258 | * @return string The cache key | ||
259 | */ | ||
260 | function getCacheKey($name); | ||
261 | |||
262 | /** | ||
263 | * Returns true if the template is still fresh. | ||
264 | * | ||
265 | * @param string $name The template name | ||
266 | * @param timestamp $time The last modification time of the cached template | ||
267 | */ | ||
268 | function isFresh($name, $time); | ||
269 | } | ||
270 | |||
271 | As an example, here is how the built-in ``Twig_Loader_String`` reads:: | ||
272 | |||
273 | class Twig_Loader_String implements Twig_LoaderInterface | ||
274 | { | ||
275 | public function getSource($name) | ||
276 | { | ||
277 | return $name; | ||
278 | } | ||
279 | |||
280 | public function getCacheKey($name) | ||
281 | { | ||
282 | return $name; | ||
283 | } | ||
284 | |||
285 | public function isFresh($name, $time) | ||
286 | { | ||
287 | return false; | ||
288 | } | ||
289 | } | ||
290 | |||
291 | The ``isFresh()`` method must return ``true`` if the current cached template | ||
292 | is still fresh, given the last modification time, or ``false`` otherwise. | ||
293 | |||
294 | .. tip:: | ||
295 | |||
296 | As of Twig 1.11.0, you can also implement ``Twig_ExistsLoaderInterface`` | ||
297 | to make your loader faster when used with the chain loader. | ||
298 | |||
299 | Using Extensions | ||
300 | ---------------- | ||
301 | |||
302 | Twig extensions are packages that add new features to Twig. Using an | ||
303 | extension is as simple as using the ``addExtension()`` method:: | ||
304 | |||
305 | $twig->addExtension(new Twig_Extension_Sandbox()); | ||
306 | |||
307 | Twig comes bundled with the following extensions: | ||
308 | |||
309 | * *Twig_Extension_Core*: Defines all the core features of Twig. | ||
310 | |||
311 | * *Twig_Extension_Escaper*: Adds automatic output-escaping and the possibility | ||
312 | to escape/unescape blocks of code. | ||
313 | |||
314 | * *Twig_Extension_Sandbox*: Adds a sandbox mode to the default Twig | ||
315 | environment, making it safe to evaluate untrusted code. | ||
316 | |||
317 | * *Twig_Extension_Optimizer*: Optimizes the node tree before compilation. | ||
318 | |||
319 | The core, escaper, and optimizer extensions do not need to be added to the | ||
320 | Twig environment, as they are registered by default. | ||
321 | |||
322 | Built-in Extensions | ||
323 | ------------------- | ||
324 | |||
325 | This section describes the features added by the built-in extensions. | ||
326 | |||
327 | .. tip:: | ||
328 | |||
329 | Read the chapter about extending Twig to learn how to create your own | ||
330 | extensions. | ||
331 | |||
332 | Core Extension | ||
333 | ~~~~~~~~~~~~~~ | ||
334 | |||
335 | The ``core`` extension defines all the core features of Twig: | ||
336 | |||
337 | * :doc:`Tags <tags/index>`; | ||
338 | * :doc:`Filters <filters/index>`; | ||
339 | * :doc:`Functions <functions/index>`; | ||
340 | * :doc:`Tests <tests/index>`. | ||
341 | |||
342 | Escaper Extension | ||
343 | ~~~~~~~~~~~~~~~~~ | ||
344 | |||
345 | The ``escaper`` extension adds automatic output escaping to Twig. It defines a | ||
346 | tag, ``autoescape``, and a filter, ``raw``. | ||
347 | |||
348 | When creating the escaper extension, you can switch on or off the global | ||
349 | output escaping strategy:: | ||
350 | |||
351 | $escaper = new Twig_Extension_Escaper('html'); | ||
352 | $twig->addExtension($escaper); | ||
353 | |||
354 | If set to ``html``, all variables in templates are escaped (using the ``html`` | ||
355 | escaping strategy), except those using the ``raw`` filter: | ||
356 | |||
357 | .. code-block:: jinja | ||
358 | |||
359 | {{ article.to_html|raw }} | ||
360 | |||
361 | You can also change the escaping mode locally by using the ``autoescape`` tag | ||
362 | (see the :doc:`autoescape<tags/autoescape>` doc for the syntax used before | ||
363 | Twig 1.8): | ||
364 | |||
365 | .. code-block:: jinja | ||
366 | |||
367 | {% autoescape 'html' %} | ||
368 | {{ var }} | ||
369 | {{ var|raw }} {# var won't be escaped #} | ||
370 | {{ var|escape }} {# var won't be double-escaped #} | ||
371 | {% endautoescape %} | ||
372 | |||
373 | .. warning:: | ||
374 | |||
375 | The ``autoescape`` tag has no effect on included files. | ||
376 | |||
377 | The escaping rules are implemented as follows: | ||
378 | |||
379 | * Literals (integers, booleans, arrays, ...) used in the template directly as | ||
380 | variables or filter arguments are never automatically escaped: | ||
381 | |||
382 | .. code-block:: jinja | ||
383 | |||
384 | {{ "Twig<br />" }} {# won't be escaped #} | ||
385 | |||
386 | {% set text = "Twig<br />" %} | ||
387 | {{ text }} {# will be escaped #} | ||
388 | |||
389 | * Expressions which the result is always a literal or a variable marked safe | ||
390 | are never automatically escaped: | ||
391 | |||
392 | .. code-block:: jinja | ||
393 | |||
394 | {{ foo ? "Twig<br />" : "<br />Twig" }} {# won't be escaped #} | ||
395 | |||
396 | {% set text = "Twig<br />" %} | ||
397 | {{ foo ? text : "<br />Twig" }} {# will be escaped #} | ||
398 | |||
399 | {% set text = "Twig<br />" %} | ||
400 | {{ foo ? text|raw : "<br />Twig" }} {# won't be escaped #} | ||
401 | |||
402 | {% set text = "Twig<br />" %} | ||
403 | {{ foo ? text|escape : "<br />Twig" }} {# the result of the expression won't be escaped #} | ||
404 | |||
405 | * Escaping is applied before printing, after any other filter is applied: | ||
406 | |||
407 | .. code-block:: jinja | ||
408 | |||
409 | {{ var|upper }} {# is equivalent to {{ var|upper|escape }} #} | ||
410 | |||
411 | * The `raw` filter should only be used at the end of the filter chain: | ||
412 | |||
413 | .. code-block:: jinja | ||
414 | |||
415 | {{ var|raw|upper }} {# will be escaped #} | ||
416 | |||
417 | {{ var|upper|raw }} {# won't be escaped #} | ||
418 | |||
419 | * Automatic escaping is not applied if the last filter in the chain is marked | ||
420 | safe for the current context (e.g. ``html`` or ``js``). ``escaper`` and | ||
421 | ``escaper('html')`` are marked safe for html, ``escaper('js')`` is marked | ||
422 | safe for javascript, ``raw`` is marked safe for everything. | ||
423 | |||
424 | .. code-block:: jinja | ||
425 | |||
426 | {% autoescape 'js' %} | ||
427 | {{ var|escape('html') }} {# will be escaped for html and javascript #} | ||
428 | {{ var }} {# will be escaped for javascript #} | ||
429 | {{ var|escape('js') }} {# won't be double-escaped #} | ||
430 | {% endautoescape %} | ||
431 | |||
432 | .. note:: | ||
433 | |||
434 | Note that autoescaping has some limitations as escaping is applied on | ||
435 | expressions after evaluation. For instance, when working with | ||
436 | concatenation, ``{{ foo|raw ~ bar }}`` won't give the expected result as | ||
437 | escaping is applied on the result of the concatenation, not on the | ||
438 | individual variables (so, the ``raw`` filter won't have any effect here). | ||
439 | |||
440 | Sandbox Extension | ||
441 | ~~~~~~~~~~~~~~~~~ | ||
442 | |||
443 | The ``sandbox`` extension can be used to evaluate untrusted code. Access to | ||
444 | unsafe attributes and methods is prohibited. The sandbox security is managed | ||
445 | by a policy instance. By default, Twig comes with one policy class: | ||
446 | ``Twig_Sandbox_SecurityPolicy``. This class allows you to white-list some | ||
447 | tags, filters, properties, and methods:: | ||
448 | |||
449 | $tags = array('if'); | ||
450 | $filters = array('upper'); | ||
451 | $methods = array( | ||
452 | 'Article' => array('getTitle', 'getBody'), | ||
453 | ); | ||
454 | $properties = array( | ||
455 | 'Article' => array('title', 'body'), | ||
456 | ); | ||
457 | $functions = array('range'); | ||
458 | $policy = new Twig_Sandbox_SecurityPolicy($tags, $filters, $methods, $properties, $functions); | ||
459 | |||
460 | With the previous configuration, the security policy will only allow usage of | ||
461 | the ``if`` tag, and the ``upper`` filter. Moreover, the templates will only be | ||
462 | able to call the ``getTitle()`` and ``getBody()`` methods on ``Article`` | ||
463 | objects, and the ``title`` and ``body`` public properties. Everything else | ||
464 | won't be allowed and will generate a ``Twig_Sandbox_SecurityError`` exception. | ||
465 | |||
466 | The policy object is the first argument of the sandbox constructor:: | ||
467 | |||
468 | $sandbox = new Twig_Extension_Sandbox($policy); | ||
469 | $twig->addExtension($sandbox); | ||
470 | |||
471 | By default, the sandbox mode is disabled and should be enabled when including | ||
472 | untrusted template code by using the ``sandbox`` tag: | ||
473 | |||
474 | .. code-block:: jinja | ||
475 | |||
476 | {% sandbox %} | ||
477 | {% include 'user.html' %} | ||
478 | {% endsandbox %} | ||
479 | |||
480 | You can sandbox all templates by passing ``true`` as the second argument of | ||
481 | the extension constructor:: | ||
482 | |||
483 | $sandbox = new Twig_Extension_Sandbox($policy, true); | ||
484 | |||
485 | Optimizer Extension | ||
486 | ~~~~~~~~~~~~~~~~~~~ | ||
487 | |||
488 | The ``optimizer`` extension optimizes the node tree before compilation:: | ||
489 | |||
490 | $twig->addExtension(new Twig_Extension_Optimizer()); | ||
491 | |||
492 | By default, all optimizations are turned on. You can select the ones you want | ||
493 | to enable by passing them to the constructor:: | ||
494 | |||
495 | $optimizer = new Twig_Extension_Optimizer(Twig_NodeVisitor_Optimizer::OPTIMIZE_FOR); | ||
496 | |||
497 | $twig->addExtension($optimizer); | ||
498 | |||
499 | Twig supports the following optimizations: | ||
500 | |||
501 | * ``Twig_NodeVisitor_Optimizer::OPTIMIZE_ALL``, enables all optimizations | ||
502 | (this is the default value). | ||
503 | * ``Twig_NodeVisitor_Optimizer::OPTIMIZE_NONE``, disables all optimizations. | ||
504 | This reduces the compilation time, but it can increase the execution time | ||
505 | and the consumed memory. | ||
506 | * ``Twig_NodeVisitor_Optimizer::OPTIMIZE_FOR``, optimizes the ``for`` tag by | ||
507 | removing the ``loop`` variable creation whenever possible. | ||
508 | * ``Twig_NodeVisitor_Optimizer::OPTIMIZE_RAW_FILTER``, removes the ``raw`` | ||
509 | filter whenever possible. | ||
510 | * ``Twig_NodeVisitor_Optimizer::OPTIMIZE_VAR_ACCESS``, simplifies the creation | ||
511 | and access of variables in the compiled templates whenever possible. | ||
512 | |||
513 | Exceptions | ||
514 | ---------- | ||
515 | |||
516 | Twig can throw exceptions: | ||
517 | |||
518 | * ``Twig_Error``: The base exception for all errors. | ||
519 | |||
520 | * ``Twig_Error_Syntax``: Thrown to tell the user that there is a problem with | ||
521 | the template syntax. | ||
522 | |||
523 | * ``Twig_Error_Runtime``: Thrown when an error occurs at runtime (when a filter | ||
524 | does not exist for instance). | ||
525 | |||
526 | * ``Twig_Error_Loader``: Thrown when an error occurs during template loading. | ||
527 | |||
528 | * ``Twig_Sandbox_SecurityError``: Thrown when an unallowed tag, filter, or | ||
529 | method is called in a sandboxed template. | ||
diff --git a/vendor/twig/twig/doc/coding_standards.rst b/vendor/twig/twig/doc/coding_standards.rst deleted file mode 100644 index e0aab35e..00000000 --- a/vendor/twig/twig/doc/coding_standards.rst +++ /dev/null | |||
@@ -1,101 +0,0 @@ | |||
1 | Coding Standards | ||
2 | ================ | ||
3 | |||
4 | When writing Twig templates, we recommend you to follow these official coding | ||
5 | standards: | ||
6 | |||
7 | * Put one (and only one) space after the start of a delimiter (``{{``, ``{%``, | ||
8 | and ``{#``) and before the end of a delimiter (``}}``, ``%}``, and ``#}``): | ||
9 | |||
10 | .. code-block:: jinja | ||
11 | |||
12 | {{ foo }} | ||
13 | {# comment #} | ||
14 | {% if foo %}{% endif %} | ||
15 | |||
16 | When using the whitespace control character, do not put any spaces between | ||
17 | it and the delimiter: | ||
18 | |||
19 | .. code-block:: jinja | ||
20 | |||
21 | {{- foo -}} | ||
22 | {#- comment -#} | ||
23 | {%- if foo -%}{%- endif -%} | ||
24 | |||
25 | * Put one (and only one) space before and after the following operators: | ||
26 | comparison operators (``==``, ``!=``, ``<``, ``>``, ``>=``, ``<=``), math | ||
27 | operators (``+``, ``-``, ``/``, ``*``, ``%``, ``//``, ``**``), logic | ||
28 | operators (``not``, ``and``, ``or``), ``~``, ``is``, ``in``, and the ternary | ||
29 | operator (``?:``): | ||
30 | |||
31 | .. code-block:: jinja | ||
32 | |||
33 | {{ 1 + 2 }} | ||
34 | {{ foo ~ bar }} | ||
35 | {{ true ? true : false }} | ||
36 | |||
37 | * Put one (and only one) space after the ``:`` sign in hashes and ``,`` in | ||
38 | arrays and hashes: | ||
39 | |||
40 | .. code-block:: jinja | ||
41 | |||
42 | {{ [1, 2, 3] }} | ||
43 | {{ {'foo': 'bar'} }} | ||
44 | |||
45 | * Do not put any spaces after an opening parenthesis and before a closing | ||
46 | parenthesis in expressions: | ||
47 | |||
48 | .. code-block:: jinja | ||
49 | |||
50 | {{ 1 + (2 * 3) }} | ||
51 | |||
52 | * Do not put any spaces before and after string delimiters: | ||
53 | |||
54 | .. code-block:: jinja | ||
55 | |||
56 | {{ 'foo' }} | ||
57 | {{ "foo" }} | ||
58 | |||
59 | * Do not put any spaces before and after the following operators: ``|``, | ||
60 | ``.``, ``..``, ``[]``: | ||
61 | |||
62 | .. code-block:: jinja | ||
63 | |||
64 | {{ foo|upper|lower }} | ||
65 | {{ user.name }} | ||
66 | {{ user[name] }} | ||
67 | {% for i in 1..12 %}{% endfor %} | ||
68 | |||
69 | * Do not put any spaces before and after the parenthesis used for filter and | ||
70 | function calls: | ||
71 | |||
72 | .. code-block:: jinja | ||
73 | |||
74 | {{ foo|default('foo') }} | ||
75 | {{ range(1..10) }} | ||
76 | |||
77 | * Do not put any spaces before and after the opening and the closing of arrays | ||
78 | and hashes: | ||
79 | |||
80 | .. code-block:: jinja | ||
81 | |||
82 | {{ [1, 2, 3] }} | ||
83 | {{ {'foo': 'bar'} }} | ||
84 | |||
85 | * Use lower cased and underscored variable names: | ||
86 | |||
87 | .. code-block:: jinja | ||
88 | |||
89 | {% set foo = 'foo' %} | ||
90 | {% set foo_bar = 'foo' %} | ||
91 | |||
92 | * Indent your code inside tags (use the same indentation as the one used for | ||
93 | the main language of the file): | ||
94 | |||
95 | .. code-block:: jinja | ||
96 | |||
97 | {% block foo %} | ||
98 | {% if true %} | ||
99 | true | ||
100 | {% endif %} | ||
101 | {% endblock %} | ||
diff --git a/vendor/twig/twig/doc/deprecated.rst b/vendor/twig/twig/doc/deprecated.rst deleted file mode 100644 index f0a3a0f0..00000000 --- a/vendor/twig/twig/doc/deprecated.rst +++ /dev/null | |||
@@ -1,98 +0,0 @@ | |||
1 | Deprecated Features | ||
2 | =================== | ||
3 | |||
4 | This document lists all deprecated features in Twig. Deprecated features are | ||
5 | kept for backward compatibility and removed in the next major release (a | ||
6 | feature that was deprecated in Twig 1.x is removed in Twig 2.0). | ||
7 | |||
8 | Token Parsers | ||
9 | ------------- | ||
10 | |||
11 | * As of Twig 1.x, the token parser broker sub-system is deprecated. The | ||
12 | following class and interface will be removed in 2.0: | ||
13 | |||
14 | * ``Twig_TokenParserBrokerInterface`` | ||
15 | * ``Twig_TokenParserBroker`` | ||
16 | |||
17 | Extensions | ||
18 | ---------- | ||
19 | |||
20 | * As of Twig 1.x, the ability to remove an extension is deprecated and the | ||
21 | ``Twig_Environment::removeExtension()`` method will be removed in 2.0. | ||
22 | |||
23 | PEAR | ||
24 | ---- | ||
25 | |||
26 | PEAR support will be discontinued in Twig 2.0, and no PEAR packages will be | ||
27 | provided. Use Composer instead. | ||
28 | |||
29 | Filters | ||
30 | ------- | ||
31 | |||
32 | * As of Twig 1.x, use ``Twig_SimpleFilter`` to add a filter. The following | ||
33 | classes and interfaces will be removed in 2.0: | ||
34 | |||
35 | * ``Twig_FilterInterface`` | ||
36 | * ``Twig_FilterCallableInterface`` | ||
37 | * ``Twig_Filter`` | ||
38 | * ``Twig_Filter_Function`` | ||
39 | * ``Twig_Filter_Method`` | ||
40 | * ``Twig_Filter_Node`` | ||
41 | |||
42 | * As of Twig 2.x, the ``Twig_SimpleFilter`` class is deprecated and will be | ||
43 | removed in Twig 3.x (use ``Twig_Filter`` instead). In Twig 2.x, | ||
44 | ``Twig_SimpleFilter`` is just an alias for ``Twig_Filter``. | ||
45 | |||
46 | Functions | ||
47 | --------- | ||
48 | |||
49 | * As of Twig 1.x, use ``Twig_SimpleFunction`` to add a function. The following | ||
50 | classes and interfaces will be removed in 2.0: | ||
51 | |||
52 | * ``Twig_FunctionInterface`` | ||
53 | * ``Twig_FunctionCallableInterface`` | ||
54 | * ``Twig_Function`` | ||
55 | * ``Twig_Function_Function`` | ||
56 | * ``Twig_Function_Method`` | ||
57 | * ``Twig_Function_Node`` | ||
58 | |||
59 | * As of Twig 2.x, the ``Twig_SimpleFunction`` class is deprecated and will be | ||
60 | removed in Twig 3.x (use ``Twig_Function`` instead). In Twig 2.x, | ||
61 | ``Twig_SimpleFunction`` is just an alias for ``Twig_Function``. | ||
62 | |||
63 | Tests | ||
64 | ----- | ||
65 | |||
66 | * As of Twig 1.x, use ``Twig_SimpleTest`` to add a test. The following classes | ||
67 | and interfaces will be removed in 2.0: | ||
68 | |||
69 | * ``Twig_TestInterface`` | ||
70 | * ``Twig_TestCallableInterface`` | ||
71 | * ``Twig_Test`` | ||
72 | * ``Twig_Test_Function`` | ||
73 | * ``Twig_Test_Method`` | ||
74 | * ``Twig_Test_Node`` | ||
75 | |||
76 | * As of Twig 2.x, the ``Twig_SimpleTest`` class is deprecated and will be | ||
77 | removed in Twig 3.x (use ``Twig_Test`` instead). In Twig 2.x, | ||
78 | ``Twig_SimpleTest`` is just an alias for ``Twig_Test``. | ||
79 | |||
80 | Interfaces | ||
81 | ---------- | ||
82 | |||
83 | * As of Twig 2.x, the following interfaces are deprecated and empty (they will | ||
84 | be removed in Twig 3.0): | ||
85 | |||
86 | * ``Twig_CompilerInterface`` (use ``Twig_Compiler`` instead) | ||
87 | * ``Twig_LexerInterface`` (use ``Twig_Lexer`` instead) | ||
88 | * ``Twig_NodeInterface`` (use ``Twig_Node`` instead) | ||
89 | * ``Twig_ParserInterface`` (use ``Twig_Parser`` instead) | ||
90 | * ``Twig_ExistsLoaderInterface`` (merged with ``Twig_LoaderInterface``) | ||
91 | * ``Twig_TemplateInterface`` (use ``Twig_Template`` instead) | ||
92 | |||
93 | Globals | ||
94 | ------- | ||
95 | |||
96 | * As of Twig 2.x, the ability to register a global variable after the runtime | ||
97 | or the extensions have been initialized is not possible anymore (but | ||
98 | changing the value of an already registered global is possible). | ||
diff --git a/vendor/twig/twig/doc/filters/abs.rst b/vendor/twig/twig/doc/filters/abs.rst deleted file mode 100644 index 3a82f62e..00000000 --- a/vendor/twig/twig/doc/filters/abs.rst +++ /dev/null | |||
@@ -1,18 +0,0 @@ | |||
1 | ``abs`` | ||
2 | ======= | ||
3 | |||
4 | The ``abs`` filter returns the absolute value. | ||
5 | |||
6 | .. code-block:: jinja | ||
7 | |||
8 | {# number = -5 #} | ||
9 | |||
10 | {{ number|abs }} | ||
11 | |||
12 | {# outputs 5 #} | ||
13 | |||
14 | .. note:: | ||
15 | |||
16 | Internally, Twig uses the PHP `abs`_ function. | ||
17 | |||
18 | .. _`abs`: http://php.net/abs | ||
diff --git a/vendor/twig/twig/doc/filters/batch.rst b/vendor/twig/twig/doc/filters/batch.rst deleted file mode 100644 index 4366b57b..00000000 --- a/vendor/twig/twig/doc/filters/batch.rst +++ /dev/null | |||
@@ -1,45 +0,0 @@ | |||
1 | ``batch`` | ||
2 | ========= | ||
3 | |||
4 | .. versionadded:: 1.12.3 | ||
5 | The batch filter was added in Twig 1.12.3. | ||
6 | |||
7 | The ``batch`` filter "batches" items by returning a list of lists with the | ||
8 | given number of items. If you provide a second parameter, it is used to fill | ||
9 | missing items: | ||
10 | |||
11 | .. code-block:: jinja | ||
12 | |||
13 | {% set items = ['a', 'b', 'c', 'd', 'e', 'f', 'g'] %} | ||
14 | |||
15 | <table> | ||
16 | {% for row in items|batch(3, 'No item') %} | ||
17 | <tr> | ||
18 | {% for column in row %} | ||
19 | <td>{{ column }}</td> | ||
20 | {% endfor %} | ||
21 | </tr> | ||
22 | {% endfor %} | ||
23 | </table> | ||
24 | |||
25 | The above example will be rendered as: | ||
26 | |||
27 | .. code-block:: jinja | ||
28 | |||
29 | <table> | ||
30 | <tr> | ||
31 | <td>a</td> | ||
32 | <td>b</td> | ||
33 | <td>c</td> | ||
34 | </tr> | ||
35 | <tr> | ||
36 | <td>d</td> | ||
37 | <td>e</td> | ||
38 | <td>f</td> | ||
39 | </tr> | ||
40 | <tr> | ||
41 | <td>g</td> | ||
42 | <td>No item</td> | ||
43 | <td>No item</td> | ||
44 | </tr> | ||
45 | </table> | ||
diff --git a/vendor/twig/twig/doc/filters/capitalize.rst b/vendor/twig/twig/doc/filters/capitalize.rst deleted file mode 100644 index 10546a1f..00000000 --- a/vendor/twig/twig/doc/filters/capitalize.rst +++ /dev/null | |||
@@ -1,11 +0,0 @@ | |||
1 | ``capitalize`` | ||
2 | ============== | ||
3 | |||
4 | The ``capitalize`` filter capitalizes a value. The first character will be | ||
5 | uppercase, all others lowercase: | ||
6 | |||
7 | .. code-block:: jinja | ||
8 | |||
9 | {{ 'my first car'|capitalize }} | ||
10 | |||
11 | {# outputs 'My first car' #} | ||
diff --git a/vendor/twig/twig/doc/filters/convert_encoding.rst b/vendor/twig/twig/doc/filters/convert_encoding.rst deleted file mode 100644 index 1b0eb60c..00000000 --- a/vendor/twig/twig/doc/filters/convert_encoding.rst +++ /dev/null | |||
@@ -1,28 +0,0 @@ | |||
1 | ``convert_encoding`` | ||
2 | ==================== | ||
3 | |||
4 | .. versionadded:: 1.4 | ||
5 | The ``convert_encoding`` filter was added in Twig 1.4. | ||
6 | |||
7 | The ``convert_encoding`` filter converts a string from one encoding to | ||
8 | another. The first argument is the expected output charset and the second one | ||
9 | is the input charset: | ||
10 | |||
11 | .. code-block:: jinja | ||
12 | |||
13 | {{ data|convert_encoding('UTF-8', 'iso-2022-jp') }} | ||
14 | |||
15 | .. note:: | ||
16 | |||
17 | This filter relies on the `iconv`_ or `mbstring`_ extension, so one of | ||
18 | them must be installed. In case both are installed, `mbstring`_ is used by | ||
19 | default (Twig before 1.8.1 uses `iconv`_ by default). | ||
20 | |||
21 | Arguments | ||
22 | --------- | ||
23 | |||
24 | * ``from``: The input charset | ||
25 | * ``to``: The output charset | ||
26 | |||
27 | .. _`iconv`: http://php.net/iconv | ||
28 | .. _`mbstring`: http://php.net/mbstring | ||
diff --git a/vendor/twig/twig/doc/filters/date.rst b/vendor/twig/twig/doc/filters/date.rst deleted file mode 100644 index 8e2f31fa..00000000 --- a/vendor/twig/twig/doc/filters/date.rst +++ /dev/null | |||
@@ -1,88 +0,0 @@ | |||
1 | ``date`` | ||
2 | ======== | ||
3 | |||
4 | .. versionadded:: 1.1 | ||
5 | The timezone support has been added in Twig 1.1. | ||
6 | |||
7 | .. versionadded:: 1.5 | ||
8 | The default date format support has been added in Twig 1.5. | ||
9 | |||
10 | .. versionadded:: 1.6.1 | ||
11 | The default timezone support has been added in Twig 1.6.1. | ||
12 | |||
13 | .. versionadded:: 1.11.0 | ||
14 | The introduction of the false value for the timezone was introduced in Twig 1.11.0 | ||
15 | |||
16 | The ``date`` filter formats a date to a given format: | ||
17 | |||
18 | .. code-block:: jinja | ||
19 | |||
20 | {{ post.published_at|date("m/d/Y") }} | ||
21 | |||
22 | The ``date`` filter accepts strings (it must be in a format supported by the | ||
23 | `strtotime`_ function), `DateTime`_ instances, or `DateInterval`_ instances. For | ||
24 | instance, to display the current date, filter the word "now": | ||
25 | |||
26 | .. code-block:: jinja | ||
27 | |||
28 | {{ "now"|date("m/d/Y") }} | ||
29 | |||
30 | To escape words and characters in the date format use ``\\`` in front of each | ||
31 | character: | ||
32 | |||
33 | .. code-block:: jinja | ||
34 | |||
35 | {{ post.published_at|date("F jS \\a\\t g:ia") }} | ||
36 | |||
37 | If the value passed to the ``date`` filter is ``null``, it will return the | ||
38 | current date by default. If an empty string is desired instead of the current | ||
39 | date, use a ternary operator: | ||
40 | |||
41 | .. code-block:: jinja | ||
42 | |||
43 | {{ post.published_at is empty ? "" : post.published_at|date("m/d/Y") }} | ||
44 | |||
45 | If no format is provided, Twig will use the default one: ``F j, Y H:i``. This | ||
46 | default can be easily changed by calling the ``setDateFormat()`` method on the | ||
47 | ``core`` extension instance. The first argument is the default format for | ||
48 | dates and the second one is the default format for date intervals: | ||
49 | |||
50 | .. code-block:: php | ||
51 | |||
52 | $twig = new Twig_Environment($loader); | ||
53 | $twig->getExtension('core')->setDateFormat('d/m/Y', '%d days'); | ||
54 | |||
55 | Timezone | ||
56 | -------- | ||
57 | |||
58 | By default, the date is displayed by applying the default timezone (the one | ||
59 | specified in php.ini or declared in Twig -- see below), but you can override | ||
60 | it by explicitly specifying a timezone: | ||
61 | |||
62 | .. code-block:: jinja | ||
63 | |||
64 | {{ post.published_at|date("m/d/Y", "Europe/Paris") }} | ||
65 | |||
66 | If the date is already a DateTime object, and if you want to keep its current | ||
67 | timezone, pass ``false`` as the timezone value: | ||
68 | |||
69 | .. code-block:: jinja | ||
70 | |||
71 | {{ post.published_at|date("m/d/Y", false) }} | ||
72 | |||
73 | The default timezone can also be set globally by calling ``setTimezone()``: | ||
74 | |||
75 | .. code-block:: php | ||
76 | |||
77 | $twig = new Twig_Environment($loader); | ||
78 | $twig->getExtension('core')->setTimezone('Europe/Paris'); | ||
79 | |||
80 | Arguments | ||
81 | --------- | ||
82 | |||
83 | * ``format``: The date format | ||
84 | * ``timezone``: The date timezone | ||
85 | |||
86 | .. _`strtotime`: http://www.php.net/strtotime | ||
87 | .. _`DateTime`: http://www.php.net/DateTime | ||
88 | .. _`DateInterval`: http://www.php.net/DateInterval | ||
diff --git a/vendor/twig/twig/doc/filters/date_modify.rst b/vendor/twig/twig/doc/filters/date_modify.rst deleted file mode 100644 index 6a5c73d6..00000000 --- a/vendor/twig/twig/doc/filters/date_modify.rst +++ /dev/null | |||
@@ -1,23 +0,0 @@ | |||
1 | ``date_modify`` | ||
2 | =============== | ||
3 | |||
4 | .. versionadded:: 1.9.0 | ||
5 | The date_modify filter has been added in Twig 1.9.0. | ||
6 | |||
7 | The ``date_modify`` filter modifies a date with a given modifier string: | ||
8 | |||
9 | .. code-block:: jinja | ||
10 | |||
11 | {{ post.published_at|date_modify("+1 day")|date("m/d/Y") }} | ||
12 | |||
13 | The ``date_modify`` filter accepts strings (it must be in a format supported | ||
14 | by the `strtotime`_ function) or `DateTime`_ instances. You can easily combine | ||
15 | it with the :doc:`date<date>` filter for formatting. | ||
16 | |||
17 | Arguments | ||
18 | --------- | ||
19 | |||
20 | * ``modifier``: The modifier | ||
21 | |||
22 | .. _`strtotime`: http://www.php.net/strtotime | ||
23 | .. _`DateTime`: http://www.php.net/DateTime | ||
diff --git a/vendor/twig/twig/doc/filters/default.rst b/vendor/twig/twig/doc/filters/default.rst deleted file mode 100644 index 46ed9636..00000000 --- a/vendor/twig/twig/doc/filters/default.rst +++ /dev/null | |||
@@ -1,33 +0,0 @@ | |||
1 | ``default`` | ||
2 | =========== | ||
3 | |||
4 | The ``default`` filter returns the passed default value if the value is | ||
5 | undefined or empty, otherwise the value of the variable: | ||
6 | |||
7 | .. code-block:: jinja | ||
8 | |||
9 | {{ var|default('var is not defined') }} | ||
10 | |||
11 | {{ var.foo|default('foo item on var is not defined') }} | ||
12 | |||
13 | {{ var['foo']|default('foo item on var is not defined') }} | ||
14 | |||
15 | {{ ''|default('passed var is empty') }} | ||
16 | |||
17 | When using the ``default`` filter on an expression that uses variables in some | ||
18 | method calls, be sure to use the ``default`` filter whenever a variable can be | ||
19 | undefined: | ||
20 | |||
21 | .. code-block:: jinja | ||
22 | |||
23 | {{ var.method(foo|default('foo'))|default('foo') }} | ||
24 | |||
25 | .. note:: | ||
26 | |||
27 | Read the documentation for the :doc:`defined<../tests/defined>` and | ||
28 | :doc:`empty<../tests/empty>` tests to learn more about their semantics. | ||
29 | |||
30 | Arguments | ||
31 | --------- | ||
32 | |||
33 | * ``default``: The default value | ||
diff --git a/vendor/twig/twig/doc/filters/escape.rst b/vendor/twig/twig/doc/filters/escape.rst deleted file mode 100644 index 5ade7d74..00000000 --- a/vendor/twig/twig/doc/filters/escape.rst +++ /dev/null | |||
@@ -1,93 +0,0 @@ | |||
1 | ``escape`` | ||
2 | ========== | ||
3 | |||
4 | .. versionadded:: 1.9.0 | ||
5 | The ``css``, ``url``, and ``html_attr`` strategies were added in Twig | ||
6 | 1.9.0. | ||
7 | |||
8 | The ``escape`` filter escapes a string for safe insertion into the final | ||
9 | output. It supports different escaping strategies depending on the template | ||
10 | context. | ||
11 | |||
12 | By default, it uses the HTML escaping strategy: | ||
13 | |||
14 | .. code-block:: jinja | ||
15 | |||
16 | {{ user.username|escape }} | ||
17 | |||
18 | For convenience, the ``e`` filter is defined as an alias: | ||
19 | |||
20 | .. code-block:: jinja | ||
21 | |||
22 | {{ user.username|e }} | ||
23 | |||
24 | The ``escape`` filter can also be used in other contexts than HTML thanks to | ||
25 | an optional argument which defines the escaping strategy to use: | ||
26 | |||
27 | .. code-block:: jinja | ||
28 | |||
29 | {{ user.username|e }} | ||
30 | {# is equivalent to #} | ||
31 | {{ user.username|e('html') }} | ||
32 | |||
33 | And here is how to escape variables included in JavaScript code: | ||
34 | |||
35 | .. code-block:: jinja | ||
36 | |||
37 | {{ user.username|escape('js') }} | ||
38 | {{ user.username|e('js') }} | ||
39 | |||
40 | The ``escape`` filter supports the following escaping strategies: | ||
41 | |||
42 | * ``html``: escapes a string for the **HTML body** context. | ||
43 | |||
44 | * ``js``: escapes a string for the **JavaScript context**. | ||
45 | |||
46 | * ``css``: escapes a string for the **CSS context**. CSS escaping can be | ||
47 | applied to any string being inserted into CSS and escapes everything except | ||
48 | alphanumerics. | ||
49 | |||
50 | * ``url``: escapes a string for the **URI or parameter contexts**. This should | ||
51 | not be used to escape an entire URI; only a subcomponent being inserted. | ||
52 | |||
53 | * ``html_attr``: escapes a string for the **HTML attribute** context. | ||
54 | |||
55 | .. note:: | ||
56 | |||
57 | Internally, ``escape`` uses the PHP native `htmlspecialchars`_ function | ||
58 | for the HTML escaping strategy. | ||
59 | |||
60 | .. caution:: | ||
61 | |||
62 | When using automatic escaping, Twig tries to not double-escape a variable | ||
63 | when the automatic escaping strategy is the same as the one applied by the | ||
64 | escape filter; but that does not work when using a variable as the | ||
65 | escaping strategy: | ||
66 | |||
67 | .. code-block:: jinja | ||
68 | |||
69 | {% set strategy = 'html' %} | ||
70 | |||
71 | {% autoescape 'html' %} | ||
72 | {{ var|escape('html') }} {# won't be double-escaped #} | ||
73 | {{ var|escape(strategy) }} {# will be double-escaped #} | ||
74 | {% endautoescape %} | ||
75 | |||
76 | When using a variable as the escaping strategy, you should disable | ||
77 | automatic escaping: | ||
78 | |||
79 | .. code-block:: jinja | ||
80 | |||
81 | {% set strategy = 'html' %} | ||
82 | |||
83 | {% autoescape 'html' %} | ||
84 | {{ var|escape(strategy)|raw }} {# won't be double-escaped #} | ||
85 | {% endautoescape %} | ||
86 | |||
87 | Arguments | ||
88 | --------- | ||
89 | |||
90 | * ``strategy``: The escaping strategy | ||
91 | * ``charset``: The string charset | ||
92 | |||
93 | .. _`htmlspecialchars`: http://php.net/htmlspecialchars | ||
diff --git a/vendor/twig/twig/doc/filters/first.rst b/vendor/twig/twig/doc/filters/first.rst deleted file mode 100644 index 4295e833..00000000 --- a/vendor/twig/twig/doc/filters/first.rst +++ /dev/null | |||
@@ -1,25 +0,0 @@ | |||
1 | ``first`` | ||
2 | ========= | ||
3 | |||
4 | .. versionadded:: 1.12.2 | ||
5 | The first filter was added in Twig 1.12.2. | ||
6 | |||
7 | The ``first`` filter returns the first "element" of a sequence, a mapping, or | ||
8 | a string: | ||
9 | |||
10 | .. code-block:: jinja | ||
11 | |||
12 | {{ [1, 2, 3, 4]|first }} | ||
13 | {# outputs 1 #} | ||
14 | |||
15 | {{ { a: 1, b: 2, c: 3, d: 4 }|first }} | ||
16 | {# outputs 1 #} | ||
17 | |||
18 | {{ '1234'|first }} | ||
19 | {# outputs 1 #} | ||
20 | |||
21 | .. note:: | ||
22 | |||
23 | It also works with objects implementing the `Traversable`_ interface. | ||
24 | |||
25 | .. _`Traversable`: http://php.net/manual/en/class.traversable.php | ||
diff --git a/vendor/twig/twig/doc/filters/format.rst b/vendor/twig/twig/doc/filters/format.rst deleted file mode 100644 index fe55a09e..00000000 --- a/vendor/twig/twig/doc/filters/format.rst +++ /dev/null | |||
@@ -1,16 +0,0 @@ | |||
1 | ``format`` | ||
2 | ========== | ||
3 | |||
4 | The ``format`` filter formats a given string by replacing the placeholders | ||
5 | (placeholders follows the `sprintf`_ notation): | ||
6 | |||
7 | .. code-block:: jinja | ||
8 | |||
9 | {{ "I like %s and %s."|format(foo, "bar") }} | ||
10 | |||
11 | {# returns I like foo and bar | ||
12 | if the foo parameter equals to the foo string. #} | ||
13 | |||
14 | .. _`sprintf`: http://www.php.net/sprintf | ||
15 | |||
16 | .. seealso:: :doc:`replace<replace>` | ||
diff --git a/vendor/twig/twig/doc/filters/index.rst b/vendor/twig/twig/doc/filters/index.rst deleted file mode 100644 index b0c6b38d..00000000 --- a/vendor/twig/twig/doc/filters/index.rst +++ /dev/null | |||
@@ -1,36 +0,0 @@ | |||
1 | Filters | ||
2 | ======= | ||
3 | |||
4 | .. toctree:: | ||
5 | :maxdepth: 1 | ||
6 | |||
7 | abs | ||
8 | batch | ||
9 | capitalize | ||
10 | convert_encoding | ||
11 | date | ||
12 | date_modify | ||
13 | default | ||
14 | escape | ||
15 | first | ||
16 | format | ||
17 | join | ||
18 | json_encode | ||
19 | keys | ||
20 | last | ||
21 | length | ||
22 | lower | ||
23 | nl2br | ||
24 | number_format | ||
25 | merge | ||
26 | upper | ||
27 | raw | ||
28 | replace | ||
29 | reverse | ||
30 | slice | ||
31 | sort | ||
32 | split | ||
33 | striptags | ||
34 | title | ||
35 | trim | ||
36 | url_encode | ||
diff --git a/vendor/twig/twig/doc/filters/join.rst b/vendor/twig/twig/doc/filters/join.rst deleted file mode 100644 index f4952421..00000000 --- a/vendor/twig/twig/doc/filters/join.rst +++ /dev/null | |||
@@ -1,23 +0,0 @@ | |||
1 | ``join`` | ||
2 | ======== | ||
3 | |||
4 | The ``join`` filter returns a string which is the concatenation of the items | ||
5 | of a sequence: | ||
6 | |||
7 | .. code-block:: jinja | ||
8 | |||
9 | {{ [1, 2, 3]|join }} | ||
10 | {# returns 123 #} | ||
11 | |||
12 | The separator between elements is an empty string per default, but you can | ||
13 | define it with the optional first parameter: | ||
14 | |||
15 | .. code-block:: jinja | ||
16 | |||
17 | {{ [1, 2, 3]|join('|') }} | ||
18 | {# returns 1|2|3 #} | ||
19 | |||
20 | Arguments | ||
21 | --------- | ||
22 | |||
23 | * ``glue``: The separator | ||
diff --git a/vendor/twig/twig/doc/filters/json_encode.rst b/vendor/twig/twig/doc/filters/json_encode.rst deleted file mode 100644 index a33fef1b..00000000 --- a/vendor/twig/twig/doc/filters/json_encode.rst +++ /dev/null | |||
@@ -1,21 +0,0 @@ | |||
1 | ``json_encode`` | ||
2 | =============== | ||
3 | |||
4 | The ``json_encode`` filter returns the JSON representation of a string: | ||
5 | |||
6 | .. code-block:: jinja | ||
7 | |||
8 | {{ data|json_encode() }} | ||
9 | |||
10 | .. note:: | ||
11 | |||
12 | Internally, Twig uses the PHP `json_encode`_ function. | ||
13 | |||
14 | Arguments | ||
15 | --------- | ||
16 | |||
17 | * ``options``: A bitmask of `json_encode options`_ (``{{ | ||
18 | data|json_encode(constant(JSON_PRETTY_PRINT)) }}``) | ||
19 | |||
20 | .. _`json_encode`: http://php.net/json_encode | ||
21 | .. _`json_encode options`: http://www.php.net/manual/en/json.constants.php | ||
diff --git a/vendor/twig/twig/doc/filters/keys.rst b/vendor/twig/twig/doc/filters/keys.rst deleted file mode 100644 index e4f090c6..00000000 --- a/vendor/twig/twig/doc/filters/keys.rst +++ /dev/null | |||
@@ -1,11 +0,0 @@ | |||
1 | ``keys`` | ||
2 | ======== | ||
3 | |||
4 | The ``keys`` filter returns the keys of an array. It is useful when you want to | ||
5 | iterate over the keys of an array: | ||
6 | |||
7 | .. code-block:: jinja | ||
8 | |||
9 | {% for key in array|keys %} | ||
10 | ... | ||
11 | {% endfor %} | ||
diff --git a/vendor/twig/twig/doc/filters/last.rst b/vendor/twig/twig/doc/filters/last.rst deleted file mode 100644 index 723c0b57..00000000 --- a/vendor/twig/twig/doc/filters/last.rst +++ /dev/null | |||
@@ -1,25 +0,0 @@ | |||
1 | ``last`` | ||
2 | ======== | ||
3 | |||
4 | .. versionadded:: 1.12.2 | ||
5 | The last filter was added in Twig 1.12.2. | ||
6 | |||
7 | The ``last`` filter returns the last "element" of a sequence, a mapping, or | ||
8 | a string: | ||
9 | |||
10 | .. code-block:: jinja | ||
11 | |||
12 | {{ [1, 2, 3, 4]|last }} | ||
13 | {# outputs 4 #} | ||
14 | |||
15 | {{ { a: 1, b: 2, c: 3, d: 4 }|last }} | ||
16 | {# outputs 4 #} | ||
17 | |||
18 | {{ '1234'|last }} | ||
19 | {# outputs 4 #} | ||
20 | |||
21 | .. note:: | ||
22 | |||
23 | It also works with objects implementing the `Traversable`_ interface. | ||
24 | |||
25 | .. _`Traversable`: http://php.net/manual/en/class.traversable.php | ||
diff --git a/vendor/twig/twig/doc/filters/length.rst b/vendor/twig/twig/doc/filters/length.rst deleted file mode 100644 index f79b9bdf..00000000 --- a/vendor/twig/twig/doc/filters/length.rst +++ /dev/null | |||
@@ -1,12 +0,0 @@ | |||
1 | ``length`` | ||
2 | ========== | ||
3 | |||
4 | The ``length`` filters returns the number of items of a sequence or mapping, or | ||
5 | the length of a string: | ||
6 | |||
7 | .. code-block:: jinja | ||
8 | |||
9 | {% if users|length > 10 %} | ||
10 | ... | ||
11 | {% endif %} | ||
12 | |||
diff --git a/vendor/twig/twig/doc/filters/lower.rst b/vendor/twig/twig/doc/filters/lower.rst deleted file mode 100644 index ef9faa90..00000000 --- a/vendor/twig/twig/doc/filters/lower.rst +++ /dev/null | |||
@@ -1,10 +0,0 @@ | |||
1 | ``lower`` | ||
2 | ========= | ||
3 | |||
4 | The ``lower`` filter converts a value to lowercase: | ||
5 | |||
6 | .. code-block:: jinja | ||
7 | |||
8 | {{ 'WELCOME'|lower }} | ||
9 | |||
10 | {# outputs 'welcome' #} | ||
diff --git a/vendor/twig/twig/doc/filters/merge.rst b/vendor/twig/twig/doc/filters/merge.rst deleted file mode 100644 index 05a2ae7d..00000000 --- a/vendor/twig/twig/doc/filters/merge.rst +++ /dev/null | |||
@@ -1,41 +0,0 @@ | |||
1 | ``merge`` | ||
2 | ========= | ||
3 | |||
4 | The ``merge`` filter merges an array with another array: | ||
5 | |||
6 | .. code-block:: jinja | ||
7 | |||
8 | {% set values = [1, 2] %} | ||
9 | |||
10 | {% set values = values|merge(['apple', 'orange']) %} | ||
11 | |||
12 | {# values now contains [1, 2, 'apple', 'orange'] #} | ||
13 | |||
14 | New values are added at the end of the existing ones. | ||
15 | |||
16 | The ``merge`` filter also works on hashes: | ||
17 | |||
18 | .. code-block:: jinja | ||
19 | |||
20 | {% set items = { 'apple': 'fruit', 'orange': 'fruit', 'peugeot': 'unknown' } %} | ||
21 | |||
22 | {% set items = items|merge({ 'peugeot': 'car', 'renault': 'car' }) %} | ||
23 | |||
24 | {# items now contains { 'apple': 'fruit', 'orange': 'fruit', 'peugeot': 'car', 'renault': 'car' } #} | ||
25 | |||
26 | For hashes, the merging process occurs on the keys: if the key does not | ||
27 | already exist, it is added but if the key already exists, its value is | ||
28 | overridden. | ||
29 | |||
30 | .. tip:: | ||
31 | |||
32 | If you want to ensure that some values are defined in an array (by given | ||
33 | default values), reverse the two elements in the call: | ||
34 | |||
35 | .. code-block:: jinja | ||
36 | |||
37 | {% set items = { 'apple': 'fruit', 'orange': 'fruit' } %} | ||
38 | |||
39 | {% set items = { 'apple': 'unknown' }|merge(items) %} | ||
40 | |||
41 | {# items now contains { 'apple': 'fruit', 'orange': 'fruit' } #} | ||
diff --git a/vendor/twig/twig/doc/filters/nl2br.rst b/vendor/twig/twig/doc/filters/nl2br.rst deleted file mode 100644 index 694c6724..00000000 --- a/vendor/twig/twig/doc/filters/nl2br.rst +++ /dev/null | |||
@@ -1,22 +0,0 @@ | |||
1 | ``nl2br`` | ||
2 | ========= | ||
3 | |||
4 | .. versionadded:: 1.5 | ||
5 | The nl2br filter was added in Twig 1.5. | ||
6 | |||
7 | The ``nl2br`` filter inserts HTML line breaks before all newlines in a string: | ||
8 | |||
9 | .. code-block:: jinja | ||
10 | |||
11 | {{ "I like Twig.\nYou will like it too."|nl2br }} | ||
12 | {# outputs | ||
13 | |||
14 | I like Twig.<br /> | ||
15 | You will like it too. | ||
16 | |||
17 | #} | ||
18 | |||
19 | .. note:: | ||
20 | |||
21 | The ``nl2br`` filter pre-escapes the input before applying the | ||
22 | transformation. | ||
diff --git a/vendor/twig/twig/doc/filters/number_format.rst b/vendor/twig/twig/doc/filters/number_format.rst deleted file mode 100644 index fedacd9d..00000000 --- a/vendor/twig/twig/doc/filters/number_format.rst +++ /dev/null | |||
@@ -1,45 +0,0 @@ | |||
1 | ``number_format`` | ||
2 | ================= | ||
3 | |||
4 | .. versionadded:: 1.5 | ||
5 | The number_format filter was added in Twig 1.5 | ||
6 | |||
7 | The ``number_format`` filter formats numbers. It is a wrapper around PHP's | ||
8 | `number_format`_ function: | ||
9 | |||
10 | .. code-block:: jinja | ||
11 | |||
12 | {{ 200.35|number_format }} | ||
13 | |||
14 | You can control the number of decimal places, decimal point, and thousands | ||
15 | separator using the additional arguments: | ||
16 | |||
17 | .. code-block:: jinja | ||
18 | |||
19 | {{ 9800.333|number_format(2, '.', ',') }} | ||
20 | |||
21 | If no formatting options are provided then Twig will use the default formatting | ||
22 | options of: | ||
23 | |||
24 | - 0 decimal places. | ||
25 | - ``.`` as the decimal point. | ||
26 | - ``,`` as the thousands separator. | ||
27 | |||
28 | These defaults can be easily changed through the core extension: | ||
29 | |||
30 | .. code-block:: php | ||
31 | |||
32 | $twig = new Twig_Environment($loader); | ||
33 | $twig->getExtension('core')->setNumberFormat(3, '.', ','); | ||
34 | |||
35 | The defaults set for ``number_format`` can be over-ridden upon each call using the | ||
36 | additional parameters. | ||
37 | |||
38 | Arguments | ||
39 | --------- | ||
40 | |||
41 | * ``decimal``: The number of decimal points to display | ||
42 | * ``decimal_point``: The character(s) to use for the decimal point | ||
43 | * ``decimal_sep``: The character(s) to use for the thousands separator | ||
44 | |||
45 | .. _`number_format`: http://php.net/number_format | ||
diff --git a/vendor/twig/twig/doc/filters/raw.rst b/vendor/twig/twig/doc/filters/raw.rst deleted file mode 100644 index 434dd246..00000000 --- a/vendor/twig/twig/doc/filters/raw.rst +++ /dev/null | |||
@@ -1,12 +0,0 @@ | |||
1 | ``raw`` | ||
2 | ======= | ||
3 | |||
4 | The ``raw`` filter marks the value as being "safe", which means that in an | ||
5 | environment with automatic escaping enabled this variable will not be escaped | ||
6 | if ``raw`` is the last filter applied to it: | ||
7 | |||
8 | .. code-block:: jinja | ||
9 | |||
10 | {% autoescape true %} | ||
11 | {{ var|raw }} {# var won't be escaped #} | ||
12 | {% endautoescape %} | ||
diff --git a/vendor/twig/twig/doc/filters/replace.rst b/vendor/twig/twig/doc/filters/replace.rst deleted file mode 100644 index e961f23d..00000000 --- a/vendor/twig/twig/doc/filters/replace.rst +++ /dev/null | |||
@@ -1,19 +0,0 @@ | |||
1 | ``replace`` | ||
2 | =========== | ||
3 | |||
4 | The ``replace`` filter formats a given string by replacing the placeholders | ||
5 | (placeholders are free-form): | ||
6 | |||
7 | .. code-block:: jinja | ||
8 | |||
9 | {{ "I like %this% and %that%."|replace({'%this%': foo, '%that%': "bar"}) }} | ||
10 | |||
11 | {# returns I like foo and bar | ||
12 | if the foo parameter equals to the foo string. #} | ||
13 | |||
14 | Arguments | ||
15 | --------- | ||
16 | |||
17 | * ``replace_pairs``: The placeholder values | ||
18 | |||
19 | .. seealso:: :doc:`format<format>` | ||
diff --git a/vendor/twig/twig/doc/filters/reverse.rst b/vendor/twig/twig/doc/filters/reverse.rst deleted file mode 100644 index 752192b8..00000000 --- a/vendor/twig/twig/doc/filters/reverse.rst +++ /dev/null | |||
@@ -1,47 +0,0 @@ | |||
1 | ``reverse`` | ||
2 | =========== | ||
3 | |||
4 | .. versionadded:: 1.6 | ||
5 | Support for strings has been added in Twig 1.6. | ||
6 | |||
7 | The ``reverse`` filter reverses a sequence, a mapping, or a string: | ||
8 | |||
9 | .. code-block:: jinja | ||
10 | |||
11 | {% for user in users|reverse %} | ||
12 | ... | ||
13 | {% endfor %} | ||
14 | |||
15 | {{ '1234'|reverse }} | ||
16 | |||
17 | {# outputs 4321 #} | ||
18 | |||
19 | .. tip:: | ||
20 | |||
21 | For sequences and mappings, numeric keys are not preserved. To reverse | ||
22 | them as well, pass ``true`` as an argument to the ``reverse`` filter: | ||
23 | |||
24 | .. code-block:: jinja | ||
25 | |||
26 | {% for key, value in {1: "a", 2: "b", 3: "c"}|reverse %} | ||
27 | {{ key }}: {{ value }} | ||
28 | {%- endfor %} | ||
29 | |||
30 | {# output: 0: c 1: b 2: a #} | ||
31 | |||
32 | {% for key, value in {1: "a", 2: "b", 3: "c"}|reverse(true) %} | ||
33 | {{ key }}: {{ value }} | ||
34 | {%- endfor %} | ||
35 | |||
36 | {# output: 3: c 2: b 1: a #} | ||
37 | |||
38 | .. note:: | ||
39 | |||
40 | It also works with objects implementing the `Traversable`_ interface. | ||
41 | |||
42 | Arguments | ||
43 | --------- | ||
44 | |||
45 | * ``preserve_keys``: Preserve keys when reversing a mapping or a sequence. | ||
46 | |||
47 | .. _`Traversable`: http://php.net/Traversable | ||
diff --git a/vendor/twig/twig/doc/filters/slice.rst b/vendor/twig/twig/doc/filters/slice.rst deleted file mode 100644 index dbd5db37..00000000 --- a/vendor/twig/twig/doc/filters/slice.rst +++ /dev/null | |||
@@ -1,70 +0,0 @@ | |||
1 | ``slice`` | ||
2 | =========== | ||
3 | |||
4 | .. versionadded:: 1.6 | ||
5 | The slice filter was added in Twig 1.6. | ||
6 | |||
7 | The ``slice`` filter extracts a slice of a sequence, a mapping, or a string: | ||
8 | |||
9 | .. code-block:: jinja | ||
10 | |||
11 | {% for i in [1, 2, 3, 4, 5]|slice(1, 2) %} | ||
12 | {# will iterate over 2 and 3 #} | ||
13 | {% endfor %} | ||
14 | |||
15 | {{ '12345'|slice(1, 2) }} | ||
16 | |||
17 | {# outputs 23 #} | ||
18 | |||
19 | You can use any valid expression for both the start and the length: | ||
20 | |||
21 | .. code-block:: jinja | ||
22 | |||
23 | {% for i in [1, 2, 3, 4, 5]|slice(start, length) %} | ||
24 | {# ... #} | ||
25 | {% endfor %} | ||
26 | |||
27 | As syntactic sugar, you can also use the ``[]`` notation: | ||
28 | |||
29 | .. code-block:: jinja | ||
30 | |||
31 | {% for i in [1, 2, 3, 4, 5][start:length] %} | ||
32 | {# ... #} | ||
33 | {% endfor %} | ||
34 | |||
35 | {{ '12345'[1:2] }} | ||
36 | |||
37 | {# you can omit the first argument -- which is the same as 0 #} | ||
38 | {{ '12345'[:2] }} {# will display "12" #} | ||
39 | |||
40 | {# you can omit the last argument -- which will select everything till the end #} | ||
41 | {{ '12345'[2:] }} {# will display "345" #} | ||
42 | |||
43 | The ``slice`` filter works as the `array_slice`_ PHP function for arrays and | ||
44 | `substr`_ for strings. | ||
45 | |||
46 | If the start is non-negative, the sequence will start at that start in the | ||
47 | variable. If start is negative, the sequence will start that far from the end | ||
48 | of the variable. | ||
49 | |||
50 | If length is given and is positive, then the sequence will have up to that | ||
51 | many elements in it. If the variable is shorter than the length, then only the | ||
52 | available variable elements will be present. If length is given and is | ||
53 | negative then the sequence will stop that many elements from the end of the | ||
54 | variable. If it is omitted, then the sequence will have everything from offset | ||
55 | up until the end of the variable. | ||
56 | |||
57 | .. note:: | ||
58 | |||
59 | It also works with objects implementing the `Traversable`_ interface. | ||
60 | |||
61 | Arguments | ||
62 | --------- | ||
63 | |||
64 | * ``start``: The start of the slice | ||
65 | * ``length``: The size of the slice | ||
66 | * ``preserve_keys``: Whether to preserve key or not (when the input is an array) | ||
67 | |||
68 | .. _`Traversable`: http://php.net/manual/en/class.traversable.php | ||
69 | .. _`array_slice`: http://php.net/array_slice | ||
70 | .. _`substr`: http://php.net/substr | ||
diff --git a/vendor/twig/twig/doc/filters/sort.rst b/vendor/twig/twig/doc/filters/sort.rst deleted file mode 100644 index 33311528..00000000 --- a/vendor/twig/twig/doc/filters/sort.rst +++ /dev/null | |||
@@ -1,17 +0,0 @@ | |||
1 | ``sort`` | ||
2 | ======== | ||
3 | |||
4 | The ``sort`` filter sorts an array: | ||
5 | |||
6 | .. code-block:: jinja | ||
7 | |||
8 | {% for user in users|sort %} | ||
9 | ... | ||
10 | {% endfor %} | ||
11 | |||
12 | .. note:: | ||
13 | |||
14 | Internally, Twig uses the PHP `asort`_ function to maintain index | ||
15 | association. | ||
16 | |||
17 | .. _`asort`: http://php.net/asort | ||
diff --git a/vendor/twig/twig/doc/filters/split.rst b/vendor/twig/twig/doc/filters/split.rst deleted file mode 100644 index 7cd2ca5b..00000000 --- a/vendor/twig/twig/doc/filters/split.rst +++ /dev/null | |||
@@ -1,53 +0,0 @@ | |||
1 | ``split`` | ||
2 | ========= | ||
3 | |||
4 | .. versionadded:: 1.10.3 | ||
5 | The split filter was added in Twig 1.10.3. | ||
6 | |||
7 | The ``split`` filter splits a string by the given delimiter and returns a list | ||
8 | of strings: | ||
9 | |||
10 | .. code-block:: jinja | ||
11 | |||
12 | {{ "one,two,three"|split(',') }} | ||
13 | {# returns ['one', 'two', 'three'] #} | ||
14 | |||
15 | You can also pass a ``limit`` argument: | ||
16 | |||
17 | * If ``limit`` is positive, the returned array will contain a maximum of | ||
18 | limit elements with the last element containing the rest of string; | ||
19 | |||
20 | * If ``limit`` is negative, all components except the last -limit are | ||
21 | returned; | ||
22 | |||
23 | * If ``limit`` is zero, then this is treated as 1. | ||
24 | |||
25 | .. code-block:: jinja | ||
26 | |||
27 | {{ "one,two,three,four,five"|split(',', 3) }} | ||
28 | {# returns ['one', 'two', 'three,four,five'] #} | ||
29 | |||
30 | If the ``delimiter`` is an empty string, then value will be split by equal | ||
31 | chunks. Length is set by the ``limit`` argument (one character by default). | ||
32 | |||
33 | .. code-block:: jinja | ||
34 | |||
35 | {{ "123"|split('') }} | ||
36 | {# returns ['1', '2', '3'] #} | ||
37 | |||
38 | {{ "aabbcc"|split('', 2) }} | ||
39 | {# returns ['aa', 'bb', 'cc'] #} | ||
40 | |||
41 | .. note:: | ||
42 | |||
43 | Internally, Twig uses the PHP `explode`_ or `str_split`_ (if delimiter is | ||
44 | empty) functions for string splitting. | ||
45 | |||
46 | Arguments | ||
47 | --------- | ||
48 | |||
49 | * ``delimiter``: The delimiter | ||
50 | * ``limit``: The limit argument | ||
51 | |||
52 | .. _`explode`: http://php.net/explode | ||
53 | .. _`str_split`: http://php.net/str_split | ||
diff --git a/vendor/twig/twig/doc/filters/striptags.rst b/vendor/twig/twig/doc/filters/striptags.rst deleted file mode 100644 index 72c6f252..00000000 --- a/vendor/twig/twig/doc/filters/striptags.rst +++ /dev/null | |||
@@ -1,15 +0,0 @@ | |||
1 | ``striptags`` | ||
2 | ============= | ||
3 | |||
4 | The ``striptags`` filter strips SGML/XML tags and replace adjacent whitespace | ||
5 | by one space: | ||
6 | |||
7 | .. code-block:: jinja | ||
8 | |||
9 | {{ some_html|striptags }} | ||
10 | |||
11 | .. note:: | ||
12 | |||
13 | Internally, Twig uses the PHP `strip_tags`_ function. | ||
14 | |||
15 | .. _`strip_tags`: http://php.net/strip_tags | ||
diff --git a/vendor/twig/twig/doc/filters/title.rst b/vendor/twig/twig/doc/filters/title.rst deleted file mode 100644 index c5a318e8..00000000 --- a/vendor/twig/twig/doc/filters/title.rst +++ /dev/null | |||
@@ -1,11 +0,0 @@ | |||
1 | ``title`` | ||
2 | ========= | ||
3 | |||
4 | The ``title`` filter returns a titlecased version of the value. Words will | ||
5 | start with uppercase letters, all remaining characters are lowercase: | ||
6 | |||
7 | .. code-block:: jinja | ||
8 | |||
9 | {{ 'my first car'|title }} | ||
10 | |||
11 | {# outputs 'My First Car' #} | ||
diff --git a/vendor/twig/twig/doc/filters/trim.rst b/vendor/twig/twig/doc/filters/trim.rst deleted file mode 100644 index f38afd55..00000000 --- a/vendor/twig/twig/doc/filters/trim.rst +++ /dev/null | |||
@@ -1,29 +0,0 @@ | |||
1 | ``trim`` | ||
2 | ======== | ||
3 | |||
4 | .. versionadded:: 1.6.2 | ||
5 | The trim filter was added in Twig 1.6.2. | ||
6 | |||
7 | The ``trim`` filter strips whitespace (or other characters) from the beginning | ||
8 | and end of a string: | ||
9 | |||
10 | .. code-block:: jinja | ||
11 | |||
12 | {{ ' I like Twig. '|trim }} | ||
13 | |||
14 | {# outputs 'I like Twig.' #} | ||
15 | |||
16 | {{ ' I like Twig.'|trim('.') }} | ||
17 | |||
18 | {# outputs ' I like Twig' #} | ||
19 | |||
20 | .. note:: | ||
21 | |||
22 | Internally, Twig uses the PHP `trim`_ function. | ||
23 | |||
24 | Arguments | ||
25 | --------- | ||
26 | |||
27 | * ``character_mask``: The characters to strip | ||
28 | |||
29 | .. _`trim`: http://php.net/trim | ||
diff --git a/vendor/twig/twig/doc/filters/upper.rst b/vendor/twig/twig/doc/filters/upper.rst deleted file mode 100644 index 561cebe3..00000000 --- a/vendor/twig/twig/doc/filters/upper.rst +++ /dev/null | |||
@@ -1,10 +0,0 @@ | |||
1 | ``upper`` | ||
2 | ========= | ||
3 | |||
4 | The ``upper`` filter converts a value to uppercase: | ||
5 | |||
6 | .. code-block:: jinja | ||
7 | |||
8 | {{ 'welcome'|upper }} | ||
9 | |||
10 | {# outputs 'WELCOME' #} | ||
diff --git a/vendor/twig/twig/doc/filters/url_encode.rst b/vendor/twig/twig/doc/filters/url_encode.rst deleted file mode 100644 index b4f9a6ca..00000000 --- a/vendor/twig/twig/doc/filters/url_encode.rst +++ /dev/null | |||
@@ -1,28 +0,0 @@ | |||
1 | ``url_encode`` | ||
2 | ============== | ||
3 | |||
4 | .. versionadded:: 1.12.3 | ||
5 | Support for encoding an array as query string was added in Twig 1.12.3. | ||
6 | |||
7 | The ``url_encode`` filter percent encodes a given string as URL segment | ||
8 | or an array as query string: | ||
9 | |||
10 | .. code-block:: jinja | ||
11 | |||
12 | {{ "path-seg*ment"|url_encode }} | ||
13 | {# outputs "path-seg%2Ament" #} | ||
14 | |||
15 | {{ "string with spaces"|url_encode(true) }} | ||
16 | {# outputs "string%20with%20spaces" #} | ||
17 | |||
18 | {{ {'param': 'value', 'foo': 'bar'}|url_encode }} | ||
19 | {# outputs "param=value&foo=bar" #} | ||
20 | |||
21 | .. note:: | ||
22 | |||
23 | Internally, Twig uses the PHP `urlencode`_ (or `rawurlencode`_ if you pass | ||
24 | ``true`` as the first parameter) or the `http_build_query`_ function. | ||
25 | |||
26 | .. _`urlencode`: http://php.net/urlencode | ||
27 | .. _`rawurlencode`: http://php.net/rawurlencode | ||
28 | .. _`http_build_query`: http://php.net/http_build_query | ||
diff --git a/vendor/twig/twig/doc/functions/attribute.rst b/vendor/twig/twig/doc/functions/attribute.rst deleted file mode 100644 index 3051bdaa..00000000 --- a/vendor/twig/twig/doc/functions/attribute.rst +++ /dev/null | |||
@@ -1,18 +0,0 @@ | |||
1 | ``attribute`` | ||
2 | ============= | ||
3 | |||
4 | .. versionadded:: 1.2 | ||
5 | The ``attribute`` function was added in Twig 1.2. | ||
6 | |||
7 | ``attribute`` can be used to access a "dynamic" attribute of a variable: | ||
8 | |||
9 | .. code-block:: jinja | ||
10 | |||
11 | {{ attribute(object, method) }} | ||
12 | {{ attribute(object, method, arguments) }} | ||
13 | {{ attribute(array, item) }} | ||
14 | |||
15 | .. note:: | ||
16 | |||
17 | The resolution algorithm is the same as the one used for the ``.`` | ||
18 | notation, except that the item can be any valid expression. | ||
diff --git a/vendor/twig/twig/doc/functions/block.rst b/vendor/twig/twig/doc/functions/block.rst deleted file mode 100644 index fd571efb..00000000 --- a/vendor/twig/twig/doc/functions/block.rst +++ /dev/null | |||
@@ -1,15 +0,0 @@ | |||
1 | ``block`` | ||
2 | ========= | ||
3 | |||
4 | When a template uses inheritance and if you want to print a block multiple | ||
5 | times, use the ``block`` function: | ||
6 | |||
7 | .. code-block:: jinja | ||
8 | |||
9 | <title>{% block title %}{% endblock %}</title> | ||
10 | |||
11 | <h1>{{ block('title') }}</h1> | ||
12 | |||
13 | {% block body %}{% endblock %} | ||
14 | |||
15 | .. seealso:: :doc:`extends<../tags/extends>`, :doc:`parent<../functions/parent>` | ||
diff --git a/vendor/twig/twig/doc/functions/constant.rst b/vendor/twig/twig/doc/functions/constant.rst deleted file mode 100644 index bea0e9fc..00000000 --- a/vendor/twig/twig/doc/functions/constant.rst +++ /dev/null | |||
@@ -1,18 +0,0 @@ | |||
1 | ``constant`` | ||
2 | ============ | ||
3 | |||
4 | .. versionadded: 1.12.1 | ||
5 | constant now accepts object instances as the second argument. | ||
6 | |||
7 | ``constant`` returns the constant value for a given string: | ||
8 | |||
9 | .. code-block:: jinja | ||
10 | |||
11 | {{ some_date|date(constant('DATE_W3C')) }} | ||
12 | {{ constant('Namespace\\Classname::CONSTANT_NAME') }} | ||
13 | |||
14 | As of 1.12.1 you can read constants from object instances as well: | ||
15 | |||
16 | .. code-block:: jinja | ||
17 | |||
18 | {{ constant('RSS', date) }} | ||
diff --git a/vendor/twig/twig/doc/functions/cycle.rst b/vendor/twig/twig/doc/functions/cycle.rst deleted file mode 100644 index 0015cae1..00000000 --- a/vendor/twig/twig/doc/functions/cycle.rst +++ /dev/null | |||
@@ -1,25 +0,0 @@ | |||
1 | ``cycle`` | ||
2 | ========= | ||
3 | |||
4 | The ``cycle`` function cycles on an array of values: | ||
5 | |||
6 | .. code-block:: jinja | ||
7 | |||
8 | {% for i in 0..10 %} | ||
9 | {{ cycle(['odd', 'even'], i) }} | ||
10 | {% endfor %} | ||
11 | |||
12 | The array can contain any number of values: | ||
13 | |||
14 | .. code-block:: jinja | ||
15 | |||
16 | {% set fruits = ['apple', 'orange', 'citrus'] %} | ||
17 | |||
18 | {% for i in 0..10 %} | ||
19 | {{ cycle(fruits, i) }} | ||
20 | {% endfor %} | ||
21 | |||
22 | Arguments | ||
23 | --------- | ||
24 | |||
25 | * ``position``: The cycle position | ||
diff --git a/vendor/twig/twig/doc/functions/date.rst b/vendor/twig/twig/doc/functions/date.rst deleted file mode 100644 index f1c94819..00000000 --- a/vendor/twig/twig/doc/functions/date.rst +++ /dev/null | |||
@@ -1,52 +0,0 @@ | |||
1 | ``date`` | ||
2 | ======== | ||
3 | |||
4 | .. versionadded:: 1.6 | ||
5 | The date function has been added in Twig 1.6. | ||
6 | |||
7 | .. versionadded:: 1.6.1 | ||
8 | The default timezone support has been added in Twig 1.6.1. | ||
9 | |||
10 | Converts an argument to a date to allow date comparison: | ||
11 | |||
12 | .. code-block:: jinja | ||
13 | |||
14 | {% if date(user.created_at) < date('-2days') %} | ||
15 | {# do something #} | ||
16 | {% endif %} | ||
17 | |||
18 | The argument must be in a format supported by the `date`_ function. | ||
19 | |||
20 | You can pass a timezone as the second argument: | ||
21 | |||
22 | .. code-block:: jinja | ||
23 | |||
24 | {% if date(user.created_at) < date('-2days', 'Europe/Paris') %} | ||
25 | {# do something #} | ||
26 | {% endif %} | ||
27 | |||
28 | If no argument is passed, the function returns the current date: | ||
29 | |||
30 | .. code-block:: jinja | ||
31 | |||
32 | {% if date(user.created_at) < date() %} | ||
33 | {# always! #} | ||
34 | {% endif %} | ||
35 | |||
36 | .. note:: | ||
37 | |||
38 | You can set the default timezone globally by calling ``setTimezone()`` on | ||
39 | the ``core`` extension instance: | ||
40 | |||
41 | .. code-block:: php | ||
42 | |||
43 | $twig = new Twig_Environment($loader); | ||
44 | $twig->getExtension('core')->setTimezone('Europe/Paris'); | ||
45 | |||
46 | Arguments | ||
47 | --------- | ||
48 | |||
49 | * ``date``: The date | ||
50 | * ``timezone``: The timezone | ||
51 | |||
52 | .. _`date`: http://www.php.net/date | ||
diff --git a/vendor/twig/twig/doc/functions/dump.rst b/vendor/twig/twig/doc/functions/dump.rst deleted file mode 100644 index 1500b0f4..00000000 --- a/vendor/twig/twig/doc/functions/dump.rst +++ /dev/null | |||
@@ -1,69 +0,0 @@ | |||
1 | ``dump`` | ||
2 | ======== | ||
3 | |||
4 | .. versionadded:: 1.5 | ||
5 | The dump function was added in Twig 1.5. | ||
6 | |||
7 | The ``dump`` function dumps information about a template variable. This is | ||
8 | mostly useful to debug a template that does not behave as expected by | ||
9 | introspecting its variables: | ||
10 | |||
11 | .. code-block:: jinja | ||
12 | |||
13 | {{ dump(user) }} | ||
14 | |||
15 | .. note:: | ||
16 | |||
17 | The ``dump`` function is not available by default. You must add the | ||
18 | ``Twig_Extension_Debug`` extension explicitly when creating your Twig | ||
19 | environment:: | ||
20 | |||
21 | $twig = new Twig_Environment($loader, array( | ||
22 | 'debug' => true, | ||
23 | // ... | ||
24 | )); | ||
25 | $twig->addExtension(new Twig_Extension_Debug()); | ||
26 | |||
27 | Even when enabled, the ``dump`` function won't display anything if the | ||
28 | ``debug`` option on the environment is not enabled (to avoid leaking debug | ||
29 | information on a production server). | ||
30 | |||
31 | In an HTML context, wrap the output with a ``pre`` tag to make it easier to | ||
32 | read: | ||
33 | |||
34 | .. code-block:: jinja | ||
35 | |||
36 | <pre> | ||
37 | {{ dump(user) }} | ||
38 | </pre> | ||
39 | |||
40 | .. tip:: | ||
41 | |||
42 | Using a ``pre`` tag is not needed when `XDebug`_ is enabled and | ||
43 | ``html_errors`` is ``on``; as a bonus, the output is also nicer with | ||
44 | XDebug enabled. | ||
45 | |||
46 | You can debug several variables by passing them as additional arguments: | ||
47 | |||
48 | .. code-block:: jinja | ||
49 | |||
50 | {{ dump(user, categories) }} | ||
51 | |||
52 | If you don't pass any value, all variables from the current context are | ||
53 | dumped: | ||
54 | |||
55 | .. code-block:: jinja | ||
56 | |||
57 | {{ dump() }} | ||
58 | |||
59 | .. note:: | ||
60 | |||
61 | Internally, Twig uses the PHP `var_dump`_ function. | ||
62 | |||
63 | Arguments | ||
64 | --------- | ||
65 | |||
66 | * ``context``: The context to dump | ||
67 | |||
68 | .. _`XDebug`: http://xdebug.org/docs/display | ||
69 | .. _`var_dump`: http://php.net/var_dump | ||
diff --git a/vendor/twig/twig/doc/functions/include.rst b/vendor/twig/twig/doc/functions/include.rst deleted file mode 100644 index eaddfe61..00000000 --- a/vendor/twig/twig/doc/functions/include.rst +++ /dev/null | |||
@@ -1,80 +0,0 @@ | |||
1 | ``include`` | ||
2 | =========== | ||
3 | |||
4 | .. versionadded:: 1.12 | ||
5 | The include function was added in Twig 1.12. | ||
6 | |||
7 | The ``include`` function returns the rendered content of a template: | ||
8 | |||
9 | .. code-block:: jinja | ||
10 | |||
11 | {{ include('template.html') }} | ||
12 | {{ include(some_var) }} | ||
13 | |||
14 | Included templates have access to the variables of the active context. | ||
15 | |||
16 | If you are using the filesystem loader, the templates are looked for in the | ||
17 | paths defined by it. | ||
18 | |||
19 | The context is passed by default to the template but you can also pass | ||
20 | additional variables: | ||
21 | |||
22 | .. code-block:: jinja | ||
23 | |||
24 | {# template.html will have access to the variables from the current context and the additional ones provided #} | ||
25 | {{ include('template.html', {foo: 'bar'}) }} | ||
26 | |||
27 | You can disable access to the context by setting ``with_context`` to | ||
28 | ``false``: | ||
29 | |||
30 | .. code-block:: jinja | ||
31 | |||
32 | {# only the foo variable will be accessible #} | ||
33 | {{ include('template.html', {foo: 'bar'}, with_context = false) }} | ||
34 | |||
35 | .. code-block:: jinja | ||
36 | |||
37 | {# no variables will be accessible #} | ||
38 | {{ include('template.html', with_context = false) }} | ||
39 | |||
40 | And if the expression evaluates to a ``Twig_Template`` object, Twig will use it | ||
41 | directly:: | ||
42 | |||
43 | // {{ include(template) }} | ||
44 | |||
45 | $template = $twig->loadTemplate('some_template.twig'); | ||
46 | |||
47 | $twig->loadTemplate('template.twig')->display(array('template' => $template)); | ||
48 | |||
49 | When you set the ``ignore_missing`` flag, Twig will return an empty string if | ||
50 | the template does not exist: | ||
51 | |||
52 | .. code-block:: jinja | ||
53 | |||
54 | {{ include('sidebar.html', ignore_missing = true) }} | ||
55 | |||
56 | You can also provide a list of templates that are checked for existence before | ||
57 | inclusion. The first template that exists will be rendered: | ||
58 | |||
59 | .. code-block:: jinja | ||
60 | |||
61 | {{ include(['page_detailed.html', 'page.html']) }} | ||
62 | |||
63 | If ``ignore_missing`` is set, it will fall back to rendering nothing if none | ||
64 | of the templates exist, otherwise it will throw an exception. | ||
65 | |||
66 | When including a template created by an end user, you should consider | ||
67 | sandboxing it: | ||
68 | |||
69 | .. code-block:: jinja | ||
70 | |||
71 | {{ include('page.html', sandboxed = true) }} | ||
72 | |||
73 | Arguments | ||
74 | --------- | ||
75 | |||
76 | * ``template``: The template to render | ||
77 | * ``variables``: The variables to pass to the template | ||
78 | * ``with_context``: Whether to pass the current context variables or not | ||
79 | * ``ignore_missing``: Whether to ignore missing templates or not | ||
80 | * ``sandboxed``: Whether to sandbox the template or not | ||
diff --git a/vendor/twig/twig/doc/functions/index.rst b/vendor/twig/twig/doc/functions/index.rst deleted file mode 100644 index 8650cbdb..00000000 --- a/vendor/twig/twig/doc/functions/index.rst +++ /dev/null | |||
@@ -1,17 +0,0 @@ | |||
1 | Functions | ||
2 | ========= | ||
3 | |||
4 | .. toctree:: | ||
5 | :maxdepth: 1 | ||
6 | |||
7 | attribute | ||
8 | block | ||
9 | constant | ||
10 | cycle | ||
11 | date | ||
12 | dump | ||
13 | include | ||
14 | parent | ||
15 | random | ||
16 | range | ||
17 | template_from_string | ||
diff --git a/vendor/twig/twig/doc/functions/parent.rst b/vendor/twig/twig/doc/functions/parent.rst deleted file mode 100644 index f5bd2001..00000000 --- a/vendor/twig/twig/doc/functions/parent.rst +++ /dev/null | |||
@@ -1,20 +0,0 @@ | |||
1 | ``parent`` | ||
2 | ========== | ||
3 | |||
4 | When a template uses inheritance, it's possible to render the contents of the | ||
5 | parent block when overriding a block by using the ``parent`` function: | ||
6 | |||
7 | .. code-block:: jinja | ||
8 | |||
9 | {% extends "base.html" %} | ||
10 | |||
11 | {% block sidebar %} | ||
12 | <h3>Table Of Contents</h3> | ||
13 | ... | ||
14 | {{ parent() }} | ||
15 | {% endblock %} | ||
16 | |||
17 | The ``parent()`` call will return the content of the ``sidebar`` block as | ||
18 | defined in the ``base.html`` template. | ||
19 | |||
20 | .. seealso:: :doc:`extends<../tags/extends>`, :doc:`block<../functions/block>`, :doc:`block<../tags/block>` | ||
diff --git a/vendor/twig/twig/doc/functions/random.rst b/vendor/twig/twig/doc/functions/random.rst deleted file mode 100644 index a5a916bb..00000000 --- a/vendor/twig/twig/doc/functions/random.rst +++ /dev/null | |||
@@ -1,29 +0,0 @@ | |||
1 | ``random`` | ||
2 | ========== | ||
3 | |||
4 | .. versionadded:: 1.5 | ||
5 | The random function was added in Twig 1.5. | ||
6 | |||
7 | .. versionadded:: 1.6 | ||
8 | String and integer handling was added in Twig 1.6. | ||
9 | |||
10 | The ``random`` function returns a random value depending on the supplied | ||
11 | parameter type: | ||
12 | |||
13 | * a random item from a sequence; | ||
14 | * a random character from a string; | ||
15 | * a random integer between 0 and the integer parameter (inclusive). | ||
16 | |||
17 | .. code-block:: jinja | ||
18 | |||
19 | {{ random(['apple', 'orange', 'citrus']) }} {# example output: orange #} | ||
20 | {{ random('ABC') }} {# example output: C #} | ||
21 | {{ random() }} {# example output: 15386094 (works as native PHP `mt_rand`_ function) #} | ||
22 | {{ random(5) }} {# example output: 3 #} | ||
23 | |||
24 | Arguments | ||
25 | --------- | ||
26 | |||
27 | * ``values``: The values | ||
28 | |||
29 | .. _`mt_rand`: http://php.net/mt_rand | ||
diff --git a/vendor/twig/twig/doc/functions/range.rst b/vendor/twig/twig/doc/functions/range.rst deleted file mode 100644 index b1fa5471..00000000 --- a/vendor/twig/twig/doc/functions/range.rst +++ /dev/null | |||
@@ -1,45 +0,0 @@ | |||
1 | ``range`` | ||
2 | ========= | ||
3 | |||
4 | Returns a list containing an arithmetic progression of integers: | ||
5 | |||
6 | .. code-block:: jinja | ||
7 | |||
8 | {% for i in range(0, 3) %} | ||
9 | {{ i }}, | ||
10 | {% endfor %} | ||
11 | |||
12 | {# returns 0, 1, 2, 3 #} | ||
13 | |||
14 | When step is given (as the third parameter), it specifies the increment (or | ||
15 | decrement): | ||
16 | |||
17 | .. code-block:: jinja | ||
18 | |||
19 | {% for i in range(0, 6, 2) %} | ||
20 | {{ i }}, | ||
21 | {% endfor %} | ||
22 | |||
23 | {# returns 0, 2, 4, 6 #} | ||
24 | |||
25 | The Twig built-in ``..`` operator is just syntactic sugar for the ``range`` | ||
26 | function (with a step of 1): | ||
27 | |||
28 | .. code-block:: jinja | ||
29 | |||
30 | {% for i in 0..3 %} | ||
31 | {{ i }}, | ||
32 | {% endfor %} | ||
33 | |||
34 | .. tip:: | ||
35 | |||
36 | The ``range`` function works as the native PHP `range`_ function. | ||
37 | |||
38 | Arguments | ||
39 | --------- | ||
40 | |||
41 | * ``low``: The first value of the sequence. | ||
42 | * ``high``: The highest possible value of the sequence. | ||
43 | * ``step``: The increment between elements of the sequence. | ||
44 | |||
45 | .. _`range`: http://php.net/range | ||
diff --git a/vendor/twig/twig/doc/functions/template_from_string.rst b/vendor/twig/twig/doc/functions/template_from_string.rst deleted file mode 100644 index bbb06d86..00000000 --- a/vendor/twig/twig/doc/functions/template_from_string.rst +++ /dev/null | |||
@@ -1,32 +0,0 @@ | |||
1 | ``template_from_string`` | ||
2 | ======================== | ||
3 | |||
4 | .. versionadded:: 1.11 | ||
5 | The template_from_string function was added in Twig 1.11. | ||
6 | |||
7 | The ``template_from_string`` function loads a template from a string: | ||
8 | |||
9 | .. code-block:: jinja | ||
10 | |||
11 | {{ include(template_from_string("Hello {{ name }}") }} | ||
12 | {{ include(template_from_string(page.template)) }} | ||
13 | |||
14 | .. note:: | ||
15 | |||
16 | The ``template_from_string`` function is not available by default. You | ||
17 | must add the ``Twig_Extension_StringLoader`` extension explicitly when | ||
18 | creating your Twig environment:: | ||
19 | |||
20 | $twig = new Twig_Environment(...); | ||
21 | $twig->addExtension(new Twig_Extension_StringLoader()); | ||
22 | |||
23 | .. note:: | ||
24 | |||
25 | Even if you will probably always use the ``template_from_string`` function | ||
26 | with the ``include`` function, you can use it with any tag or function that | ||
27 | takes a template as an argument (like the ``embed`` or ``extends`` tags). | ||
28 | |||
29 | Arguments | ||
30 | --------- | ||
31 | |||
32 | * ``template``: The template | ||
diff --git a/vendor/twig/twig/doc/index.rst b/vendor/twig/twig/doc/index.rst deleted file mode 100644 index 3e5166c6..00000000 --- a/vendor/twig/twig/doc/index.rst +++ /dev/null | |||
@@ -1,18 +0,0 @@ | |||
1 | Twig | ||
2 | ==== | ||
3 | |||
4 | .. toctree:: | ||
5 | :maxdepth: 2 | ||
6 | |||
7 | intro | ||
8 | templates | ||
9 | api | ||
10 | advanced | ||
11 | internals | ||
12 | recipes | ||
13 | coding_standards | ||
14 | tags/index | ||
15 | filters/index | ||
16 | functions/index | ||
17 | tests/index | ||
18 | deprecated | ||
diff --git a/vendor/twig/twig/doc/internals.rst b/vendor/twig/twig/doc/internals.rst deleted file mode 100644 index 79a3c8d5..00000000 --- a/vendor/twig/twig/doc/internals.rst +++ /dev/null | |||
@@ -1,140 +0,0 @@ | |||
1 | Twig Internals | ||
2 | ============== | ||
3 | |||
4 | Twig is very extensible and you can easily hack it. Keep in mind that you | ||
5 | should probably try to create an extension before hacking the core, as most | ||
6 | features and enhancements can be done with extensions. This chapter is also | ||
7 | useful for people who want to understand how Twig works under the hood. | ||
8 | |||
9 | How Twig works? | ||
10 | --------------- | ||
11 | |||
12 | The rendering of a Twig template can be summarized into four key steps: | ||
13 | |||
14 | * **Load** the template: If the template is already compiled, load it and go | ||
15 | to the *evaluation* step, otherwise: | ||
16 | |||
17 | * First, the **lexer** tokenizes the template source code into small pieces | ||
18 | for easier processing; | ||
19 | * Then, the **parser** converts the token stream into a meaningful tree | ||
20 | of nodes (the Abstract Syntax Tree); | ||
21 | * Eventually, the *compiler* transforms the AST into PHP code; | ||
22 | |||
23 | * **Evaluate** the template: It basically means calling the ``display()`` | ||
24 | method of the compiled template and passing it the context. | ||
25 | |||
26 | The Lexer | ||
27 | --------- | ||
28 | |||
29 | The lexer tokenizes a template source code into a token stream (each token is | ||
30 | an instance of ``Twig_Token``, and the stream is an instance of | ||
31 | ``Twig_TokenStream``). The default lexer recognizes 13 different token types: | ||
32 | |||
33 | * ``Twig_Token::BLOCK_START_TYPE``, ``Twig_Token::BLOCK_END_TYPE``: Delimiters for blocks (``{% %}``) | ||
34 | * ``Twig_Token::VAR_START_TYPE``, ``Twig_Token::VAR_END_TYPE``: Delimiters for variables (``{{ }}``) | ||
35 | * ``Twig_Token::TEXT_TYPE``: A text outside an expression; | ||
36 | * ``Twig_Token::NAME_TYPE``: A name in an expression; | ||
37 | * ``Twig_Token::NUMBER_TYPE``: A number in an expression; | ||
38 | * ``Twig_Token::STRING_TYPE``: A string in an expression; | ||
39 | * ``Twig_Token::OPERATOR_TYPE``: An operator; | ||
40 | * ``Twig_Token::PUNCTUATION_TYPE``: A punctuation sign; | ||
41 | * ``Twig_Token::INTERPOLATION_START_TYPE``, ``Twig_Token::INTERPOLATION_END_TYPE`` (as of Twig 1.5): Delimiters for string interpolation; | ||
42 | * ``Twig_Token::EOF_TYPE``: Ends of template. | ||
43 | |||
44 | You can manually convert a source code into a token stream by calling the | ||
45 | ``tokenize()`` of an environment:: | ||
46 | |||
47 | $stream = $twig->tokenize($source, $identifier); | ||
48 | |||
49 | As the stream has a ``__toString()`` method, you can have a textual | ||
50 | representation of it by echoing the object:: | ||
51 | |||
52 | echo $stream."\n"; | ||
53 | |||
54 | Here is the output for the ``Hello {{ name }}`` template: | ||
55 | |||
56 | .. code-block:: text | ||
57 | |||
58 | TEXT_TYPE(Hello ) | ||
59 | VAR_START_TYPE() | ||
60 | NAME_TYPE(name) | ||
61 | VAR_END_TYPE() | ||
62 | EOF_TYPE() | ||
63 | |||
64 | .. note:: | ||
65 | |||
66 | You can change the default lexer use by Twig (``Twig_Lexer``) by calling | ||
67 | the ``setLexer()`` method:: | ||
68 | |||
69 | $twig->setLexer($lexer); | ||
70 | |||
71 | The Parser | ||
72 | ---------- | ||
73 | |||
74 | The parser converts the token stream into an AST (Abstract Syntax Tree), or a | ||
75 | node tree (an instance of ``Twig_Node_Module``). The core extension defines | ||
76 | the basic nodes like: ``for``, ``if``, ... and the expression nodes. | ||
77 | |||
78 | You can manually convert a token stream into a node tree by calling the | ||
79 | ``parse()`` method of an environment:: | ||
80 | |||
81 | $nodes = $twig->parse($stream); | ||
82 | |||
83 | Echoing the node object gives you a nice representation of the tree:: | ||
84 | |||
85 | echo $nodes."\n"; | ||
86 | |||
87 | Here is the output for the ``Hello {{ name }}`` template: | ||
88 | |||
89 | .. code-block:: text | ||
90 | |||
91 | Twig_Node_Module( | ||
92 | Twig_Node_Text(Hello ) | ||
93 | Twig_Node_Print( | ||
94 | Twig_Node_Expression_Name(name) | ||
95 | ) | ||
96 | ) | ||
97 | |||
98 | .. note:: | ||
99 | |||
100 | The default parser (``Twig_TokenParser``) can be also changed by calling the | ||
101 | ``setParser()`` method:: | ||
102 | |||
103 | $twig->setParser($parser); | ||
104 | |||
105 | The Compiler | ||
106 | ------------ | ||
107 | |||
108 | The last step is done by the compiler. It takes a node tree as an input and | ||
109 | generates PHP code usable for runtime execution of the template. | ||
110 | |||
111 | You can call the compiler by hand with the ``compile()`` method of an | ||
112 | environment:: | ||
113 | |||
114 | $php = $twig->compile($nodes); | ||
115 | |||
116 | The ``compile()`` method returns the PHP source code representing the node. | ||
117 | |||
118 | The generated template for a ``Hello {{ name }}`` template reads as follows | ||
119 | (the actual output can differ depending on the version of Twig you are | ||
120 | using):: | ||
121 | |||
122 | /* Hello {{ name }} */ | ||
123 | class __TwigTemplate_1121b6f109fe93ebe8c6e22e3712bceb extends Twig_Template | ||
124 | { | ||
125 | protected function doDisplay(array $context, array $blocks = array()) | ||
126 | { | ||
127 | // line 1 | ||
128 | echo "Hello "; | ||
129 | echo twig_escape_filter($this->env, $this->getContext($context, "name"), "ndex", null, true); | ||
130 | } | ||
131 | |||
132 | // some more code | ||
133 | } | ||
134 | |||
135 | .. note:: | ||
136 | |||
137 | As for the lexer and the parser, the default compiler (``Twig_Compiler``) can | ||
138 | be changed by calling the ``setCompiler()`` method:: | ||
139 | |||
140 | $twig->setCompiler($compiler); | ||
diff --git a/vendor/twig/twig/doc/intro.rst b/vendor/twig/twig/doc/intro.rst deleted file mode 100644 index bdcdb8a0..00000000 --- a/vendor/twig/twig/doc/intro.rst +++ /dev/null | |||
@@ -1,164 +0,0 @@ | |||
1 | Introduction | ||
2 | ============ | ||
3 | |||
4 | This is the documentation for Twig, the flexible, fast, and secure template | ||
5 | engine for PHP. | ||
6 | |||
7 | If you have any exposure to other text-based template languages, such as | ||
8 | Smarty, Django, or Jinja, you should feel right at home with Twig. It's both | ||
9 | designer and developer friendly by sticking to PHP's principles and adding | ||
10 | functionality useful for templating environments. | ||
11 | |||
12 | The key-features are... | ||
13 | |||
14 | * *Fast*: Twig compiles templates down to plain optimized PHP code. The | ||
15 | overhead compared to regular PHP code was reduced to the very minimum. | ||
16 | |||
17 | * *Secure*: Twig has a sandbox mode to evaluate untrusted template code. This | ||
18 | allows Twig to be used as a template language for applications where users | ||
19 | may modify the template design. | ||
20 | |||
21 | * *Flexible*: Twig is powered by a flexible lexer and parser. This allows the | ||
22 | developer to define its own custom tags and filters, and create its own DSL. | ||
23 | |||
24 | Prerequisites | ||
25 | ------------- | ||
26 | |||
27 | Twig needs at least **PHP 5.2.4** to run. | ||
28 | |||
29 | Installation | ||
30 | ------------ | ||
31 | |||
32 | You have multiple ways to install Twig. | ||
33 | |||
34 | Installing via Composer (recommended) | ||
35 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
36 | |||
37 | 1. Install composer in your project: | ||
38 | |||
39 | .. code-block:: bash | ||
40 | |||
41 | curl -s http://getcomposer.org/installer | php | ||
42 | |||
43 | 2. Create a ``composer.json`` file in your project root: | ||
44 | |||
45 | .. code-block:: javascript | ||
46 | |||
47 | { | ||
48 | "require": { | ||
49 | "twig/twig": "1.*" | ||
50 | } | ||
51 | } | ||
52 | |||
53 | 3. Install via composer | ||
54 | |||
55 | .. code-block:: bash | ||
56 | |||
57 | php composer.phar install | ||
58 | |||
59 | .. note:: | ||
60 | If you want to learn more about Composer, the ``composer.json`` file syntax | ||
61 | and its usage, you can read the `online documentation`_. | ||
62 | |||
63 | Installing from the tarball release | ||
64 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
65 | |||
66 | 1. Download the most recent tarball from the `download page`_ | ||
67 | 2. Unpack the tarball | ||
68 | 3. Move the files somewhere in your project | ||
69 | |||
70 | Installing the development version | ||
71 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
72 | |||
73 | 1. Install Git | ||
74 | 2. ``git clone git://github.com/fabpot/Twig.git`` | ||
75 | |||
76 | Installing the PEAR package | ||
77 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
78 | |||
79 | 1. Install PEAR | ||
80 | 2. ``pear channel-discover pear.twig-project.org`` | ||
81 | 3. ``pear install twig/Twig`` (or ``pear install twig/Twig-beta``) | ||
82 | |||
83 | |||
84 | Installing the C extension | ||
85 | ~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
86 | |||
87 | .. versionadded:: 1.4 | ||
88 | The C extension was added in Twig 1.4. | ||
89 | |||
90 | Twig comes with a C extension that enhances the performance of the Twig | ||
91 | runtime engine. You can install it like any other PHP extension: | ||
92 | |||
93 | .. code-block:: bash | ||
94 | |||
95 | $ cd ext/twig | ||
96 | $ phpize | ||
97 | $ ./configure | ||
98 | $ make | ||
99 | $ make install | ||
100 | |||
101 | Finally, enable the extension in your ``php.ini`` configuration file: | ||
102 | |||
103 | .. code-block:: ini | ||
104 | |||
105 | extension=twig.so | ||
106 | |||
107 | And from now on, Twig will automatically compile your templates to take | ||
108 | advantage of the C extension. Note that this extension does not replace the | ||
109 | PHP code but only provides an optimized version of the | ||
110 | ``Twig_Template::getAttribute()`` method. | ||
111 | |||
112 | .. tip:: | ||
113 | |||
114 | On Windows, you can also simply download and install a `pre-built DLL`_. | ||
115 | |||
116 | Basic API Usage | ||
117 | --------------- | ||
118 | |||
119 | This section gives you a brief introduction to the PHP API for Twig. | ||
120 | |||
121 | The first step to use Twig is to register its autoloader:: | ||
122 | |||
123 | require_once '/path/to/lib/Twig/Autoloader.php'; | ||
124 | Twig_Autoloader::register(); | ||
125 | |||
126 | Replace the ``/path/to/lib/`` path with the path you used for Twig | ||
127 | installation. | ||
128 | |||
129 | If you have installed Twig via Composer you can take advantage of Composer's | ||
130 | autoload mechanism by replacing the previous snippet for:: | ||
131 | |||
132 | require_once '/path/to/vendor/autoload.php'; | ||
133 | |||
134 | .. note:: | ||
135 | |||
136 | Twig follows the PEAR convention names for its classes, which means you | ||
137 | can easily integrate Twig classes loading in your own autoloader. | ||
138 | |||
139 | .. code-block:: php | ||
140 | |||
141 | $loader = new Twig_Loader_String(); | ||
142 | $twig = new Twig_Environment($loader); | ||
143 | |||
144 | echo $twig->render('Hello {{ name }}!', array('name' => 'Fabien')); | ||
145 | |||
146 | Twig uses a loader (``Twig_Loader_String``) to locate templates, and an | ||
147 | environment (``Twig_Environment``) to store the configuration. | ||
148 | |||
149 | The ``render()`` method loads the template passed as a first argument and | ||
150 | renders it with the variables passed as a second argument. | ||
151 | |||
152 | As templates are generally stored on the filesystem, Twig also comes with a | ||
153 | filesystem loader:: | ||
154 | |||
155 | $loader = new Twig_Loader_Filesystem('/path/to/templates'); | ||
156 | $twig = new Twig_Environment($loader, array( | ||
157 | 'cache' => '/path/to/compilation_cache', | ||
158 | )); | ||
159 | |||
160 | echo $twig->render('index.html', array('name' => 'Fabien')); | ||
161 | |||
162 | .. _`download page`: https://github.com/fabpot/Twig/tags | ||
163 | .. _`online documentation`: http://getcomposer.org/doc | ||
164 | .. _`pre-built DLL`: https://github.com/stealth35/stealth35.github.com/downloads | ||
diff --git a/vendor/twig/twig/doc/recipes.rst b/vendor/twig/twig/doc/recipes.rst deleted file mode 100644 index dfcc9205..00000000 --- a/vendor/twig/twig/doc/recipes.rst +++ /dev/null | |||
@@ -1,475 +0,0 @@ | |||
1 | Recipes | ||
2 | ======= | ||
3 | |||
4 | Making a Layout conditional | ||
5 | --------------------------- | ||
6 | |||
7 | Working with Ajax means that the same content is sometimes displayed as is, | ||
8 | and sometimes decorated with a layout. As Twig layout template names can be | ||
9 | any valid expression, you can pass a variable that evaluates to ``true`` when | ||
10 | the request is made via Ajax and choose the layout accordingly: | ||
11 | |||
12 | .. code-block:: jinja | ||
13 | |||
14 | {% extends request.ajax ? "base_ajax.html" : "base.html" %} | ||
15 | |||
16 | {% block content %} | ||
17 | This is the content to be displayed. | ||
18 | {% endblock %} | ||
19 | |||
20 | Making an Include dynamic | ||
21 | ------------------------- | ||
22 | |||
23 | When including a template, its name does not need to be a string. For | ||
24 | instance, the name can depend on the value of a variable: | ||
25 | |||
26 | .. code-block:: jinja | ||
27 | |||
28 | {% include var ~ '_foo.html' %} | ||
29 | |||
30 | If ``var`` evaluates to ``index``, the ``index_foo.html`` template will be | ||
31 | rendered. | ||
32 | |||
33 | As a matter of fact, the template name can be any valid expression, such as | ||
34 | the following: | ||
35 | |||
36 | .. code-block:: jinja | ||
37 | |||
38 | {% include var|default('index') ~ '_foo.html' %} | ||
39 | |||
40 | Overriding a Template that also extends itself | ||
41 | ---------------------------------------------- | ||
42 | |||
43 | A template can be customized in two different ways: | ||
44 | |||
45 | * *Inheritance*: A template *extends* a parent template and overrides some | ||
46 | blocks; | ||
47 | |||
48 | * *Replacement*: If you use the filesystem loader, Twig loads the first | ||
49 | template it finds in a list of configured directories; a template found in a | ||
50 | directory *replaces* another one from a directory further in the list. | ||
51 | |||
52 | But how do you combine both: *replace* a template that also extends itself | ||
53 | (aka a template in a directory further in the list)? | ||
54 | |||
55 | Let's say that your templates are loaded from both ``.../templates/mysite`` | ||
56 | and ``.../templates/default`` in this order. The ``page.twig`` template, | ||
57 | stored in ``.../templates/default`` reads as follows: | ||
58 | |||
59 | .. code-block:: jinja | ||
60 | |||
61 | {# page.twig #} | ||
62 | {% extends "layout.twig" %} | ||
63 | |||
64 | {% block content %} | ||
65 | {% endblock %} | ||
66 | |||
67 | You can replace this template by putting a file with the same name in | ||
68 | ``.../templates/mysite``. And if you want to extend the original template, you | ||
69 | might be tempted to write the following: | ||
70 | |||
71 | .. code-block:: jinja | ||
72 | |||
73 | {# page.twig in .../templates/mysite #} | ||
74 | {% extends "page.twig" %} {# from .../templates/default #} | ||
75 | |||
76 | Of course, this will not work as Twig will always load the template from | ||
77 | ``.../templates/mysite``. | ||
78 | |||
79 | It turns out it is possible to get this to work, by adding a directory right | ||
80 | at the end of your template directories, which is the parent of all of the | ||
81 | other directories: ``.../templates`` in our case. This has the effect of | ||
82 | making every template file within our system uniquely addressable. Most of the | ||
83 | time you will use the "normal" paths, but in the special case of wanting to | ||
84 | extend a template with an overriding version of itself we can reference its | ||
85 | parent's full, unambiguous template path in the extends tag: | ||
86 | |||
87 | .. code-block:: jinja | ||
88 | |||
89 | {# page.twig in .../templates/mysite #} | ||
90 | {% extends "default/page.twig" %} {# from .../templates #} | ||
91 | |||
92 | .. note:: | ||
93 | |||
94 | This recipe was inspired by the following Django wiki page: | ||
95 | http://code.djangoproject.com/wiki/ExtendingTemplates | ||
96 | |||
97 | Customizing the Syntax | ||
98 | ---------------------- | ||
99 | |||
100 | Twig allows some syntax customization for the block delimiters. It's not | ||
101 | recommended to use this feature as templates will be tied with your custom | ||
102 | syntax. But for specific projects, it can make sense to change the defaults. | ||
103 | |||
104 | To change the block delimiters, you need to create your own lexer object:: | ||
105 | |||
106 | $twig = new Twig_Environment(); | ||
107 | |||
108 | $lexer = new Twig_Lexer($twig, array( | ||
109 | 'tag_comment' => array('{#', '#}'), | ||
110 | 'tag_block' => array('{%', '%}'), | ||
111 | 'tag_variable' => array('{{', '}}'), | ||
112 | 'interpolation' => array('#{', '}'), | ||
113 | )); | ||
114 | $twig->setLexer($lexer); | ||
115 | |||
116 | Here are some configuration example that simulates some other template engines | ||
117 | syntax:: | ||
118 | |||
119 | // Ruby erb syntax | ||
120 | $lexer = new Twig_Lexer($twig, array( | ||
121 | 'tag_comment' => array('<%#', '%>'), | ||
122 | 'tag_block' => array('<%', '%>'), | ||
123 | 'tag_variable' => array('<%=', '%>'), | ||
124 | )); | ||
125 | |||
126 | // SGML Comment Syntax | ||
127 | $lexer = new Twig_Lexer($twig, array( | ||
128 | 'tag_comment' => array('<!--#', '-->'), | ||
129 | 'tag_block' => array('<!--', '-->'), | ||
130 | 'tag_variable' => array('${', '}'), | ||
131 | )); | ||
132 | |||
133 | // Smarty like | ||
134 | $lexer = new Twig_Lexer($twig, array( | ||
135 | 'tag_comment' => array('{*', '*}'), | ||
136 | 'tag_block' => array('{', '}'), | ||
137 | 'tag_variable' => array('{$', '}'), | ||
138 | )); | ||
139 | |||
140 | Using dynamic Object Properties | ||
141 | ------------------------------- | ||
142 | |||
143 | When Twig encounters a variable like ``article.title``, it tries to find a | ||
144 | ``title`` public property in the ``article`` object. | ||
145 | |||
146 | It also works if the property does not exist but is rather defined dynamically | ||
147 | thanks to the magic ``__get()`` method; you just need to also implement the | ||
148 | ``__isset()`` magic method like shown in the following snippet of code:: | ||
149 | |||
150 | class Article | ||
151 | { | ||
152 | public function __get($name) | ||
153 | { | ||
154 | if ('title' == $name) { | ||
155 | return 'The title'; | ||
156 | } | ||
157 | |||
158 | // throw some kind of error | ||
159 | } | ||
160 | |||
161 | public function __isset($name) | ||
162 | { | ||
163 | if ('title' == $name) { | ||
164 | return true; | ||
165 | } | ||
166 | |||
167 | return false; | ||
168 | } | ||
169 | } | ||
170 | |||
171 | Accessing the parent Context in Nested Loops | ||
172 | -------------------------------------------- | ||
173 | |||
174 | Sometimes, when using nested loops, you need to access the parent context. The | ||
175 | parent context is always accessible via the ``loop.parent`` variable. For | ||
176 | instance, if you have the following template data:: | ||
177 | |||
178 | $data = array( | ||
179 | 'topics' => array( | ||
180 | 'topic1' => array('Message 1 of topic 1', 'Message 2 of topic 1'), | ||
181 | 'topic2' => array('Message 1 of topic 2', 'Message 2 of topic 2'), | ||
182 | ), | ||
183 | ); | ||
184 | |||
185 | And the following template to display all messages in all topics: | ||
186 | |||
187 | .. code-block:: jinja | ||
188 | |||
189 | {% for topic, messages in topics %} | ||
190 | * {{ loop.index }}: {{ topic }} | ||
191 | {% for message in messages %} | ||
192 | - {{ loop.parent.loop.index }}.{{ loop.index }}: {{ message }} | ||
193 | {% endfor %} | ||
194 | {% endfor %} | ||
195 | |||
196 | The output will be similar to: | ||
197 | |||
198 | .. code-block:: text | ||
199 | |||
200 | * 1: topic1 | ||
201 | - 1.1: The message 1 of topic 1 | ||
202 | - 1.2: The message 2 of topic 1 | ||
203 | * 2: topic2 | ||
204 | - 2.1: The message 1 of topic 2 | ||
205 | - 2.2: The message 2 of topic 2 | ||
206 | |||
207 | In the inner loop, the ``loop.parent`` variable is used to access the outer | ||
208 | context. So, the index of the current ``topic`` defined in the outer for loop | ||
209 | is accessible via the ``loop.parent.loop.index`` variable. | ||
210 | |||
211 | Defining undefined Functions and Filters on the Fly | ||
212 | --------------------------------------------------- | ||
213 | |||
214 | When a function (or a filter) is not defined, Twig defaults to throw a | ||
215 | ``Twig_Error_Syntax`` exception. However, it can also call a `callback`_ (any | ||
216 | valid PHP callable) which should return a function (or a filter). | ||
217 | |||
218 | For filters, register callbacks with ``registerUndefinedFilterCallback()``. | ||
219 | For functions, use ``registerUndefinedFunctionCallback()``:: | ||
220 | |||
221 | // auto-register all native PHP functions as Twig functions | ||
222 | // don't try this at home as it's not secure at all! | ||
223 | $twig->registerUndefinedFunctionCallback(function ($name) { | ||
224 | if (function_exists($name)) { | ||
225 | return new Twig_Function_Function($name); | ||
226 | } | ||
227 | |||
228 | return false; | ||
229 | }); | ||
230 | |||
231 | If the callable is not able to return a valid function (or filter), it must | ||
232 | return ``false``. | ||
233 | |||
234 | If you register more than one callback, Twig will call them in turn until one | ||
235 | does not return ``false``. | ||
236 | |||
237 | .. tip:: | ||
238 | |||
239 | As the resolution of functions and filters is done during compilation, | ||
240 | there is no overhead when registering these callbacks. | ||
241 | |||
242 | Validating the Template Syntax | ||
243 | ------------------------------ | ||
244 | |||
245 | When template code is providing by a third-party (through a web interface for | ||
246 | instance), it might be interesting to validate the template syntax before | ||
247 | saving it. If the template code is stored in a `$template` variable, here is | ||
248 | how you can do it:: | ||
249 | |||
250 | try { | ||
251 | $twig->parse($twig->tokenize($template)); | ||
252 | |||
253 | // the $template is valid | ||
254 | } catch (Twig_Error_Syntax $e) { | ||
255 | // $template contains one or more syntax errors | ||
256 | } | ||
257 | |||
258 | If you iterate over a set of files, you can pass the filename to the | ||
259 | ``tokenize()`` method to get the filename in the exception message:: | ||
260 | |||
261 | foreach ($files as $file) { | ||
262 | try { | ||
263 | $twig->parse($twig->tokenize($template, $file)); | ||
264 | |||
265 | // the $template is valid | ||
266 | } catch (Twig_Error_Syntax $e) { | ||
267 | // $template contains one or more syntax errors | ||
268 | } | ||
269 | } | ||
270 | |||
271 | .. note:: | ||
272 | |||
273 | This method won't catch any sandbox policy violations because the policy | ||
274 | is enforced during template rendering (as Twig needs the context for some | ||
275 | checks like allowed methods on objects). | ||
276 | |||
277 | Refreshing modified Templates when APC is enabled and apc.stat = 0 | ||
278 | ------------------------------------------------------------------ | ||
279 | |||
280 | When using APC with ``apc.stat`` set to ``0`` and Twig cache enabled, clearing | ||
281 | the template cache won't update the APC cache. To get around this, one can | ||
282 | extend ``Twig_Environment`` and force the update of the APC cache when Twig | ||
283 | rewrites the cache:: | ||
284 | |||
285 | class Twig_Environment_APC extends Twig_Environment | ||
286 | { | ||
287 | protected function writeCacheFile($file, $content) | ||
288 | { | ||
289 | parent::writeCacheFile($file, $content); | ||
290 | |||
291 | // Compile cached file into bytecode cache | ||
292 | apc_compile_file($file); | ||
293 | } | ||
294 | } | ||
295 | |||
296 | Reusing a stateful Node Visitor | ||
297 | ------------------------------- | ||
298 | |||
299 | When attaching a visitor to a ``Twig_Environment`` instance, Twig uses it to | ||
300 | visit *all* templates it compiles. If you need to keep some state information | ||
301 | around, you probably want to reset it when visiting a new template. | ||
302 | |||
303 | This can be easily achieved with the following code:: | ||
304 | |||
305 | protected $someTemplateState = array(); | ||
306 | |||
307 | public function enterNode(Twig_NodeInterface $node, Twig_Environment $env) | ||
308 | { | ||
309 | if ($node instanceof Twig_Node_Module) { | ||
310 | // reset the state as we are entering a new template | ||
311 | $this->someTemplateState = array(); | ||
312 | } | ||
313 | |||
314 | // ... | ||
315 | |||
316 | return $node; | ||
317 | } | ||
318 | |||
319 | Using the Template name to set the default Escaping Strategy | ||
320 | ------------------------------------------------------------ | ||
321 | |||
322 | .. versionadded:: 1.8 | ||
323 | This recipe requires Twig 1.8 or later. | ||
324 | |||
325 | The ``autoescape`` option determines the default escaping strategy to use when | ||
326 | no escaping is applied on a variable. When Twig is used to mostly generate | ||
327 | HTML files, you can set it to ``html`` and explicitly change it to ``js`` when | ||
328 | you have some dynamic JavaScript files thanks to the ``autoescape`` tag: | ||
329 | |||
330 | .. code-block:: jinja | ||
331 | |||
332 | {% autoescape 'js' %} | ||
333 | ... some JS ... | ||
334 | {% endautoescape %} | ||
335 | |||
336 | But if you have many HTML and JS files, and if your template names follow some | ||
337 | conventions, you can instead determine the default escaping strategy to use | ||
338 | based on the template name. Let's say that your template names always ends | ||
339 | with ``.html`` for HTML files, ``.js`` for JavaScript ones, and ``.css`` for | ||
340 | stylesheets, here is how you can configure Twig:: | ||
341 | |||
342 | class TwigEscapingGuesser | ||
343 | { | ||
344 | function guess($filename) | ||
345 | { | ||
346 | // get the format | ||
347 | $format = substr($filename, strrpos($filename, '.') + 1); | ||
348 | |||
349 | switch ($format) { | ||
350 | case 'js': | ||
351 | return 'js'; | ||
352 | case 'css': | ||
353 | return 'css'; | ||
354 | case 'html': | ||
355 | default: | ||
356 | return 'html'; | ||
357 | } | ||
358 | } | ||
359 | } | ||
360 | |||
361 | $loader = new Twig_Loader_Filesystem('/path/to/templates'); | ||
362 | $twig = new Twig_Environment($loader, array( | ||
363 | 'autoescape' => array(new TwigEscapingGuesser(), 'guess'), | ||
364 | )); | ||
365 | |||
366 | This dynamic strategy does not incur any overhead at runtime as auto-escaping | ||
367 | is done at compilation time. | ||
368 | |||
369 | Using a Database to store Templates | ||
370 | ----------------------------------- | ||
371 | |||
372 | If you are developing a CMS, templates are usually stored in a database. This | ||
373 | recipe gives you a simple PDO template loader you can use as a starting point | ||
374 | for your own. | ||
375 | |||
376 | First, let's create a temporary in-memory SQLite3 database to work with:: | ||
377 | |||
378 | $dbh = new PDO('sqlite::memory:'); | ||
379 | $dbh->exec('CREATE TABLE templates (name STRING, source STRING, last_modified INTEGER)'); | ||
380 | $base = '{% block content %}{% endblock %}'; | ||
381 | $index = ' | ||
382 | {% extends "base.twig" %} | ||
383 | {% block content %}Hello {{ name }}{% endblock %} | ||
384 | '; | ||
385 | $now = time(); | ||
386 | $dbh->exec("INSERT INTO templates (name, source, last_modified) VALUES ('base.twig', '$base', $now)"); | ||
387 | $dbh->exec("INSERT INTO templates (name, source, last_modified) VALUES ('index.twig', '$index', $now)"); | ||
388 | |||
389 | We have created a simple ``templates`` table that hosts two templates: | ||
390 | ``base.twig`` and ``index.twig``. | ||
391 | |||
392 | Now, let's define a loader able to use this database:: | ||
393 | |||
394 | class DatabaseTwigLoader implements Twig_LoaderInterface, Twig_ExistsLoaderInterface | ||
395 | { | ||
396 | protected $dbh; | ||
397 | |||
398 | public function __construct(PDO $dbh) | ||
399 | { | ||
400 | $this->dbh = $dbh; | ||
401 | } | ||
402 | |||
403 | public function getSource($name) | ||
404 | { | ||
405 | if (false === $source = $this->getValue('source', $name)) { | ||
406 | throw new Twig_Error_Loader(sprintf('Template "%s" does not exist.', $name)); | ||
407 | } | ||
408 | |||
409 | return $source; | ||
410 | } | ||
411 | |||
412 | // Twig_ExistsLoaderInterface as of Twig 1.11 | ||
413 | public function exists($name) | ||
414 | { | ||
415 | return $name === $this->getValue('name', $name); | ||
416 | } | ||
417 | |||
418 | public function getCacheKey($name) | ||
419 | { | ||
420 | return $name; | ||
421 | } | ||
422 | |||
423 | public function isFresh($name, $time) | ||
424 | { | ||
425 | if (false === $lastModified = $this->getValue('last_modified', $name)) { | ||
426 | return false; | ||
427 | } | ||
428 | |||
429 | return $lastModified <= $time; | ||
430 | } | ||
431 | |||
432 | protected function getValue($column, $name) | ||
433 | { | ||
434 | $sth = $this->dbh->prepare('SELECT '.$column.' FROM templates WHERE name = :name'); | ||
435 | $sth->execute(array(':name' => (string) $name)); | ||
436 | |||
437 | return $sth->fetchColumn(); | ||
438 | } | ||
439 | } | ||
440 | |||
441 | Finally, here is an example on how you can use it:: | ||
442 | |||
443 | $loader = new DatabaseTwigLoader($dbh); | ||
444 | $twig = new Twig_Environment($loader); | ||
445 | |||
446 | echo $twig->render('index.twig', array('name' => 'Fabien')); | ||
447 | |||
448 | Using different Template Sources | ||
449 | -------------------------------- | ||
450 | |||
451 | This recipe is the continuation of the previous one. Even if you store the | ||
452 | contributed templates in a database, you might want to keep the original/base | ||
453 | templates on the filesystem. When templates can be loaded from different | ||
454 | sources, you need to use the ``Twig_Loader_Chain`` loader. | ||
455 | |||
456 | As you can see in the previous recipe, we reference the template in the exact | ||
457 | same way as we would have done it with a regular filesystem loader. This is | ||
458 | the key to be able to mix and match templates coming from the database, the | ||
459 | filesystem, or any other loader for that matter: the template name should be a | ||
460 | logical name, and not the path from the filesystem:: | ||
461 | |||
462 | $loader1 = new DatabaseTwigLoader($dbh); | ||
463 | $loader2 = new Twig_Loader_Array(array( | ||
464 | 'base.twig' => '{% block content %}{% endblock %}', | ||
465 | )); | ||
466 | $loader = new Twig_Loader_Chain(array($loader1, $loader2)); | ||
467 | |||
468 | $twig = new Twig_Environment($loader); | ||
469 | |||
470 | echo $twig->render('index.twig', array('name' => 'Fabien')); | ||
471 | |||
472 | Now that the ``base.twig`` templates is defined in an array loader, you can | ||
473 | remove it from the database, and everything else will still work as before. | ||
474 | |||
475 | .. _callback: http://www.php.net/manual/en/function.is-callable.php | ||
diff --git a/vendor/twig/twig/doc/tags/autoescape.rst b/vendor/twig/twig/doc/tags/autoescape.rst deleted file mode 100644 index c5ff0c2c..00000000 --- a/vendor/twig/twig/doc/tags/autoescape.rst +++ /dev/null | |||
@@ -1,71 +0,0 @@ | |||
1 | ``autoescape`` | ||
2 | ============== | ||
3 | |||
4 | Whether automatic escaping is enabled or not, you can mark a section of a | ||
5 | template to be escaped or not by using the ``autoescape`` tag: | ||
6 | |||
7 | .. code-block:: jinja | ||
8 | |||
9 | {# The following syntax works as of Twig 1.8 -- see the note below for previous versions #} | ||
10 | |||
11 | {% autoescape %} | ||
12 | Everything will be automatically escaped in this block | ||
13 | using the HTML strategy | ||
14 | {% endautoescape %} | ||
15 | |||
16 | {% autoescape 'html' %} | ||
17 | Everything will be automatically escaped in this block | ||
18 | using the HTML strategy | ||
19 | {% endautoescape %} | ||
20 | |||
21 | {% autoescape 'js' %} | ||
22 | Everything will be automatically escaped in this block | ||
23 | using the js escaping strategy | ||
24 | {% endautoescape %} | ||
25 | |||
26 | {% autoescape false %} | ||
27 | Everything will be outputted as is in this block | ||
28 | {% endautoescape %} | ||
29 | |||
30 | .. note:: | ||
31 | |||
32 | Before Twig 1.8, the syntax was different: | ||
33 | |||
34 | .. code-block:: jinja | ||
35 | |||
36 | {% autoescape true %} | ||
37 | Everything will be automatically escaped in this block | ||
38 | using the HTML strategy | ||
39 | {% endautoescape %} | ||
40 | |||
41 | {% autoescape false %} | ||
42 | Everything will be outputted as is in this block | ||
43 | {% endautoescape %} | ||
44 | |||
45 | {% autoescape true js %} | ||
46 | Everything will be automatically escaped in this block | ||
47 | using the js escaping strategy | ||
48 | {% endautoescape %} | ||
49 | |||
50 | When automatic escaping is enabled everything is escaped by default except for | ||
51 | values explicitly marked as safe. Those can be marked in the template by using | ||
52 | the :doc:`raw<../filters/raw>` filter: | ||
53 | |||
54 | .. code-block:: jinja | ||
55 | |||
56 | {% autoescape %} | ||
57 | {{ safe_value|raw }} | ||
58 | {% endautoescape %} | ||
59 | |||
60 | Functions returning template data (like :doc:`macros<macro>` and | ||
61 | :doc:`parent<../functions/parent>`) always return safe markup. | ||
62 | |||
63 | .. note:: | ||
64 | |||
65 | Twig is smart enough to not escape an already escaped value by the | ||
66 | :doc:`escape<../filters/escape>` filter. | ||
67 | |||
68 | .. note:: | ||
69 | |||
70 | The chapter :doc:`Twig for Developers<../api>` gives more information | ||
71 | about when and how automatic escaping is applied. | ||
diff --git a/vendor/twig/twig/doc/tags/block.rst b/vendor/twig/twig/doc/tags/block.rst deleted file mode 100644 index e3804823..00000000 --- a/vendor/twig/twig/doc/tags/block.rst +++ /dev/null | |||
@@ -1,11 +0,0 @@ | |||
1 | ``block`` | ||
2 | ========= | ||
3 | |||
4 | Blocks are used for inheritance and act as placeholders and replacements at | ||
5 | the same time. They are documented in detail in the documentation for the | ||
6 | :doc:`extends<../tags/extends>` tag. | ||
7 | |||
8 | Block names should consist of alphanumeric characters, and underscores. Dashes | ||
9 | are not permitted. | ||
10 | |||
11 | .. seealso:: :doc:`block<../functions/block>`, :doc:`parent<../functions/parent>`, :doc:`use<../tags/use>`, :doc:`extends<../tags/extends>` | ||
diff --git a/vendor/twig/twig/doc/tags/do.rst b/vendor/twig/twig/doc/tags/do.rst deleted file mode 100644 index eca63d0a..00000000 --- a/vendor/twig/twig/doc/tags/do.rst +++ /dev/null | |||
@@ -1,12 +0,0 @@ | |||
1 | ``do`` | ||
2 | ====== | ||
3 | |||
4 | .. versionadded:: 1.5 | ||
5 | The do tag was added in Twig 1.5. | ||
6 | |||
7 | The ``do`` tag works exactly like the regular variable expression (``{{ ... | ||
8 | }}``) just that it doesn't print anything: | ||
9 | |||
10 | .. code-block:: jinja | ||
11 | |||
12 | {% do 1 + 2 %} | ||
diff --git a/vendor/twig/twig/doc/tags/embed.rst b/vendor/twig/twig/doc/tags/embed.rst deleted file mode 100644 index 5a6a0299..00000000 --- a/vendor/twig/twig/doc/tags/embed.rst +++ /dev/null | |||
@@ -1,178 +0,0 @@ | |||
1 | ``embed`` | ||
2 | ========= | ||
3 | |||
4 | .. versionadded:: 1.8 | ||
5 | The ``embed`` tag was added in Twig 1.8. | ||
6 | |||
7 | The ``embed`` tag combines the behaviour of :doc:`include<include>` and | ||
8 | :doc:`extends<extends>`. | ||
9 | It allows you to include another template's contents, just like ``include`` | ||
10 | does. But it also allows you to override any block defined inside the | ||
11 | included template, like when extending a template. | ||
12 | |||
13 | Think of an embedded template as a "micro layout skeleton". | ||
14 | |||
15 | .. code-block:: jinja | ||
16 | |||
17 | {% embed "teasers_skeleton.twig" %} | ||
18 | {# These blocks are defined in "teasers_skeleton.twig" #} | ||
19 | {# and we override them right here: #} | ||
20 | {% block left_teaser %} | ||
21 | Some content for the left teaser box | ||
22 | {% endblock %} | ||
23 | {% block right_teaser %} | ||
24 | Some content for the right teaser box | ||
25 | {% endblock %} | ||
26 | {% endembed %} | ||
27 | |||
28 | The ``embed`` tag takes the idea of template inheritance to the level of | ||
29 | content fragments. While template inheritance allows for "document skeletons", | ||
30 | which are filled with life by child templates, the ``embed`` tag allows you to | ||
31 | create "skeletons" for smaller units of content and re-use and fill them | ||
32 | anywhere you like. | ||
33 | |||
34 | Since the use case may not be obvious, let's look at a simplified example. | ||
35 | Imagine a base template shared by multiple HTML pages, defining a single block | ||
36 | named "content": | ||
37 | |||
38 | .. code-block:: text | ||
39 | |||
40 | ┌─── page layout ─────────────────────┐ | ||
41 | │ │ | ||
42 | │ ┌── block "content" ──┐ │ | ||
43 | │ │ │ │ | ||
44 | │ │ │ │ | ||
45 | │ │ (child template to │ │ | ||
46 | │ │ put content here) │ │ | ||
47 | │ │ │ │ | ||
48 | │ │ │ │ | ||
49 | │ └─────────────────────┘ │ | ||
50 | │ │ | ||
51 | └─────────────────────────────────────┘ | ||
52 | |||
53 | Some pages ("foo" and "bar") share the same content structure - | ||
54 | two vertically stacked boxes: | ||
55 | |||
56 | .. code-block:: text | ||
57 | |||
58 | ┌─── page layout ─────────────────────┐ | ||
59 | │ │ | ||
60 | │ ┌── block "content" ──┐ │ | ||
61 | │ │ ┌─ block "top" ───┐ │ │ | ||
62 | │ │ │ │ │ │ | ||
63 | │ │ └─────────────────┘ │ │ | ||
64 | │ │ ┌─ block "bottom" ┐ │ │ | ||
65 | │ │ │ │ │ │ | ||
66 | │ │ └─────────────────┘ │ │ | ||
67 | │ └─────────────────────┘ │ | ||
68 | │ │ | ||
69 | └─────────────────────────────────────┘ | ||
70 | |||
71 | While other pages ("boom" and "baz") share a different content structure - | ||
72 | two boxes side by side: | ||
73 | |||
74 | .. code-block:: text | ||
75 | |||
76 | ┌─── page layout ─────────────────────┐ | ||
77 | │ │ | ||
78 | │ ┌── block "content" ──┐ │ | ||
79 | │ │ │ │ | ||
80 | │ │ ┌ block ┐ ┌ block ┐ │ │ | ||
81 | │ │ │"left" │ │"right"│ │ │ | ||
82 | │ │ │ │ │ │ │ │ | ||
83 | │ │ │ │ │ │ │ │ | ||
84 | │ │ └───────┘ └───────┘ │ │ | ||
85 | │ └─────────────────────┘ │ | ||
86 | │ │ | ||
87 | └─────────────────────────────────────┘ | ||
88 | |||
89 | Without the ``embed`` tag, you have two ways to design your templates: | ||
90 | |||
91 | * Create two "intermediate" base templates that extend the master layout | ||
92 | template: one with vertically stacked boxes to be used by the "foo" and | ||
93 | "bar" pages and another one with side-by-side boxes for the "boom" and | ||
94 | "baz" pages. | ||
95 | |||
96 | * Embed the markup for the top/bottom and left/right boxes into each page | ||
97 | template directly. | ||
98 | |||
99 | These two solutions do not scale well because they each have a major drawback: | ||
100 | |||
101 | * The first solution may indeed work for this simplified example. But imagine | ||
102 | we add a sidebar, which may again contain different, recurring structures | ||
103 | of content. Now we would need to create intermediate base templates for | ||
104 | all occurring combinations of content structure and sidebar structure... | ||
105 | and so on. | ||
106 | |||
107 | * The second solution involves duplication of common code with all its negative | ||
108 | consequences: any change involves finding and editing all affected copies | ||
109 | of the structure, correctness has to be verified for each copy, copies may | ||
110 | go out of sync by careless modifications etc. | ||
111 | |||
112 | In such a situation, the ``embed`` tag comes in handy. The common layout | ||
113 | code can live in a single base template, and the two different content structures, | ||
114 | let's call them "micro layouts" go into separate templates which are embedded | ||
115 | as necessary: | ||
116 | |||
117 | Page template ``foo.twig``: | ||
118 | |||
119 | .. code-block:: jinja | ||
120 | |||
121 | {% extends "layout_skeleton.twig" %} | ||
122 | |||
123 | {% block content %} | ||
124 | {% embed "vertical_boxes_skeleton.twig" %} | ||
125 | {% block top %} | ||
126 | Some content for the top box | ||
127 | {% endblock %} | ||
128 | |||
129 | {% block bottom %} | ||
130 | Some content for the bottom box | ||
131 | {% endblock %} | ||
132 | {% endembed %} | ||
133 | {% endblock %} | ||
134 | |||
135 | And here is the code for ``vertical_boxes_skeleton.twig``: | ||
136 | |||
137 | .. code-block:: html+jinja | ||
138 | |||
139 | <div class="top_box"> | ||
140 | {% block top %} | ||
141 | Top box default content | ||
142 | {% endblock %} | ||
143 | </div> | ||
144 | |||
145 | <div class="bottom_box"> | ||
146 | {% block bottom %} | ||
147 | Bottom box default content | ||
148 | {% endblock %} | ||
149 | </div> | ||
150 | |||
151 | The goal of the ``vertical_boxes_skeleton.twig`` template being to factor | ||
152 | out the HTML markup for the boxes. | ||
153 | |||
154 | The ``embed`` tag takes the exact same arguments as the ``include`` tag: | ||
155 | |||
156 | .. code-block:: jinja | ||
157 | |||
158 | {% embed "base" with {'foo': 'bar'} %} | ||
159 | ... | ||
160 | {% endembed %} | ||
161 | |||
162 | {% embed "base" with {'foo': 'bar'} only %} | ||
163 | ... | ||
164 | {% endembed %} | ||
165 | |||
166 | {% embed "base" ignore missing %} | ||
167 | ... | ||
168 | {% endembed %} | ||
169 | |||
170 | .. warning:: | ||
171 | |||
172 | As embedded templates do not have "names", auto-escaping strategies based | ||
173 | on the template "filename" won't work as expected if you change the | ||
174 | context (for instance, if you embed a CSS/JavaScript template into an HTML | ||
175 | one). In that case, explicitly set the default auto-escaping strategy with | ||
176 | the ``autoescape`` tag. | ||
177 | |||
178 | .. seealso:: :doc:`include<../tags/include>` | ||
diff --git a/vendor/twig/twig/doc/tags/extends.rst b/vendor/twig/twig/doc/tags/extends.rst deleted file mode 100644 index f995a5dc..00000000 --- a/vendor/twig/twig/doc/tags/extends.rst +++ /dev/null | |||
@@ -1,268 +0,0 @@ | |||
1 | ``extends`` | ||
2 | =========== | ||
3 | |||
4 | The ``extends`` tag can be used to extend a template from another one. | ||
5 | |||
6 | .. note:: | ||
7 | |||
8 | Like PHP, Twig does not support multiple inheritance. So you can only have | ||
9 | one extends tag called per rendering. However, Twig supports horizontal | ||
10 | :doc:`reuse<use>`. | ||
11 | |||
12 | Let's define a base template, ``base.html``, which defines a simple HTML | ||
13 | skeleton document: | ||
14 | |||
15 | .. code-block:: html+jinja | ||
16 | |||
17 | <!DOCTYPE html> | ||
18 | <html> | ||
19 | <head> | ||
20 | {% block head %} | ||
21 | <link rel="stylesheet" href="style.css" /> | ||
22 | <title>{% block title %}{% endblock %} - My Webpage</title> | ||
23 | {% endblock %} | ||
24 | </head> | ||
25 | <body> | ||
26 | <div id="content">{% block content %}{% endblock %}</div> | ||
27 | <div id="footer"> | ||
28 | {% block footer %} | ||
29 | © Copyright 2011 by <a href="http://domain.invalid/">you</a>. | ||
30 | {% endblock %} | ||
31 | </div> | ||
32 | </body> | ||
33 | </html> | ||
34 | |||
35 | In this example, the :doc:`block<block>` tags define four blocks that child | ||
36 | templates can fill in. | ||
37 | |||
38 | All the ``block`` tag does is to tell the template engine that a child | ||
39 | template may override those portions of the template. | ||
40 | |||
41 | Child Template | ||
42 | -------------- | ||
43 | |||
44 | A child template might look like this: | ||
45 | |||
46 | .. code-block:: jinja | ||
47 | |||
48 | {% extends "base.html" %} | ||
49 | |||
50 | {% block title %}Index{% endblock %} | ||
51 | {% block head %} | ||
52 | {{ parent() }} | ||
53 | <style type="text/css"> | ||
54 | .important { color: #336699; } | ||
55 | </style> | ||
56 | {% endblock %} | ||
57 | {% block content %} | ||
58 | <h1>Index</h1> | ||
59 | <p class="important"> | ||
60 | Welcome on my awesome homepage. | ||
61 | </p> | ||
62 | {% endblock %} | ||
63 | |||
64 | The ``extends`` tag is the key here. It tells the template engine that this | ||
65 | template "extends" another template. When the template system evaluates this | ||
66 | template, first it locates the parent. The extends tag should be the first tag | ||
67 | in the template. | ||
68 | |||
69 | Note that since the child template doesn't define the ``footer`` block, the | ||
70 | value from the parent template is used instead. | ||
71 | |||
72 | You can't define multiple ``block`` tags with the same name in the same | ||
73 | template. This limitation exists because a block tag works in "both" | ||
74 | directions. That is, a block tag doesn't just provide a hole to fill - it also | ||
75 | defines the content that fills the hole in the *parent*. If there were two | ||
76 | similarly-named ``block`` tags in a template, that template's parent wouldn't | ||
77 | know which one of the blocks' content to use. | ||
78 | |||
79 | If you want to print a block multiple times you can however use the | ||
80 | ``block`` function: | ||
81 | |||
82 | .. code-block:: jinja | ||
83 | |||
84 | <title>{% block title %}{% endblock %}</title> | ||
85 | <h1>{{ block('title') }}</h1> | ||
86 | {% block body %}{% endblock %} | ||
87 | |||
88 | Parent Blocks | ||
89 | ------------- | ||
90 | |||
91 | It's possible to render the contents of the parent block by using the | ||
92 | :doc:`parent<../functions/parent>` function. This gives back the results of | ||
93 | the parent block: | ||
94 | |||
95 | .. code-block:: jinja | ||
96 | |||
97 | {% block sidebar %} | ||
98 | <h3>Table Of Contents</h3> | ||
99 | ... | ||
100 | {{ parent() }} | ||
101 | {% endblock %} | ||
102 | |||
103 | Named Block End-Tags | ||
104 | -------------------- | ||
105 | |||
106 | Twig allows you to put the name of the block after the end tag for better | ||
107 | readability: | ||
108 | |||
109 | .. code-block:: jinja | ||
110 | |||
111 | {% block sidebar %} | ||
112 | {% block inner_sidebar %} | ||
113 | ... | ||
114 | {% endblock inner_sidebar %} | ||
115 | {% endblock sidebar %} | ||
116 | |||
117 | Of course, the name after the ``endblock`` word must match the block name. | ||
118 | |||
119 | Block Nesting and Scope | ||
120 | ----------------------- | ||
121 | |||
122 | Blocks can be nested for more complex layouts. Per default, blocks have access | ||
123 | to variables from outer scopes: | ||
124 | |||
125 | .. code-block:: jinja | ||
126 | |||
127 | {% for item in seq %} | ||
128 | <li>{% block loop_item %}{{ item }}{% endblock %}</li> | ||
129 | {% endfor %} | ||
130 | |||
131 | Block Shortcuts | ||
132 | --------------- | ||
133 | |||
134 | For blocks with few content, it's possible to use a shortcut syntax. The | ||
135 | following constructs do the same: | ||
136 | |||
137 | .. code-block:: jinja | ||
138 | |||
139 | {% block title %} | ||
140 | {{ page_title|title }} | ||
141 | {% endblock %} | ||
142 | |||
143 | .. code-block:: jinja | ||
144 | |||
145 | {% block title page_title|title %} | ||
146 | |||
147 | Dynamic Inheritance | ||
148 | ------------------- | ||
149 | |||
150 | Twig supports dynamic inheritance by using a variable as the base template: | ||
151 | |||
152 | .. code-block:: jinja | ||
153 | |||
154 | {% extends some_var %} | ||
155 | |||
156 | If the variable evaluates to a ``Twig_Template`` object, Twig will use it as | ||
157 | the parent template:: | ||
158 | |||
159 | // {% extends layout %} | ||
160 | |||
161 | $layout = $twig->loadTemplate('some_layout_template.twig'); | ||
162 | |||
163 | $twig->display('template.twig', array('layout' => $layout)); | ||
164 | |||
165 | .. versionadded:: 1.2 | ||
166 | The possibility to pass an array of templates has been added in Twig 1.2. | ||
167 | |||
168 | You can also provide a list of templates that are checked for existence. The | ||
169 | first template that exists will be used as a parent: | ||
170 | |||
171 | .. code-block:: jinja | ||
172 | |||
173 | {% extends ['layout.html', 'base_layout.html'] %} | ||
174 | |||
175 | Conditional Inheritance | ||
176 | ----------------------- | ||
177 | |||
178 | As the template name for the parent can be any valid Twig expression, it's | ||
179 | possible to make the inheritance mechanism conditional: | ||
180 | |||
181 | .. code-block:: jinja | ||
182 | |||
183 | {% extends standalone ? "minimum.html" : "base.html" %} | ||
184 | |||
185 | In this example, the template will extend the "minimum.html" layout template | ||
186 | if the ``standalone`` variable evaluates to ``true``, and "base.html" | ||
187 | otherwise. | ||
188 | |||
189 | How blocks work? | ||
190 | ---------------- | ||
191 | |||
192 | A block provides a way to change how a certain part of a template is rendered | ||
193 | but it does not interfere in any way with the logic around it. | ||
194 | |||
195 | Let's take the following example to illustrate how a block work and more | ||
196 | importantly, how it does not work: | ||
197 | |||
198 | .. code-block:: jinja | ||
199 | |||
200 | {# base.twig #} | ||
201 | |||
202 | {% for post in posts %} | ||
203 | {% block post %} | ||
204 | <h1>{{ post.title }}</h1> | ||
205 | <p>{{ post.body }}</p> | ||
206 | {% endblock %} | ||
207 | {% endfor %} | ||
208 | |||
209 | If you render this template, the result would be exactly the same with or | ||
210 | without the ``block`` tag. The ``block`` inside the ``for`` loop is just a way | ||
211 | to make it overridable by a child template: | ||
212 | |||
213 | .. code-block:: jinja | ||
214 | |||
215 | {# child.twig #} | ||
216 | |||
217 | {% extends "base.twig" %} | ||
218 | |||
219 | {% block post %} | ||
220 | <article> | ||
221 | <header>{{ post.title }}</header> | ||
222 | <section>{{ post.text }}</section> | ||
223 | </article> | ||
224 | {% endblock %} | ||
225 | |||
226 | Now, when rendering the child template, the loop is going to use the block | ||
227 | defined in the child template instead of the one defined in the base one; the | ||
228 | executed template is then equivalent to the following one: | ||
229 | |||
230 | .. code-block:: jinja | ||
231 | |||
232 | {% for post in posts %} | ||
233 | <article> | ||
234 | <header>{{ post.title }}</header> | ||
235 | <section>{{ post.text }}</section> | ||
236 | </article> | ||
237 | {% endfor %} | ||
238 | |||
239 | Let's take another example: a block included within an ``if`` statement: | ||
240 | |||
241 | .. code-block:: jinja | ||
242 | |||
243 | {% if posts is empty %} | ||
244 | {% block head %} | ||
245 | {{ parent() }} | ||
246 | |||
247 | <meta name="robots" content="noindex, follow"> | ||
248 | {% endblock head %} | ||
249 | {% endif %} | ||
250 | |||
251 | Contrary to what you might think, this template does not define a block | ||
252 | conditionally; it just makes overridable by a child template the output of | ||
253 | what will be rendered when the condition is ``true``. | ||
254 | |||
255 | If you want the output to be displayed conditionally, use the following | ||
256 | instead: | ||
257 | |||
258 | .. code-block:: jinja | ||
259 | |||
260 | {% block head %} | ||
261 | {{ parent() }} | ||
262 | |||
263 | {% if posts is empty %} | ||
264 | <meta name="robots" content="noindex, follow"> | ||
265 | {% endif %} | ||
266 | {% endblock head %} | ||
267 | |||
268 | .. seealso:: :doc:`block<../functions/block>`, :doc:`block<../tags/block>`, :doc:`parent<../functions/parent>`, :doc:`use<../tags/use>` | ||
diff --git a/vendor/twig/twig/doc/tags/filter.rst b/vendor/twig/twig/doc/tags/filter.rst deleted file mode 100644 index 82ca5c62..00000000 --- a/vendor/twig/twig/doc/tags/filter.rst +++ /dev/null | |||
@@ -1,21 +0,0 @@ | |||
1 | ``filter`` | ||
2 | ========== | ||
3 | |||
4 | Filter sections allow you to apply regular Twig filters on a block of template | ||
5 | data. Just wrap the code in the special ``filter`` section: | ||
6 | |||
7 | .. code-block:: jinja | ||
8 | |||
9 | {% filter upper %} | ||
10 | This text becomes uppercase | ||
11 | {% endfilter %} | ||
12 | |||
13 | You can also chain filters: | ||
14 | |||
15 | .. code-block:: jinja | ||
16 | |||
17 | {% filter lower|escape %} | ||
18 | <strong>SOME TEXT</strong> | ||
19 | {% endfilter %} | ||
20 | |||
21 | {# outputs "<strong>some text</strong>" #} | ||
diff --git a/vendor/twig/twig/doc/tags/flush.rst b/vendor/twig/twig/doc/tags/flush.rst deleted file mode 100644 index 55ef593a..00000000 --- a/vendor/twig/twig/doc/tags/flush.rst +++ /dev/null | |||
@@ -1,17 +0,0 @@ | |||
1 | ``flush`` | ||
2 | ========= | ||
3 | |||
4 | .. versionadded:: 1.5 | ||
5 | The flush tag was added in Twig 1.5. | ||
6 | |||
7 | The ``flush`` tag tells Twig to flush the output buffer: | ||
8 | |||
9 | .. code-block:: jinja | ||
10 | |||
11 | {% flush %} | ||
12 | |||
13 | .. note:: | ||
14 | |||
15 | Internally, Twig uses the PHP `flush`_ function. | ||
16 | |||
17 | .. _`flush`: http://php.net/flush | ||
diff --git a/vendor/twig/twig/doc/tags/for.rst b/vendor/twig/twig/doc/tags/for.rst deleted file mode 100644 index 0673b551..00000000 --- a/vendor/twig/twig/doc/tags/for.rst +++ /dev/null | |||
@@ -1,172 +0,0 @@ | |||
1 | ``for`` | ||
2 | ======= | ||
3 | |||
4 | Loop over each item in a sequence. For example, to display a list of users | ||
5 | provided in a variable called ``users``: | ||
6 | |||
7 | .. code-block:: jinja | ||
8 | |||
9 | <h1>Members</h1> | ||
10 | <ul> | ||
11 | {% for user in users %} | ||
12 | <li>{{ user.username|e }}</li> | ||
13 | {% endfor %} | ||
14 | </ul> | ||
15 | |||
16 | .. note:: | ||
17 | |||
18 | A sequence can be either an array or an object implementing the | ||
19 | ``Traversable`` interface. | ||
20 | |||
21 | If you do need to iterate over a sequence of numbers, you can use the ``..`` | ||
22 | operator: | ||
23 | |||
24 | .. code-block:: jinja | ||
25 | |||
26 | {% for i in 0..10 %} | ||
27 | * {{ i }} | ||
28 | {% endfor %} | ||
29 | |||
30 | The above snippet of code would print all numbers from 0 to 10. | ||
31 | |||
32 | It can be also useful with letters: | ||
33 | |||
34 | .. code-block:: jinja | ||
35 | |||
36 | {% for letter in 'a'..'z' %} | ||
37 | * {{ letter }} | ||
38 | {% endfor %} | ||
39 | |||
40 | The ``..`` operator can take any expression at both sides: | ||
41 | |||
42 | .. code-block:: jinja | ||
43 | |||
44 | {% for letter in 'a'|upper..'z'|upper %} | ||
45 | * {{ letter }} | ||
46 | {% endfor %} | ||
47 | |||
48 | .. tip: | ||
49 | |||
50 | If you need a step different from 1, you can use the ``range`` function | ||
51 | instead. | ||
52 | |||
53 | The `loop` variable | ||
54 | ------------------- | ||
55 | |||
56 | Inside of a ``for`` loop block you can access some special variables: | ||
57 | |||
58 | ===================== ============================================================= | ||
59 | Variable Description | ||
60 | ===================== ============================================================= | ||
61 | ``loop.index`` The current iteration of the loop. (1 indexed) | ||
62 | ``loop.index0`` The current iteration of the loop. (0 indexed) | ||
63 | ``loop.revindex`` The number of iterations from the end of the loop (1 indexed) | ||
64 | ``loop.revindex0`` The number of iterations from the end of the loop (0 indexed) | ||
65 | ``loop.first`` True if first iteration | ||
66 | ``loop.last`` True if last iteration | ||
67 | ``loop.length`` The number of items in the sequence | ||
68 | ``loop.parent`` The parent context | ||
69 | ===================== ============================================================= | ||
70 | |||
71 | .. code-block:: jinja | ||
72 | |||
73 | {% for user in users %} | ||
74 | {{ loop.index }} - {{ user.username }} | ||
75 | {% endfor %} | ||
76 | |||
77 | .. note:: | ||
78 | |||
79 | The ``loop.length``, ``loop.revindex``, ``loop.revindex0``, and | ||
80 | ``loop.last`` variables are only available for PHP arrays, or objects that | ||
81 | implement the ``Countable`` interface. They are also not available when | ||
82 | looping with a condition. | ||
83 | |||
84 | .. versionadded:: 1.2 | ||
85 | The ``if`` modifier support has been added in Twig 1.2. | ||
86 | |||
87 | Adding a condition | ||
88 | ------------------ | ||
89 | |||
90 | Unlike in PHP, it's not possible to ``break`` or ``continue`` in a loop. You | ||
91 | can however filter the sequence during iteration which allows you to skip | ||
92 | items. The following example skips all the users which are not active: | ||
93 | |||
94 | .. code-block:: jinja | ||
95 | |||
96 | <ul> | ||
97 | {% for user in users if user.active %} | ||
98 | <li>{{ user.username|e }}</li> | ||
99 | {% endfor %} | ||
100 | </ul> | ||
101 | |||
102 | The advantage is that the special loop variable will count correctly thus not | ||
103 | counting the users not iterated over. Keep in mind that properties like | ||
104 | ``loop.last`` will not be defined when using loop conditions. | ||
105 | |||
106 | .. note:: | ||
107 | |||
108 | Using the ``loop`` variable within the condition is not recommended as it | ||
109 | will probably not be doing what you expect it to. For instance, adding a | ||
110 | condition like ``loop.index > 4`` won't work as the index is only | ||
111 | incremented when the condition is true (so the condition will never | ||
112 | match). | ||
113 | |||
114 | The `else` Clause | ||
115 | ----------------- | ||
116 | |||
117 | If no iteration took place because the sequence was empty, you can render a | ||
118 | replacement block by using ``else``: | ||
119 | |||
120 | .. code-block:: jinja | ||
121 | |||
122 | <ul> | ||
123 | {% for user in users %} | ||
124 | <li>{{ user.username|e }}</li> | ||
125 | {% else %} | ||
126 | <li><em>no user found</em></li> | ||
127 | {% endfor %} | ||
128 | </ul> | ||
129 | |||
130 | Iterating over Keys | ||
131 | ------------------- | ||
132 | |||
133 | By default, a loop iterates over the values of the sequence. You can iterate | ||
134 | on keys by using the ``keys`` filter: | ||
135 | |||
136 | .. code-block:: jinja | ||
137 | |||
138 | <h1>Members</h1> | ||
139 | <ul> | ||
140 | {% for key in users|keys %} | ||
141 | <li>{{ key }}</li> | ||
142 | {% endfor %} | ||
143 | </ul> | ||
144 | |||
145 | Iterating over Keys and Values | ||
146 | ------------------------------ | ||
147 | |||
148 | You can also access both keys and values: | ||
149 | |||
150 | .. code-block:: jinja | ||
151 | |||
152 | <h1>Members</h1> | ||
153 | <ul> | ||
154 | {% for key, user in users %} | ||
155 | <li>{{ key }}: {{ user.username|e }}</li> | ||
156 | {% endfor %} | ||
157 | </ul> | ||
158 | |||
159 | Iterating over a Subset | ||
160 | ----------------------- | ||
161 | |||
162 | You might want to iterate over a subset of values. This can be achieved using | ||
163 | the :doc:`slice <../filters/slice>` filter: | ||
164 | |||
165 | .. code-block:: jinja | ||
166 | |||
167 | <h1>Top Ten Members</h1> | ||
168 | <ul> | ||
169 | {% for user in users|slice(0, 10) %} | ||
170 | <li>{{ user.username|e }}</li> | ||
171 | {% endfor %} | ||
172 | </ul> | ||
diff --git a/vendor/twig/twig/doc/tags/from.rst b/vendor/twig/twig/doc/tags/from.rst deleted file mode 100644 index 5337a235..00000000 --- a/vendor/twig/twig/doc/tags/from.rst +++ /dev/null | |||
@@ -1,8 +0,0 @@ | |||
1 | ``from`` | ||
2 | ======== | ||
3 | |||
4 | The ``from`` tags import :doc:`macro<../tags/macro>` names into the current | ||
5 | namespace. The tag is documented in detail in the documentation for the | ||
6 | :doc:`import<../tags/import>` tag. | ||
7 | |||
8 | .. seealso:: :doc:`macro<../tags/macro>`, :doc:`import<../tags/import>` | ||
diff --git a/vendor/twig/twig/doc/tags/if.rst b/vendor/twig/twig/doc/tags/if.rst deleted file mode 100644 index d7a1451c..00000000 --- a/vendor/twig/twig/doc/tags/if.rst +++ /dev/null | |||
@@ -1,43 +0,0 @@ | |||
1 | ``if`` | ||
2 | ====== | ||
3 | |||
4 | The ``if`` statement in Twig is comparable with the if statements of PHP. | ||
5 | |||
6 | In the simplest form you can use it to test if an expression evaluates to | ||
7 | ``true``: | ||
8 | |||
9 | .. code-block:: jinja | ||
10 | |||
11 | {% if online == false %} | ||
12 | <p>Our website is in maintenance mode. Please, come back later.</p> | ||
13 | {% endif %} | ||
14 | |||
15 | You can also test if an array is not empty: | ||
16 | |||
17 | .. code-block:: jinja | ||
18 | |||
19 | {% if users %} | ||
20 | <ul> | ||
21 | {% for user in users %} | ||
22 | <li>{{ user.username|e }}</li> | ||
23 | {% endfor %} | ||
24 | </ul> | ||
25 | {% endif %} | ||
26 | |||
27 | .. note:: | ||
28 | |||
29 | If you want to test if the variable is defined, use ``if users is | ||
30 | defined`` instead. | ||
31 | |||
32 | For multiple branches ``elseif`` and ``else`` can be used like in PHP. You can use | ||
33 | more complex ``expressions`` there too: | ||
34 | |||
35 | .. code-block:: jinja | ||
36 | |||
37 | {% if kenny.sick %} | ||
38 | Kenny is sick. | ||
39 | {% elseif kenny.dead %} | ||
40 | You killed Kenny! You bastard!!! | ||
41 | {% else %} | ||
42 | Kenny looks okay --- so far | ||
43 | {% endif %} | ||
diff --git a/vendor/twig/twig/doc/tags/import.rst b/vendor/twig/twig/doc/tags/import.rst deleted file mode 100644 index f6bf718e..00000000 --- a/vendor/twig/twig/doc/tags/import.rst +++ /dev/null | |||
@@ -1,57 +0,0 @@ | |||
1 | ``import`` | ||
2 | ========== | ||
3 | |||
4 | Twig supports putting often used code into :doc:`macros<../tags/macro>`. These | ||
5 | macros can go into different templates and get imported from there. | ||
6 | |||
7 | There are two ways to import templates. You can import the complete template | ||
8 | into a variable or request specific macros from it. | ||
9 | |||
10 | Imagine we have a helper module that renders forms (called ``forms.html``): | ||
11 | |||
12 | .. code-block:: jinja | ||
13 | |||
14 | {% macro input(name, value, type, size) %} | ||
15 | <input type="{{ type|default('text') }}" name="{{ name }}" value="{{ value|e }}" size="{{ size|default(20) }}" /> | ||
16 | {% endmacro %} | ||
17 | |||
18 | {% macro textarea(name, value, rows) %} | ||
19 | <textarea name="{{ name }}" rows="{{ rows|default(10) }}" cols="{{ cols|default(40) }}">{{ value|e }}</textarea> | ||
20 | {% endmacro %} | ||
21 | |||
22 | The easiest and most flexible is importing the whole module into a variable. | ||
23 | That way you can access the attributes: | ||
24 | |||
25 | .. code-block:: jinja | ||
26 | |||
27 | {% import 'forms.html' as forms %} | ||
28 | |||
29 | <dl> | ||
30 | <dt>Username</dt> | ||
31 | <dd>{{ forms.input('username') }}</dd> | ||
32 | <dt>Password</dt> | ||
33 | <dd>{{ forms.input('password', null, 'password') }}</dd> | ||
34 | </dl> | ||
35 | <p>{{ forms.textarea('comment') }}</p> | ||
36 | |||
37 | Alternatively you can import names from the template into the current | ||
38 | namespace: | ||
39 | |||
40 | .. code-block:: jinja | ||
41 | |||
42 | {% from 'forms.html' import input as input_field, textarea %} | ||
43 | |||
44 | <dl> | ||
45 | <dt>Username</dt> | ||
46 | <dd>{{ input_field('username') }}</dd> | ||
47 | <dt>Password</dt> | ||
48 | <dd>{{ input_field('password', '', 'password') }}</dd> | ||
49 | </dl> | ||
50 | <p>{{ textarea('comment') }}</p> | ||
51 | |||
52 | .. tip:: | ||
53 | |||
54 | To import macros from the current file, use the special ``_self`` variable | ||
55 | for the source. | ||
56 | |||
57 | .. seealso:: :doc:`macro<../tags/macro>`, :doc:`from<../tags/from>` | ||
diff --git a/vendor/twig/twig/doc/tags/include.rst b/vendor/twig/twig/doc/tags/include.rst deleted file mode 100644 index 10b262de..00000000 --- a/vendor/twig/twig/doc/tags/include.rst +++ /dev/null | |||
@@ -1,86 +0,0 @@ | |||
1 | ``include`` | ||
2 | =========== | ||
3 | |||
4 | The ``include`` statement includes a template and return the rendered content | ||
5 | of that file into the current namespace: | ||
6 | |||
7 | .. code-block:: jinja | ||
8 | |||
9 | {% include 'header.html' %} | ||
10 | Body | ||
11 | {% include 'footer.html' %} | ||
12 | |||
13 | Included templates have access to the variables of the active context. | ||
14 | |||
15 | If you are using the filesystem loader, the templates are looked for in the | ||
16 | paths defined by it. | ||
17 | |||
18 | You can add additional variables by passing them after the ``with`` keyword: | ||
19 | |||
20 | .. code-block:: jinja | ||
21 | |||
22 | {# template.html will have access to the variables from the current context and the additional ones provided #} | ||
23 | {% include 'template.html' with {'foo': 'bar'} %} | ||
24 | |||
25 | {% set vars = {'foo': 'bar'} %} | ||
26 | {% include 'template.html' with vars %} | ||
27 | |||
28 | You can disable access to the context by appending the ``only`` keyword: | ||
29 | |||
30 | .. code-block:: jinja | ||
31 | |||
32 | {# only the foo variable will be accessible #} | ||
33 | {% include 'template.html' with {'foo': 'bar'} only %} | ||
34 | |||
35 | .. code-block:: jinja | ||
36 | |||
37 | {# no variables will be accessible #} | ||
38 | {% include 'template.html' only %} | ||
39 | |||
40 | .. tip:: | ||
41 | |||
42 | When including a template created by an end user, you should consider | ||
43 | sandboxing it. More information in the :doc:`Twig for Developers<../api>` | ||
44 | chapter and in the :doc:`sandbox<../tags/sandbox>` tag documentation. | ||
45 | |||
46 | The template name can be any valid Twig expression: | ||
47 | |||
48 | .. code-block:: jinja | ||
49 | |||
50 | {% include some_var %} | ||
51 | {% include ajax ? 'ajax.html' : 'not_ajax.html' %} | ||
52 | |||
53 | And if the expression evaluates to a ``Twig_Template`` object, Twig will use it | ||
54 | directly:: | ||
55 | |||
56 | // {% include template %} | ||
57 | |||
58 | $template = $twig->loadTemplate('some_template.twig'); | ||
59 | |||
60 | $twig->loadTemplate('template.twig')->display(array('template' => $template)); | ||
61 | |||
62 | .. versionadded:: 1.2 | ||
63 | The ``ignore missing`` feature has been added in Twig 1.2. | ||
64 | |||
65 | You can mark an include with ``ignore missing`` in which case Twig will ignore | ||
66 | the statement if the template to be included does not exist. It has to be | ||
67 | placed just after the template name. Here some valid examples: | ||
68 | |||
69 | .. code-block:: jinja | ||
70 | |||
71 | {% include 'sidebar.html' ignore missing %} | ||
72 | {% include 'sidebar.html' ignore missing with {'foo': 'bar'} %} | ||
73 | {% include 'sidebar.html' ignore missing only %} | ||
74 | |||
75 | .. versionadded:: 1.2 | ||
76 | The possibility to pass an array of templates has been added in Twig 1.2. | ||
77 | |||
78 | You can also provide a list of templates that are checked for existence before | ||
79 | inclusion. The first template that exists will be included: | ||
80 | |||
81 | .. code-block:: jinja | ||
82 | |||
83 | {% include ['page_detailed.html', 'page.html'] %} | ||
84 | |||
85 | If ``ignore missing`` is given, it will fall back to rendering nothing if none | ||
86 | of the templates exist, otherwise it will throw an exception. | ||
diff --git a/vendor/twig/twig/doc/tags/index.rst b/vendor/twig/twig/doc/tags/index.rst deleted file mode 100644 index 64e88644..00000000 --- a/vendor/twig/twig/doc/tags/index.rst +++ /dev/null | |||
@@ -1,24 +0,0 @@ | |||
1 | Tags | ||
2 | ==== | ||
3 | |||
4 | .. toctree:: | ||
5 | :maxdepth: 1 | ||
6 | |||
7 | autoescape | ||
8 | block | ||
9 | filter | ||
10 | do | ||
11 | embed | ||
12 | extends | ||
13 | flush | ||
14 | for | ||
15 | from | ||
16 | if | ||
17 | import | ||
18 | include | ||
19 | macro | ||
20 | sandbox | ||
21 | set | ||
22 | spaceless | ||
23 | use | ||
24 | verbatim | ||
diff --git a/vendor/twig/twig/doc/tags/macro.rst b/vendor/twig/twig/doc/tags/macro.rst deleted file mode 100644 index 11c115a0..00000000 --- a/vendor/twig/twig/doc/tags/macro.rst +++ /dev/null | |||
@@ -1,83 +0,0 @@ | |||
1 | ``macro`` | ||
2 | ========= | ||
3 | |||
4 | Macros are comparable with functions in regular programming languages. They | ||
5 | are useful to put often used HTML idioms into reusable elements to not repeat | ||
6 | yourself. | ||
7 | |||
8 | Here is a small example of a macro that renders a form element: | ||
9 | |||
10 | .. code-block:: jinja | ||
11 | |||
12 | {% macro input(name, value, type, size) %} | ||
13 | <input type="{{ type|default('text') }}" name="{{ name }}" value="{{ value|e }}" size="{{ size|default(20) }}" /> | ||
14 | {% endmacro %} | ||
15 | |||
16 | Macros differs from native PHP functions in a few ways: | ||
17 | |||
18 | * Default argument values are defined by using the ``default`` filter in the | ||
19 | macro body; | ||
20 | |||
21 | * Arguments of a macro are always optional. | ||
22 | |||
23 | But as with PHP functions, macros don't have access to the current template | ||
24 | variables. | ||
25 | |||
26 | .. tip:: | ||
27 | |||
28 | You can pass the whole context as an argument by using the special | ||
29 | ``_context`` variable. | ||
30 | |||
31 | Macros can be defined in any template, and need to be "imported" before being | ||
32 | used (see the documentation for the :doc:`import<../tags/import>` tag for more | ||
33 | information): | ||
34 | |||
35 | .. code-block:: jinja | ||
36 | |||
37 | {% import "forms.html" as forms %} | ||
38 | |||
39 | The above ``import`` call imports the "forms.html" file (which can contain only | ||
40 | macros, or a template and some macros), and import the functions as items of | ||
41 | the ``forms`` variable. | ||
42 | |||
43 | The macro can then be called at will: | ||
44 | |||
45 | .. code-block:: jinja | ||
46 | |||
47 | <p>{{ forms.input('username') }}</p> | ||
48 | <p>{{ forms.input('password', null, 'password') }}</p> | ||
49 | |||
50 | If macros are defined and used in the same template, you can use the | ||
51 | special ``_self`` variable to import them: | ||
52 | |||
53 | .. code-block:: jinja | ||
54 | |||
55 | {% import _self as forms %} | ||
56 | |||
57 | <p>{{ forms.input('username') }}</p> | ||
58 | |||
59 | .. warning:: | ||
60 | |||
61 | When you define a macro in the template where you are going to use it, you | ||
62 | might be tempted to call the macro directly via ``_self.input()`` instead | ||
63 | of importing it; even if seems to work, this is just a side-effect of the | ||
64 | current implementation and it won't work anymore in Twig 2.x. | ||
65 | |||
66 | When you want to use a macro in another macro from the same file, you need to | ||
67 | import it locally: | ||
68 | |||
69 | .. code-block:: jinja | ||
70 | |||
71 | {% macro input(name, value, type, size) %} | ||
72 | <input type="{{ type|default('text') }}" name="{{ name }}" value="{{ value|e }}" size="{{ size|default(20) }}" /> | ||
73 | {% endmacro %} | ||
74 | |||
75 | {% macro wrapped_input(name, value, type, size) %} | ||
76 | {% import _self as forms %} | ||
77 | |||
78 | <div class="field"> | ||
79 | {{ forms.input(name, value, type, size) }} | ||
80 | </div> | ||
81 | {% endmacro %} | ||
82 | |||
83 | .. seealso:: :doc:`from<../tags/from>`, :doc:`import<../tags/import>` | ||
diff --git a/vendor/twig/twig/doc/tags/sandbox.rst b/vendor/twig/twig/doc/tags/sandbox.rst deleted file mode 100644 index e186726c..00000000 --- a/vendor/twig/twig/doc/tags/sandbox.rst +++ /dev/null | |||
@@ -1,30 +0,0 @@ | |||
1 | ``sandbox`` | ||
2 | =========== | ||
3 | |||
4 | The ``sandbox`` tag can be used to enable the sandboxing mode for an included | ||
5 | template, when sandboxing is not enabled globally for the Twig environment: | ||
6 | |||
7 | .. code-block:: jinja | ||
8 | |||
9 | {% sandbox %} | ||
10 | {% include 'user.html' %} | ||
11 | {% endsandbox %} | ||
12 | |||
13 | .. warning:: | ||
14 | |||
15 | The ``sandbox`` tag is only available when the sandbox extension is | ||
16 | enabled (see the :doc:`Twig for Developers<../api>` chapter). | ||
17 | |||
18 | .. note:: | ||
19 | |||
20 | The ``sandbox`` tag can only be used to sandbox an include tag and it | ||
21 | cannot be used to sandbox a section of a template. The following example | ||
22 | won't work: | ||
23 | |||
24 | .. code-block:: jinja | ||
25 | |||
26 | {% sandbox %} | ||
27 | {% for i in 1..2 %} | ||
28 | {{ i }} | ||
29 | {% endfor %} | ||
30 | {% endsandbox %} | ||
diff --git a/vendor/twig/twig/doc/tags/set.rst b/vendor/twig/twig/doc/tags/set.rst deleted file mode 100644 index 3eba239a..00000000 --- a/vendor/twig/twig/doc/tags/set.rst +++ /dev/null | |||
@@ -1,78 +0,0 @@ | |||
1 | ``set`` | ||
2 | ======= | ||
3 | |||
4 | Inside code blocks you can also assign values to variables. Assignments use | ||
5 | the ``set`` tag and can have multiple targets. | ||
6 | |||
7 | Here is how you can assign the ``bar`` value to the ``foo`` variable: | ||
8 | |||
9 | .. code-block:: jinja | ||
10 | |||
11 | {% set foo = 'bar' %} | ||
12 | |||
13 | After the ``set`` call, the ``foo`` variable is available in the template like | ||
14 | any other ones: | ||
15 | |||
16 | .. code-block:: jinja | ||
17 | |||
18 | {# displays bar #} | ||
19 | {{ foo }} | ||
20 | |||
21 | The assigned value can be any valid :ref:`Twig expressions | ||
22 | <twig-expressions>`: | ||
23 | |||
24 | .. code-block:: jinja | ||
25 | |||
26 | {% set foo = [1, 2] %} | ||
27 | {% set foo = {'foo': 'bar'} %} | ||
28 | {% set foo = 'foo' ~ 'bar' %} | ||
29 | |||
30 | Several variables can be assigned in one block: | ||
31 | |||
32 | .. code-block:: jinja | ||
33 | |||
34 | {% set foo, bar = 'foo', 'bar' %} | ||
35 | |||
36 | {# is equivalent to #} | ||
37 | |||
38 | {% set foo = 'foo' %} | ||
39 | {% set bar = 'bar' %} | ||
40 | |||
41 | The ``set`` tag can also be used to 'capture' chunks of text: | ||
42 | |||
43 | .. code-block:: jinja | ||
44 | |||
45 | {% set foo %} | ||
46 | <div id="pagination"> | ||
47 | ... | ||
48 | </div> | ||
49 | {% endset %} | ||
50 | |||
51 | .. caution:: | ||
52 | |||
53 | If you enable automatic output escaping, Twig will only consider the | ||
54 | content to be safe when capturing chunks of text. | ||
55 | |||
56 | .. note:: | ||
57 | |||
58 | Note that loops are scoped in Twig; therefore a variable declared inside a | ||
59 | ``for`` loop is not accessible outside the loop itself: | ||
60 | |||
61 | .. code-block:: jinja | ||
62 | |||
63 | {% for item in list %} | ||
64 | {% set foo = item %} | ||
65 | {% endfor %} | ||
66 | |||
67 | {# foo is NOT available #} | ||
68 | |||
69 | If you want to access the variable, just declare it before the loop: | ||
70 | |||
71 | .. code-block:: jinja | ||
72 | |||
73 | {% set foo = "" %} | ||
74 | {% for item in list %} | ||
75 | {% set foo = item %} | ||
76 | {% endfor %} | ||
77 | |||
78 | {# foo is available #} | ||
diff --git a/vendor/twig/twig/doc/tags/spaceless.rst b/vendor/twig/twig/doc/tags/spaceless.rst deleted file mode 100644 index 12e77b25..00000000 --- a/vendor/twig/twig/doc/tags/spaceless.rst +++ /dev/null | |||
@@ -1,37 +0,0 @@ | |||
1 | ``spaceless`` | ||
2 | ============= | ||
3 | |||
4 | Use the ``spaceless`` tag to remove whitespace *between HTML tags*, not | ||
5 | whitespace within HTML tags or whitespace in plain text: | ||
6 | |||
7 | .. code-block:: jinja | ||
8 | |||
9 | {% spaceless %} | ||
10 | <div> | ||
11 | <strong>foo</strong> | ||
12 | </div> | ||
13 | {% endspaceless %} | ||
14 | |||
15 | {# output will be <div><strong>foo</strong></div> #} | ||
16 | |||
17 | This tag is not meant to "optimize" the size of the generated HTML content but | ||
18 | merely to avoid extra whitespace between HTML tags to avoid browser rendering | ||
19 | quirks under some circumstances. | ||
20 | |||
21 | .. tip:: | ||
22 | |||
23 | If you want to optimize the size of the generated HTML content, gzip | ||
24 | compress the output instead. | ||
25 | |||
26 | .. tip:: | ||
27 | |||
28 | If you want to create a tag that actually removes all extra whitespace in | ||
29 | an HTML string, be warned that this is not as easy as it seems to be | ||
30 | (think of ``textarea`` or ``pre`` tags for instance). Using a third-party | ||
31 | library like Tidy is probably a better idea. | ||
32 | |||
33 | .. tip:: | ||
34 | |||
35 | For more information on whitespace control, read the | ||
36 | :doc:`dedicated<../templates>` section of the documentation and learn how | ||
37 | you can also use the whitespace control modifier on your tags. | ||
diff --git a/vendor/twig/twig/doc/tags/use.rst b/vendor/twig/twig/doc/tags/use.rst deleted file mode 100644 index 085f9161..00000000 --- a/vendor/twig/twig/doc/tags/use.rst +++ /dev/null | |||
@@ -1,123 +0,0 @@ | |||
1 | ``use`` | ||
2 | ======= | ||
3 | |||
4 | .. versionadded:: 1.1 | ||
5 | Horizontal reuse was added in Twig 1.1. | ||
6 | |||
7 | .. note:: | ||
8 | |||
9 | Horizontal reuse is an advanced Twig feature that is hardly ever needed in | ||
10 | regular templates. It is mainly used by projects that need to make | ||
11 | template blocks reusable without using inheritance. | ||
12 | |||
13 | Template inheritance is one of the most powerful Twig's feature but it is | ||
14 | limited to single inheritance; a template can only extend one other template. | ||
15 | This limitation makes template inheritance simple to understand and easy to | ||
16 | debug: | ||
17 | |||
18 | .. code-block:: jinja | ||
19 | |||
20 | {% extends "base.html" %} | ||
21 | |||
22 | {% block title %}{% endblock %} | ||
23 | {% block content %}{% endblock %} | ||
24 | |||
25 | Horizontal reuse is a way to achieve the same goal as multiple inheritance, | ||
26 | but without the associated complexity: | ||
27 | |||
28 | .. code-block:: jinja | ||
29 | |||
30 | {% extends "base.html" %} | ||
31 | |||
32 | {% use "blocks.html" %} | ||
33 | |||
34 | {% block title %}{% endblock %} | ||
35 | {% block content %}{% endblock %} | ||
36 | |||
37 | The ``use`` statement tells Twig to import the blocks defined in | ||
38 | ```blocks.html`` into the current template (it's like macros, but for blocks): | ||
39 | |||
40 | .. code-block:: jinja | ||
41 | |||
42 | # blocks.html | ||
43 | {% block sidebar %}{% endblock %} | ||
44 | |||
45 | In this example, the ``use`` statement imports the ``sidebar`` block into the | ||
46 | main template. The code is mostly equivalent to the following one (the | ||
47 | imported blocks are not outputted automatically): | ||
48 | |||
49 | .. code-block:: jinja | ||
50 | |||
51 | {% extends "base.html" %} | ||
52 | |||
53 | {% block sidebar %}{% endblock %} | ||
54 | {% block title %}{% endblock %} | ||
55 | {% block content %}{% endblock %} | ||
56 | |||
57 | .. note:: | ||
58 | |||
59 | The ``use`` tag only imports a template if it does not extend another | ||
60 | template, if it does not define macros, and if the body is empty. But it | ||
61 | can *use* other templates. | ||
62 | |||
63 | .. note:: | ||
64 | |||
65 | Because ``use`` statements are resolved independently of the context | ||
66 | passed to the template, the template reference cannot be an expression. | ||
67 | |||
68 | The main template can also override any imported block. If the template | ||
69 | already defines the ``sidebar`` block, then the one defined in ``blocks.html`` | ||
70 | is ignored. To avoid name conflicts, you can rename imported blocks: | ||
71 | |||
72 | .. code-block:: jinja | ||
73 | |||
74 | {% extends "base.html" %} | ||
75 | |||
76 | {% use "blocks.html" with sidebar as base_sidebar %} | ||
77 | |||
78 | {% block sidebar %}{% endblock %} | ||
79 | {% block title %}{% endblock %} | ||
80 | {% block content %}{% endblock %} | ||
81 | |||
82 | .. versionadded:: 1.3 | ||
83 | The ``parent()`` support was added in Twig 1.3. | ||
84 | |||
85 | The ``parent()`` function automatically determines the correct inheritance | ||
86 | tree, so it can be used when overriding a block defined in an imported | ||
87 | template: | ||
88 | |||
89 | .. code-block:: jinja | ||
90 | |||
91 | {% extends "base.html" %} | ||
92 | |||
93 | {% use "blocks.html" %} | ||
94 | |||
95 | {% block sidebar %} | ||
96 | {{ parent() }} | ||
97 | {% endblock %} | ||
98 | |||
99 | {% block title %}{% endblock %} | ||
100 | {% block content %}{% endblock %} | ||
101 | |||
102 | In this example, ``parent()`` will correctly call the ``sidebar`` block from | ||
103 | the ``blocks.html`` template. | ||
104 | |||
105 | .. tip:: | ||
106 | |||
107 | In Twig 1.2, renaming allows you to simulate inheritance by calling the | ||
108 | "parent" block: | ||
109 | |||
110 | .. code-block:: jinja | ||
111 | |||
112 | {% extends "base.html" %} | ||
113 | |||
114 | {% use "blocks.html" with sidebar as parent_sidebar %} | ||
115 | |||
116 | {% block sidebar %} | ||
117 | {{ block('parent_sidebar') }} | ||
118 | {% endblock %} | ||
119 | |||
120 | .. note:: | ||
121 | |||
122 | You can use as many ``use`` statements as you want in any given template. | ||
123 | If two imported templates define the same block, the latest one wins. | ||
diff --git a/vendor/twig/twig/doc/tags/verbatim.rst b/vendor/twig/twig/doc/tags/verbatim.rst deleted file mode 100644 index fe61ca1b..00000000 --- a/vendor/twig/twig/doc/tags/verbatim.rst +++ /dev/null | |||
@@ -1,24 +0,0 @@ | |||
1 | ``verbatim`` | ||
2 | ============ | ||
3 | |||
4 | .. versionadded:: 1.12 | ||
5 | The ``verbatim`` tag was added in Twig 1.12 (it was named ``raw`` before). | ||
6 | |||
7 | The ``verbatim`` tag marks sections as being raw text that should not be | ||
8 | parsed. For example to put Twig syntax as example into a template you can use | ||
9 | this snippet: | ||
10 | |||
11 | .. code-block:: jinja | ||
12 | |||
13 | {% verbatim %} | ||
14 | <ul> | ||
15 | {% for item in seq %} | ||
16 | <li>{{ item }}</li> | ||
17 | {% endfor %} | ||
18 | </ul> | ||
19 | {% endverbatim %} | ||
20 | |||
21 | .. note:: | ||
22 | |||
23 | The ``verbatim`` tag works in the exact same way as the old ``raw`` tag, | ||
24 | but was renamed to avoid confusion with the ``raw`` filter. \ No newline at end of file | ||
diff --git a/vendor/twig/twig/doc/templates.rst b/vendor/twig/twig/doc/templates.rst deleted file mode 100644 index 542b8aef..00000000 --- a/vendor/twig/twig/doc/templates.rst +++ /dev/null | |||
@@ -1,851 +0,0 @@ | |||
1 | Twig for Template Designers | ||
2 | =========================== | ||
3 | |||
4 | This document describes the syntax and semantics of the template engine and | ||
5 | will be most useful as reference to those creating Twig templates. | ||
6 | |||
7 | Synopsis | ||
8 | -------- | ||
9 | |||
10 | A template is simply a text file. It can generate any text-based format (HTML, | ||
11 | XML, CSV, LaTeX, etc.). It doesn't have a specific extension, ``.html`` or | ||
12 | ``.xml`` are just fine. | ||
13 | |||
14 | A template contains **variables** or **expressions**, which get replaced with | ||
15 | values when the template is evaluated, and **tags**, which control the logic | ||
16 | of the template. | ||
17 | |||
18 | Below is a minimal template that illustrates a few basics. We will cover the | ||
19 | details later on: | ||
20 | |||
21 | .. code-block:: html+jinja | ||
22 | |||
23 | <!DOCTYPE html> | ||
24 | <html> | ||
25 | <head> | ||
26 | <title>My Webpage</title> | ||
27 | </head> | ||
28 | <body> | ||
29 | <ul id="navigation"> | ||
30 | {% for item in navigation %} | ||
31 | <li><a href="{{ item.href }}">{{ item.caption }}</a></li> | ||
32 | {% endfor %} | ||
33 | </ul> | ||
34 | |||
35 | <h1>My Webpage</h1> | ||
36 | {{ a_variable }} | ||
37 | </body> | ||
38 | </html> | ||
39 | |||
40 | There are two kinds of delimiters: ``{% ... %}`` and ``{{ ... }}``. The first | ||
41 | one is used to execute statements such as for-loops, the latter prints the | ||
42 | result of an expression to the template. | ||
43 | |||
44 | IDEs Integration | ||
45 | ---------------- | ||
46 | |||
47 | Many IDEs support syntax highlighting and auto-completion for Twig: | ||
48 | |||
49 | * *Textmate* via the `Twig bundle`_ | ||
50 | * *Vim* via the `Jinja syntax plugin`_ | ||
51 | * *Netbeans* via the `Twig syntax plugin`_ (until 7.1, native as of 7.2) | ||
52 | * *PhpStorm* (native as of 2.1) | ||
53 | * *Eclipse* via the `Twig plugin`_ | ||
54 | * *Sublime Text* via the `Twig bundle`_ | ||
55 | * *GtkSourceView* via the `Twig language definition`_ (used by gedit and other projects) | ||
56 | * *Coda* and *SubEthaEdit* via the `Twig syntax mode`_ | ||
57 | * *Coda 2* via the `other Twig syntax mode`_ | ||
58 | * *Komodo* and *Komodo Edit* via the Twig highlight/syntax check mode | ||
59 | * *Notepad++* via the `Notepad++ Twig Highlighter`_ | ||
60 | * *Emacs* via `web-mode.el`_ | ||
61 | |||
62 | Variables | ||
63 | --------- | ||
64 | |||
65 | The application passes variables to the templates you can mess around in the | ||
66 | template. Variables may have attributes or elements on them you can access | ||
67 | too. How a variable looks like heavily depends on the application providing | ||
68 | those. | ||
69 | |||
70 | You can use a dot (``.``) to access attributes of a variable (methods or | ||
71 | properties of a PHP object, or items of a PHP array), or the so-called | ||
72 | "subscript" syntax (``[]``): | ||
73 | |||
74 | .. code-block:: jinja | ||
75 | |||
76 | {{ foo.bar }} | ||
77 | {{ foo['bar'] }} | ||
78 | |||
79 | When the attribute contains special characters (like ``-`` that would be | ||
80 | interpreted as the minus operator), use the ``attribute`` function instead to | ||
81 | access the variable attribute: | ||
82 | |||
83 | .. code-block:: jinja | ||
84 | |||
85 | {# equivalent to the non-working foo.data-foo #} | ||
86 | {{ attribute(foo, 'data-foo') }} | ||
87 | |||
88 | .. note:: | ||
89 | |||
90 | It's important to know that the curly braces are *not* part of the | ||
91 | variable but the print statement. If you access variables inside tags | ||
92 | don't put the braces around. | ||
93 | |||
94 | If a variable or attribute does not exist, you will get back a ``null`` value | ||
95 | when the ``strict_variables`` option is set to ``false``, otherwise Twig will | ||
96 | throw an error (see :ref:`environment options<environment_options>`). | ||
97 | |||
98 | .. sidebar:: Implementation | ||
99 | |||
100 | For convenience sake ``foo.bar`` does the following things on the PHP | ||
101 | layer: | ||
102 | |||
103 | * check if ``foo`` is an array and ``bar`` a valid element; | ||
104 | * if not, and if ``foo`` is an object, check that ``bar`` is a valid property; | ||
105 | * if not, and if ``foo`` is an object, check that ``bar`` is a valid method | ||
106 | (even if ``bar`` is the constructor - use ``__construct()`` instead); | ||
107 | * if not, and if ``foo`` is an object, check that ``getBar`` is a valid method; | ||
108 | * if not, and if ``foo`` is an object, check that ``isBar`` is a valid method; | ||
109 | * if not, return a ``null`` value. | ||
110 | |||
111 | ``foo['bar']`` on the other hand only works with PHP arrays: | ||
112 | |||
113 | * check if ``foo`` is an array and ``bar`` a valid element; | ||
114 | * if not, return a ``null`` value. | ||
115 | |||
116 | .. note:: | ||
117 | |||
118 | If you want to get a dynamic attribute on a variable, use the | ||
119 | :doc:`attribute<functions/attribute>` function instead. | ||
120 | |||
121 | Global Variables | ||
122 | ~~~~~~~~~~~~~~~~ | ||
123 | |||
124 | The following variables are always available in templates: | ||
125 | |||
126 | * ``_self``: references the current template; | ||
127 | * ``_context``: references the current context; | ||
128 | * ``_charset``: references the current charset. | ||
129 | |||
130 | Setting Variables | ||
131 | ~~~~~~~~~~~~~~~~~ | ||
132 | |||
133 | You can assign values to variables inside code blocks. Assignments use the | ||
134 | :doc:`set<tags/set>` tag: | ||
135 | |||
136 | .. code-block:: jinja | ||
137 | |||
138 | {% set foo = 'foo' %} | ||
139 | {% set foo = [1, 2] %} | ||
140 | {% set foo = {'foo': 'bar'} %} | ||
141 | |||
142 | Filters | ||
143 | ------- | ||
144 | |||
145 | Variables can be modified by **filters**. Filters are separated from the | ||
146 | variable by a pipe symbol (``|``) and may have optional arguments in | ||
147 | parentheses. Multiple filters can be chained. The output of one filter is | ||
148 | applied to the next. | ||
149 | |||
150 | The following example removes all HTML tags from the ``name`` and title-cases | ||
151 | it: | ||
152 | |||
153 | .. code-block:: jinja | ||
154 | |||
155 | {{ name|striptags|title }} | ||
156 | |||
157 | Filters that accept arguments have parentheses around the arguments. This | ||
158 | example will join a list by commas: | ||
159 | |||
160 | .. code-block:: jinja | ||
161 | |||
162 | {{ list|join(', ') }} | ||
163 | |||
164 | To apply a filter on a section of code, wrap it with the | ||
165 | :doc:`filter<tags/filter>` tag: | ||
166 | |||
167 | .. code-block:: jinja | ||
168 | |||
169 | {% filter upper %} | ||
170 | This text becomes uppercase | ||
171 | {% endfilter %} | ||
172 | |||
173 | Go to the :doc:`filters<filters/index>` page to learn more about the built-in | ||
174 | filters. | ||
175 | |||
176 | Functions | ||
177 | --------- | ||
178 | |||
179 | Functions can be called to generate content. Functions are called by their | ||
180 | name followed by parentheses (``()``) and may have arguments. | ||
181 | |||
182 | For instance, the ``range`` function returns a list containing an arithmetic | ||
183 | progression of integers: | ||
184 | |||
185 | .. code-block:: jinja | ||
186 | |||
187 | {% for i in range(0, 3) %} | ||
188 | {{ i }}, | ||
189 | {% endfor %} | ||
190 | |||
191 | Go to the :doc:`functions<functions/index>` page to learn more about the | ||
192 | built-in functions. | ||
193 | |||
194 | Named Arguments | ||
195 | --------------- | ||
196 | |||
197 | .. versionadded:: 1.12 | ||
198 | Support for named arguments was added in Twig 1.12. | ||
199 | |||
200 | Arguments for filters and functions can also be passed as *named arguments*: | ||
201 | |||
202 | .. code-block:: jinja | ||
203 | |||
204 | {% for i in range(low=1, high=10, step=2) %} | ||
205 | {{ i }}, | ||
206 | {% endfor %} | ||
207 | |||
208 | Using named arguments makes your templates more explicit about the meaning of | ||
209 | the values you pass as arguments: | ||
210 | |||
211 | .. code-block:: jinja | ||
212 | |||
213 | {{ data|convert_encoding('UTF-8', 'iso-2022-jp') }} | ||
214 | |||
215 | {# versus #} | ||
216 | |||
217 | {{ data|convert_encoding(from='iso-2022-jp', to='UTF-8') }} | ||
218 | |||
219 | Named arguments also allow you to skip some arguments for which you don't want | ||
220 | to change the default value: | ||
221 | |||
222 | .. code-block:: jinja | ||
223 | |||
224 | {# the first argument is the date format, which defaults to the global date format if null is passed #} | ||
225 | {{ "now"|date(null, "Europe/Paris") }} | ||
226 | |||
227 | {# or skip the format value by using a named argument for the timezone #} | ||
228 | {{ "now"|date(timezone="Europe/Paris") }} | ||
229 | |||
230 | You can also use both positional and named arguments in one call, in which | ||
231 | case positional arguments must always come before named arguments: | ||
232 | |||
233 | .. code-block:: jinja | ||
234 | |||
235 | {{ "now"|date('d/m/Y H:i', timezone="Europe/Paris") }} | ||
236 | |||
237 | .. tip:: | ||
238 | |||
239 | Each function and filter documentation page has a section where the names | ||
240 | of all arguments are listed when supported. | ||
241 | |||
242 | Control Structure | ||
243 | ----------------- | ||
244 | |||
245 | A control structure refers to all those things that control the flow of a | ||
246 | program - conditionals (i.e. ``if``/``elseif``/``else``), ``for``-loops, as | ||
247 | well as things like blocks. Control structures appear inside ``{% ... %}`` | ||
248 | blocks. | ||
249 | |||
250 | For example, to display a list of users provided in a variable called | ||
251 | ``users``, use the :doc:`for<tags/for>` tag: | ||
252 | |||
253 | .. code-block:: jinja | ||
254 | |||
255 | <h1>Members</h1> | ||
256 | <ul> | ||
257 | {% for user in users %} | ||
258 | <li>{{ user.username|e }}</li> | ||
259 | {% endfor %} | ||
260 | </ul> | ||
261 | |||
262 | The :doc:`if<tags/if>` tag can be used to test an expression: | ||
263 | |||
264 | .. code-block:: jinja | ||
265 | |||
266 | {% if users|length > 0 %} | ||
267 | <ul> | ||
268 | {% for user in users %} | ||
269 | <li>{{ user.username|e }}</li> | ||
270 | {% endfor %} | ||
271 | </ul> | ||
272 | {% endif %} | ||
273 | |||
274 | Go to the :doc:`tags<tags/index>` page to learn more about the built-in tags. | ||
275 | |||
276 | Comments | ||
277 | -------- | ||
278 | |||
279 | To comment-out part of a line in a template, use the comment syntax ``{# ... | ||
280 | #}``. This is useful for debugging or to add information for other template | ||
281 | designers or yourself: | ||
282 | |||
283 | .. code-block:: jinja | ||
284 | |||
285 | {# note: disabled template because we no longer use this | ||
286 | {% for user in users %} | ||
287 | ... | ||
288 | {% endfor %} | ||
289 | #} | ||
290 | |||
291 | Including other Templates | ||
292 | ------------------------- | ||
293 | |||
294 | The :doc:`include<tags/include>` tag is useful to include a template and | ||
295 | return the rendered content of that template into the current one: | ||
296 | |||
297 | .. code-block:: jinja | ||
298 | |||
299 | {% include 'sidebar.html' %} | ||
300 | |||
301 | Per default included templates are passed the current context. | ||
302 | |||
303 | The context that is passed to the included template includes variables defined | ||
304 | in the template: | ||
305 | |||
306 | .. code-block:: jinja | ||
307 | |||
308 | {% for box in boxes %} | ||
309 | {% include "render_box.html" %} | ||
310 | {% endfor %} | ||
311 | |||
312 | The included template ``render_box.html`` is able to access ``box``. | ||
313 | |||
314 | The filename of the template depends on the template loader. For instance, the | ||
315 | ``Twig_Loader_Filesystem`` allows you to access other templates by giving the | ||
316 | filename. You can access templates in subdirectories with a slash: | ||
317 | |||
318 | .. code-block:: jinja | ||
319 | |||
320 | {% include "sections/articles/sidebar.html" %} | ||
321 | |||
322 | This behavior depends on the application embedding Twig. | ||
323 | |||
324 | Template Inheritance | ||
325 | -------------------- | ||
326 | |||
327 | The most powerful part of Twig is template inheritance. Template inheritance | ||
328 | allows you to build a base "skeleton" template that contains all the common | ||
329 | elements of your site and defines **blocks** that child templates can | ||
330 | override. | ||
331 | |||
332 | Sounds complicated but is very basic. It's easier to understand it by | ||
333 | starting with an example. | ||
334 | |||
335 | Let's define a base template, ``base.html``, which defines a simple HTML | ||
336 | skeleton document that you might use for a simple two-column page: | ||
337 | |||
338 | .. code-block:: html+jinja | ||
339 | |||
340 | <!DOCTYPE html> | ||
341 | <html> | ||
342 | <head> | ||
343 | {% block head %} | ||
344 | <link rel="stylesheet" href="style.css" /> | ||
345 | <title>{% block title %}{% endblock %} - My Webpage</title> | ||
346 | {% endblock %} | ||
347 | </head> | ||
348 | <body> | ||
349 | <div id="content">{% block content %}{% endblock %}</div> | ||
350 | <div id="footer"> | ||
351 | {% block footer %} | ||
352 | © Copyright 2011 by <a href="http://domain.invalid/">you</a>. | ||
353 | {% endblock %} | ||
354 | </div> | ||
355 | </body> | ||
356 | </html> | ||
357 | |||
358 | In this example, the :doc:`block<tags/block>` tags define four blocks that | ||
359 | child templates can fill in. All the ``block`` tag does is to tell the | ||
360 | template engine that a child template may override those portions of the | ||
361 | template. | ||
362 | |||
363 | A child template might look like this: | ||
364 | |||
365 | .. code-block:: jinja | ||
366 | |||
367 | {% extends "base.html" %} | ||
368 | |||
369 | {% block title %}Index{% endblock %} | ||
370 | {% block head %} | ||
371 | {{ parent() }} | ||
372 | <style type="text/css"> | ||
373 | .important { color: #336699; } | ||
374 | </style> | ||
375 | {% endblock %} | ||
376 | {% block content %} | ||
377 | <h1>Index</h1> | ||
378 | <p class="important"> | ||
379 | Welcome to my awesome homepage. | ||
380 | </p> | ||
381 | {% endblock %} | ||
382 | |||
383 | The :doc:`extends<tags/extends>` tag is the key here. It tells the template | ||
384 | engine that this template "extends" another template. When the template system | ||
385 | evaluates this template, first it locates the parent. The extends tag should | ||
386 | be the first tag in the template. | ||
387 | |||
388 | Note that since the child template doesn't define the ``footer`` block, the | ||
389 | value from the parent template is used instead. | ||
390 | |||
391 | It's possible to render the contents of the parent block by using the | ||
392 | :doc:`parent<functions/parent>` function. This gives back the results of the | ||
393 | parent block: | ||
394 | |||
395 | .. code-block:: jinja | ||
396 | |||
397 | {% block sidebar %} | ||
398 | <h3>Table Of Contents</h3> | ||
399 | ... | ||
400 | {{ parent() }} | ||
401 | {% endblock %} | ||
402 | |||
403 | .. tip:: | ||
404 | |||
405 | The documentation page for the :doc:`extends<tags/extends>` tag describes | ||
406 | more advanced features like block nesting, scope, dynamic inheritance, and | ||
407 | conditional inheritance. | ||
408 | |||
409 | .. note:: | ||
410 | |||
411 | Twig also supports multiple inheritance with the so called horizontal reuse | ||
412 | with the help of the :doc:`use<tags/use>` tag. This is an advanced feature | ||
413 | hardly ever needed in regular templates. | ||
414 | |||
415 | HTML Escaping | ||
416 | ------------- | ||
417 | |||
418 | When generating HTML from templates, there's always a risk that a variable | ||
419 | will include characters that affect the resulting HTML. There are two | ||
420 | approaches: manually escaping each variable or automatically escaping | ||
421 | everything by default. | ||
422 | |||
423 | Twig supports both, automatic escaping is enabled by default. | ||
424 | |||
425 | .. note:: | ||
426 | |||
427 | Automatic escaping is only supported if the *escaper* extension has been | ||
428 | enabled (which is the default). | ||
429 | |||
430 | Working with Manual Escaping | ||
431 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
432 | |||
433 | If manual escaping is enabled, it is **your** responsibility to escape | ||
434 | variables if needed. What to escape? Any variable you don't trust. | ||
435 | |||
436 | Escaping works by piping the variable through the | ||
437 | :doc:`escape<filters/escape>` or ``e`` filter: | ||
438 | |||
439 | .. code-block:: jinja | ||
440 | |||
441 | {{ user.username|e }} | ||
442 | |||
443 | By default, the ``escape`` filter uses the ``html`` strategy, but depending on | ||
444 | the escaping context, you might want to explicitly use any other available | ||
445 | strategies: | ||
446 | |||
447 | .. code-block:: jinja | ||
448 | |||
449 | {{ user.username|e('js') }} | ||
450 | {{ user.username|e('css') }} | ||
451 | {{ user.username|e('url') }} | ||
452 | {{ user.username|e('html_attr') }} | ||
453 | |||
454 | Working with Automatic Escaping | ||
455 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
456 | |||
457 | Whether automatic escaping is enabled or not, you can mark a section of a | ||
458 | template to be escaped or not by using the :doc:`autoescape<tags/autoescape>` | ||
459 | tag: | ||
460 | |||
461 | .. code-block:: jinja | ||
462 | |||
463 | {% autoescape %} | ||
464 | Everything will be automatically escaped in this block (using the HTML strategy) | ||
465 | {% endautoescape %} | ||
466 | |||
467 | By default, auto-escaping uses the ``html`` escaping strategy. If you output | ||
468 | variables in other contexts, you need to explicitly escape them with the | ||
469 | appropriate escaping strategy: | ||
470 | |||
471 | .. code-block:: jinja | ||
472 | |||
473 | {% autoescape 'js' %} | ||
474 | Everything will be automatically escaped in this block (using the JS strategy) | ||
475 | {% endautoescape %} | ||
476 | |||
477 | Escaping | ||
478 | -------- | ||
479 | |||
480 | It is sometimes desirable or even necessary to have Twig ignore parts it would | ||
481 | otherwise handle as variables or blocks. For example if the default syntax is | ||
482 | used and you want to use ``{{`` as raw string in the template and not start a | ||
483 | variable you have to use a trick. | ||
484 | |||
485 | The easiest way is to output the variable delimiter (``{{``) by using a variable | ||
486 | expression: | ||
487 | |||
488 | .. code-block:: jinja | ||
489 | |||
490 | {{ '{{' }} | ||
491 | |||
492 | For bigger sections it makes sense to mark a block | ||
493 | :doc:`verbatim<tags/verbatim>`. | ||
494 | |||
495 | Macros | ||
496 | ------ | ||
497 | |||
498 | .. versionadded:: 1.12 | ||
499 | Support for default argument values was added in Twig 1.12. | ||
500 | |||
501 | Macros are comparable with functions in regular programming languages. They | ||
502 | are useful to reuse often used HTML fragments to not repeat yourself. | ||
503 | |||
504 | A macro is defined via the :doc:`macro<tags/macro>` tag. Here is a small example | ||
505 | (subsequently called ``forms.html``) of a macro that renders a form element: | ||
506 | |||
507 | .. code-block:: jinja | ||
508 | |||
509 | {% macro input(name, value, type, size) %} | ||
510 | <input type="{{ type|default('text') }}" name="{{ name }}" value="{{ value|e }}" size="{{ size|default(20) }}" /> | ||
511 | {% endmacro %} | ||
512 | |||
513 | Macros can be defined in any template, and need to be "imported" via the | ||
514 | :doc:`import<tags/import>` tag before being used: | ||
515 | |||
516 | .. code-block:: jinja | ||
517 | |||
518 | {% import "forms.html" as forms %} | ||
519 | |||
520 | <p>{{ forms.input('username') }}</p> | ||
521 | |||
522 | Alternatively, you can import individual macro names from a template into the | ||
523 | current namespace via the :doc:`from<tags/from>` tag and optionally alias them: | ||
524 | |||
525 | .. code-block:: jinja | ||
526 | |||
527 | {% from 'forms.html' import input as input_field %} | ||
528 | |||
529 | <dl> | ||
530 | <dt>Username</dt> | ||
531 | <dd>{{ input_field('username') }}</dd> | ||
532 | <dt>Password</dt> | ||
533 | <dd>{{ input_field('password', '', 'password') }}</dd> | ||
534 | </dl> | ||
535 | |||
536 | A default value can also be defined for macro arguments when not provided in a | ||
537 | macro call: | ||
538 | |||
539 | .. code-block:: jinja | ||
540 | |||
541 | {% macro input(name, value = "", type = "text", size = 20) %} | ||
542 | <input type="{{ type }}" name="{{ name }}" value="{{ value|e }}" size="{{ size }}" /> | ||
543 | {% endmacro %} | ||
544 | |||
545 | .. _twig-expressions: | ||
546 | |||
547 | Expressions | ||
548 | ----------- | ||
549 | |||
550 | Twig allows expressions everywhere. These work very similar to regular PHP and | ||
551 | even if you're not working with PHP you should feel comfortable with it. | ||
552 | |||
553 | .. note:: | ||
554 | |||
555 | The operator precedence is as follows, with the lowest-precedence | ||
556 | operators listed first: ``b-and``, ``b-xor``, ``b-or``, ``or``, ``and``, | ||
557 | ``==``, ``!=``, ``<``, ``>``, ``>=``, ``<=``, ``in``, ``..``, ``+``, | ||
558 | ``-``, ``~``, ``*``, ``/``, ``//``, ``%``, ``is``, ``**``, ``|``, ``[]``, | ||
559 | and ``.``: | ||
560 | |||
561 | .. code-block:: jinja | ||
562 | |||
563 | {% set greeting = 'Hello' %} | ||
564 | {% set name = 'Fabien' %} | ||
565 | |||
566 | {{ greeting ~ name|lower }} {# Hello fabien #} | ||
567 | |||
568 | {# use parenthesis to change precedence #} | ||
569 | {{ (greeting ~ name)|lower }} {# hello fabien #} | ||
570 | |||
571 | Literals | ||
572 | ~~~~~~~~ | ||
573 | |||
574 | .. versionadded:: 1.5 | ||
575 | Support for hash keys as names and expressions was added in Twig 1.5. | ||
576 | |||
577 | The simplest form of expressions are literals. Literals are representations | ||
578 | for PHP types such as strings, numbers, and arrays. The following literals | ||
579 | exist: | ||
580 | |||
581 | * ``"Hello World"``: Everything between two double or single quotes is a | ||
582 | string. They are useful whenever you need a string in the template (for | ||
583 | example as arguments to function calls, filters or just to extend or include | ||
584 | a template). A string can contain a delimiter if it is preceded by a | ||
585 | backslash (``\``) -- like in ``'It\'s good'``. | ||
586 | |||
587 | * ``42`` / ``42.23``: Integers and floating point numbers are created by just | ||
588 | writing the number down. If a dot is present the number is a float, | ||
589 | otherwise an integer. | ||
590 | |||
591 | * ``["foo", "bar"]``: Arrays are defined by a sequence of expressions | ||
592 | separated by a comma (``,``) and wrapped with squared brackets (``[]``). | ||
593 | |||
594 | * ``{"foo": "bar"}``: Hashes are defined by a list of keys and values | ||
595 | separated by a comma (``,``) and wrapped with curly braces (``{}``): | ||
596 | |||
597 | .. code-block:: jinja | ||
598 | |||
599 | {# keys as string #} | ||
600 | { 'foo': 'foo', 'bar': 'bar' } | ||
601 | |||
602 | {# keys as names (equivalent to the previous hash) -- as of Twig 1.5 #} | ||
603 | { foo: 'foo', bar: 'bar' } | ||
604 | |||
605 | {# keys as integer #} | ||
606 | { 2: 'foo', 4: 'bar' } | ||
607 | |||
608 | {# keys as expressions (the expression must be enclosed into parentheses) -- as of Twig 1.5 #} | ||
609 | { (1 + 1): 'foo', (a ~ 'b'): 'bar' } | ||
610 | |||
611 | * ``true`` / ``false``: ``true`` represents the true value, ``false`` | ||
612 | represents the false value. | ||
613 | |||
614 | * ``null``: ``null`` represents no specific value. This is the value returned | ||
615 | when a variable does not exist. ``none`` is an alias for ``null``. | ||
616 | |||
617 | Arrays and hashes can be nested: | ||
618 | |||
619 | .. code-block:: jinja | ||
620 | |||
621 | {% set foo = [1, {"foo": "bar"}] %} | ||
622 | |||
623 | .. tip:: | ||
624 | |||
625 | Using double-quoted or single-quoted strings has no impact on performance | ||
626 | but string interpolation is only supported in double-quoted strings. | ||
627 | |||
628 | Math | ||
629 | ~~~~ | ||
630 | |||
631 | Twig allows you to calculate with values. This is rarely useful in templates | ||
632 | but exists for completeness' sake. The following operators are supported: | ||
633 | |||
634 | * ``+``: Adds two objects together (the operands are casted to numbers). ``{{ | ||
635 | 1 + 1 }}`` is ``2``. | ||
636 | |||
637 | * ``-``: Subtracts the second number from the first one. ``{{ 3 - 2 }}`` is | ||
638 | ``1``. | ||
639 | |||
640 | * ``/``: Divides two numbers. The returned value will be a floating point | ||
641 | number. ``{{ 1 / 2 }}`` is ``{{ 0.5 }}``. | ||
642 | |||
643 | * ``%``: Calculates the remainder of an integer division. ``{{ 11 % 7 }}`` is | ||
644 | ``4``. | ||
645 | |||
646 | * ``//``: Divides two numbers and returns the truncated integer result. ``{{ | ||
647 | 20 // 7 }}`` is ``2``. | ||
648 | |||
649 | * ``*``: Multiplies the left operand with the right one. ``{{ 2 * 2 }}`` would | ||
650 | return ``4``. | ||
651 | |||
652 | * ``**``: Raises the left operand to the power of the right operand. ``{{ 2 ** | ||
653 | 3 }}`` would return ``8``. | ||
654 | |||
655 | Logic | ||
656 | ~~~~~ | ||
657 | |||
658 | You can combine multiple expressions with the following operators: | ||
659 | |||
660 | * ``and``: Returns true if the left and the right operands are both true. | ||
661 | |||
662 | * ``or``: Returns true if the left or the right operand is true. | ||
663 | |||
664 | * ``not``: Negates a statement. | ||
665 | |||
666 | * ``(expr)``: Groups an expression. | ||
667 | |||
668 | .. note:: | ||
669 | |||
670 | Twig also support bitwise operators (``b-and``, ``b-xor``, and ``b-or``). | ||
671 | |||
672 | Comparisons | ||
673 | ~~~~~~~~~~~ | ||
674 | |||
675 | The following comparison operators are supported in any expression: ``==``, | ||
676 | ``!=``, ``<``, ``>``, ``>=``, and ``<=``. | ||
677 | |||
678 | Containment Operator | ||
679 | ~~~~~~~~~~~~~~~~~~~~ | ||
680 | |||
681 | The ``in`` operator performs containment test. | ||
682 | |||
683 | It returns ``true`` if the left operand is contained in the right: | ||
684 | |||
685 | .. code-block:: jinja | ||
686 | |||
687 | {# returns true #} | ||
688 | |||
689 | {{ 1 in [1, 2, 3] }} | ||
690 | |||
691 | {{ 'cd' in 'abcde' }} | ||
692 | |||
693 | .. tip:: | ||
694 | |||
695 | You can use this filter to perform a containment test on strings, arrays, | ||
696 | or objects implementing the ``Traversable`` interface. | ||
697 | |||
698 | To perform a negative test, use the ``not in`` operator: | ||
699 | |||
700 | .. code-block:: jinja | ||
701 | |||
702 | {% if 1 not in [1, 2, 3] %} | ||
703 | |||
704 | {# is equivalent to #} | ||
705 | {% if not (1 in [1, 2, 3]) %} | ||
706 | |||
707 | Test Operator | ||
708 | ~~~~~~~~~~~~~ | ||
709 | |||
710 | The ``is`` operator performs tests. Tests can be used to test a variable against | ||
711 | a common expression. The right operand is name of the test: | ||
712 | |||
713 | .. code-block:: jinja | ||
714 | |||
715 | {# find out if a variable is odd #} | ||
716 | |||
717 | {{ name is odd }} | ||
718 | |||
719 | Tests can accept arguments too: | ||
720 | |||
721 | .. code-block:: jinja | ||
722 | |||
723 | {% if loop.index is divisibleby(3) %} | ||
724 | |||
725 | Tests can be negated by using the ``is not`` operator: | ||
726 | |||
727 | .. code-block:: jinja | ||
728 | |||
729 | {% if loop.index is not divisibleby(3) %} | ||
730 | |||
731 | {# is equivalent to #} | ||
732 | {% if not (loop.index is divisibleby(3)) %} | ||
733 | |||
734 | Go to the :doc:`tests<tests/index>` page to learn more about the built-in | ||
735 | tests. | ||
736 | |||
737 | Other Operators | ||
738 | ~~~~~~~~~~~~~~~ | ||
739 | |||
740 | .. versionadded:: 1.12.0 | ||
741 | Support for the extended ternary operator was added in Twig 1.12.0. | ||
742 | |||
743 | The following operators are very useful but don't fit into any of the other | ||
744 | categories: | ||
745 | |||
746 | * ``..``: Creates a sequence based on the operand before and after the | ||
747 | operator (this is just syntactic sugar for the :doc:`range<functions/range>` | ||
748 | function). | ||
749 | |||
750 | * ``|``: Applies a filter. | ||
751 | |||
752 | * ``~``: Converts all operands into strings and concatenates them. ``{{ "Hello | ||
753 | " ~ name ~ "!" }}`` would return (assuming ``name`` is ``'John'``) ``Hello | ||
754 | John!``. | ||
755 | |||
756 | * ``.``, ``[]``: Gets an attribute of an object. | ||
757 | |||
758 | * ``?:``: The ternary operator: | ||
759 | |||
760 | .. code-block:: jinja | ||
761 | |||
762 | {{ foo ? 'yes' : 'no' }} | ||
763 | |||
764 | {# as of Twig 1.12.0 #} | ||
765 | {{ foo ?: 'no' }} == {{ foo ? foo : 'no' }} | ||
766 | {{ foo ? 'yes' }} == {{ foo ? 'yes' : '' }} | ||
767 | |||
768 | String Interpolation | ||
769 | ~~~~~~~~~~~~~~~~~~~~ | ||
770 | |||
771 | .. versionadded:: 1.5 | ||
772 | String interpolation was added in Twig 1.5. | ||
773 | |||
774 | String interpolation (`#{expression}`) allows any valid expression to appear | ||
775 | within a *double-quoted string*. The result of evaluating that expression is | ||
776 | inserted into the string: | ||
777 | |||
778 | .. code-block:: jinja | ||
779 | |||
780 | {{ "foo #{bar} baz" }} | ||
781 | {{ "foo #{1 + 2} baz" }} | ||
782 | |||
783 | Whitespace Control | ||
784 | ------------------ | ||
785 | |||
786 | .. versionadded:: 1.1 | ||
787 | Tag level whitespace control was added in Twig 1.1. | ||
788 | |||
789 | The first newline after a template tag is removed automatically (like in PHP.) | ||
790 | Whitespace is not further modified by the template engine, so each whitespace | ||
791 | (spaces, tabs, newlines etc.) is returned unchanged. | ||
792 | |||
793 | Use the ``spaceless`` tag to remove whitespace *between HTML tags*: | ||
794 | |||
795 | .. code-block:: jinja | ||
796 | |||
797 | {% spaceless %} | ||
798 | <div> | ||
799 | <strong>foo bar</strong> | ||
800 | </div> | ||
801 | {% endspaceless %} | ||
802 | |||
803 | {# output will be <div><strong>foo bar</strong></div> #} | ||
804 | |||
805 | In addition to the spaceless tag you can also control whitespace on a per tag | ||
806 | level. By using the whitespace control modifier on your tags, you can trim | ||
807 | leading and or trailing whitespace: | ||
808 | |||
809 | .. code-block:: jinja | ||
810 | |||
811 | {% set value = 'no spaces' %} | ||
812 | {#- No leading/trailing whitespace -#} | ||
813 | {%- if true -%} | ||
814 | {{- value -}} | ||
815 | {%- endif -%} | ||
816 | |||
817 | {# output 'no spaces' #} | ||
818 | |||
819 | The above sample shows the default whitespace control modifier, and how you can | ||
820 | use it to remove whitespace around tags. Trimming space will consume all whitespace | ||
821 | for that side of the tag. It is possible to use whitespace trimming on one side | ||
822 | of a tag: | ||
823 | |||
824 | .. code-block:: jinja | ||
825 | |||
826 | {% set value = 'no spaces' %} | ||
827 | <li> {{- value }} </li> | ||
828 | |||
829 | {# outputs '<li>no spaces </li>' #} | ||
830 | |||
831 | Extensions | ||
832 | ---------- | ||
833 | |||
834 | Twig can be easily extended. | ||
835 | |||
836 | If you are looking for new tags, filters, or functions, have a look at the Twig official | ||
837 | `extension repository`_. | ||
838 | |||
839 | If you want to create your own, read the :ref:`Creating an | ||
840 | Extension<creating_extensions>` chapter. | ||
841 | |||
842 | .. _`Twig bundle`: https://github.com/Anomareh/PHP-Twig.tmbundle | ||
843 | .. _`Jinja syntax plugin`: http://jinja.pocoo.org/2/documentation/integration | ||
844 | .. _`Twig syntax plugin`: http://plugins.netbeans.org/plugin/37069/php-twig | ||
845 | .. _`Twig plugin`: https://github.com/pulse00/Twig-Eclipse-Plugin | ||
846 | .. _`Twig language definition`: https://github.com/gabrielcorpse/gedit-twig-template-language | ||
847 | .. _`extension repository`: http://github.com/fabpot/Twig-extensions | ||
848 | .. _`Twig syntax mode`: https://github.com/bobthecow/Twig-HTML.mode | ||
849 | .. _`other Twig syntax mode`: https://github.com/muxx/Twig-HTML.mode | ||
850 | .. _`Notepad++ Twig Highlighter`: https://github.com/Banane9/notepadplusplus-twig | ||
851 | .. _`web-mode.el`: http://web-mode.org/ | ||
diff --git a/vendor/twig/twig/doc/tests/constant.rst b/vendor/twig/twig/doc/tests/constant.rst deleted file mode 100644 index 8d0724a8..00000000 --- a/vendor/twig/twig/doc/tests/constant.rst +++ /dev/null | |||
@@ -1,22 +0,0 @@ | |||
1 | ``constant`` | ||
2 | ============ | ||
3 | |||
4 | .. versionadded: 1.13.1 | ||
5 | constant now accepts object instances as the second argument. | ||
6 | |||
7 | ``constant`` checks if a variable has the exact same value as a constant. You | ||
8 | can use either global constants or class constants: | ||
9 | |||
10 | .. code-block:: jinja | ||
11 | |||
12 | {% if post.status is constant('Post::PUBLISHED') %} | ||
13 | the status attribute is exactly the same as Post::PUBLISHED | ||
14 | {% endif %} | ||
15 | |||
16 | You can test constants from object instances as well: | ||
17 | |||
18 | .. code-block:: jinja | ||
19 | |||
20 | {% if post.status is constant('PUBLISHED', post) %} | ||
21 | the status attribute is exactly the same as Post::PUBLISHED | ||
22 | {% endif %} | ||
diff --git a/vendor/twig/twig/doc/tests/defined.rst b/vendor/twig/twig/doc/tests/defined.rst deleted file mode 100644 index 702ce725..00000000 --- a/vendor/twig/twig/doc/tests/defined.rst +++ /dev/null | |||
@@ -1,30 +0,0 @@ | |||
1 | ``defined`` | ||
2 | =========== | ||
3 | |||
4 | ``defined`` checks if a variable is defined in the current context. This is very | ||
5 | useful if you use the ``strict_variables`` option: | ||
6 | |||
7 | .. code-block:: jinja | ||
8 | |||
9 | {# defined works with variable names #} | ||
10 | {% if foo is defined %} | ||
11 | ... | ||
12 | {% endif %} | ||
13 | |||
14 | {# and attributes on variables names #} | ||
15 | {% if foo.bar is defined %} | ||
16 | ... | ||
17 | {% endif %} | ||
18 | |||
19 | {% if foo['bar'] is defined %} | ||
20 | ... | ||
21 | {% endif %} | ||
22 | |||
23 | When using the ``defined`` test on an expression that uses variables in some | ||
24 | method calls, be sure that they are all defined first: | ||
25 | |||
26 | .. code-block:: jinja | ||
27 | |||
28 | {% if var is defined and foo.method(var) is defined %} | ||
29 | ... | ||
30 | {% endif %} | ||
diff --git a/vendor/twig/twig/doc/tests/divisibleby.rst b/vendor/twig/twig/doc/tests/divisibleby.rst deleted file mode 100644 index 9b0b9644..00000000 --- a/vendor/twig/twig/doc/tests/divisibleby.rst +++ /dev/null | |||
@@ -1,10 +0,0 @@ | |||
1 | ``divisibleby`` | ||
2 | =============== | ||
3 | |||
4 | ``divisibleby`` checks if a variable is divisible by a number: | ||
5 | |||
6 | .. code-block:: jinja | ||
7 | |||
8 | {% if loop.index is divisibleby(3) %} | ||
9 | ... | ||
10 | {% endif %} | ||
diff --git a/vendor/twig/twig/doc/tests/empty.rst b/vendor/twig/twig/doc/tests/empty.rst deleted file mode 100644 index e5b55999..00000000 --- a/vendor/twig/twig/doc/tests/empty.rst +++ /dev/null | |||
@@ -1,11 +0,0 @@ | |||
1 | ``empty`` | ||
2 | ========= | ||
3 | |||
4 | ``empty`` checks if a variable is empty: | ||
5 | |||
6 | .. code-block:: jinja | ||
7 | |||
8 | {# evaluates to true if the foo variable is null, false, an empty array, or the empty string #} | ||
9 | {% if foo is empty %} | ||
10 | ... | ||
11 | {% endif %} | ||
diff --git a/vendor/twig/twig/doc/tests/even.rst b/vendor/twig/twig/doc/tests/even.rst deleted file mode 100644 index 6ab5cc39..00000000 --- a/vendor/twig/twig/doc/tests/even.rst +++ /dev/null | |||
@@ -1,10 +0,0 @@ | |||
1 | ``even`` | ||
2 | ======== | ||
3 | |||
4 | ``even`` returns ``true`` if the given number is even: | ||
5 | |||
6 | .. code-block:: jinja | ||
7 | |||
8 | {{ var is even }} | ||
9 | |||
10 | .. seealso:: :doc:`odd<../tests/odd>` | ||
diff --git a/vendor/twig/twig/doc/tests/index.rst b/vendor/twig/twig/doc/tests/index.rst deleted file mode 100644 index c63208ee..00000000 --- a/vendor/twig/twig/doc/tests/index.rst +++ /dev/null | |||
@@ -1,15 +0,0 @@ | |||
1 | Tests | ||
2 | ===== | ||
3 | |||
4 | .. toctree:: | ||
5 | :maxdepth: 1 | ||
6 | |||
7 | constant | ||
8 | defined | ||
9 | divisibleby | ||
10 | empty | ||
11 | even | ||
12 | iterable | ||
13 | null | ||
14 | odd | ||
15 | sameas | ||
diff --git a/vendor/twig/twig/doc/tests/iterable.rst b/vendor/twig/twig/doc/tests/iterable.rst deleted file mode 100644 index 89a172f7..00000000 --- a/vendor/twig/twig/doc/tests/iterable.rst +++ /dev/null | |||
@@ -1,19 +0,0 @@ | |||
1 | ``iterable`` | ||
2 | ============ | ||
3 | |||
4 | .. versionadded:: 1.7 | ||
5 | The iterable test was added in Twig 1.7. | ||
6 | |||
7 | ``iterable`` checks if a variable is an array or a traversable object: | ||
8 | |||
9 | .. code-block:: jinja | ||
10 | |||
11 | {# evaluates to true if the foo variable is iterable #} | ||
12 | {% if users is iterable %} | ||
13 | {% for user in users %} | ||
14 | Hello {{ user }}! | ||
15 | {% endfor %} | ||
16 | {% else %} | ||
17 | {# users is probably a string #} | ||
18 | Hello {{ users }}! | ||
19 | {% endif %} | ||
diff --git a/vendor/twig/twig/doc/tests/null.rst b/vendor/twig/twig/doc/tests/null.rst deleted file mode 100644 index 44eec62e..00000000 --- a/vendor/twig/twig/doc/tests/null.rst +++ /dev/null | |||
@@ -1,12 +0,0 @@ | |||
1 | ``null`` | ||
2 | ======== | ||
3 | |||
4 | ``null`` returns ``true`` if the variable is ``null``: | ||
5 | |||
6 | .. code-block:: jinja | ||
7 | |||
8 | {{ var is null }} | ||
9 | |||
10 | .. note:: | ||
11 | |||
12 | ``none`` is an alias for ``null``. | ||
diff --git a/vendor/twig/twig/doc/tests/odd.rst b/vendor/twig/twig/doc/tests/odd.rst deleted file mode 100644 index 9eece777..00000000 --- a/vendor/twig/twig/doc/tests/odd.rst +++ /dev/null | |||
@@ -1,10 +0,0 @@ | |||
1 | ``odd`` | ||
2 | ======= | ||
3 | |||
4 | ``odd`` returns ``true`` if the given number is odd: | ||
5 | |||
6 | .. code-block:: jinja | ||
7 | |||
8 | {{ var is odd }} | ||
9 | |||
10 | .. seealso:: :doc:`even<../tests/even>` | ||
diff --git a/vendor/twig/twig/doc/tests/sameas.rst b/vendor/twig/twig/doc/tests/sameas.rst deleted file mode 100644 index efb15c35..00000000 --- a/vendor/twig/twig/doc/tests/sameas.rst +++ /dev/null | |||
@@ -1,11 +0,0 @@ | |||
1 | ``sameas`` | ||
2 | ========== | ||
3 | |||
4 | ``sameas`` checks if a variable points to the same memory address than another | ||
5 | variable: | ||
6 | |||
7 | .. code-block:: jinja | ||
8 | |||
9 | {% if foo.attribute is sameas(false) %} | ||
10 | the foo attribute really is the ``false`` PHP value | ||
11 | {% endif %} | ||