Commit Graph

519 Commits

Author SHA1 Message Date
Fabien Potencier 29534aada8 fixed the "defined" test and the "default" filter 2011-10-27 18:26:17 +02:00
Fabien Potencier 52a8afd67c added more unit tests (some do not pass... yet) 2011-10-26 22:23:21 +02:00
Fabien Potencier 5e290cbb4d fixed deep nested defined tests 2011-10-26 11:20:38 +02:00
Fabien Potencier 996128dfce added a way to change Twig's options when running integration tests (updated tests accordingly) 2011-10-26 09:29:16 +02:00
Fabien Potencier a41c6e21d2 added more unit tests 2011-10-17 01:16:34 +02:00
Fabien Potencier dd0546eaa9 refactored Twig_Node_Expression_GetAttr for better readability of compiled templates 2011-10-08 14:27:18 +02:00
Fabien Potencier a68425118d optimized variable access when possible 2011-10-08 14:27:18 +02:00
Fabien Potencier bd5687ee10 made an optimization by removing array_merge usage 2011-10-08 14:27:18 +02:00
Fabien Potencier 737c29a613 fixed a unit test for PHPUnit 3.6 2011-10-03 23:08:58 +02:00
Fabien Potencier 3e66e3e9c0 added an optimization for simple variables output 2011-09-30 17:11:02 +02:00
Fabien Potencier e0cd76614f fixed hardcoded name escaping 2011-09-30 17:10:56 +02:00
Fabien Potencier b058160e97 removed usage of PHP 5.3 __DIR__ 2011-09-29 17:16:55 +02:00
Fabien Potencier a188f97040 fixed unit test broken by previous merge 2011-09-29 16:44:28 +02:00
Fabien Potencier f96d8d8219 added an optimization for the parent() function 2011-09-27 14:17:34 +02:00
Fabien Potencier 46080c90ea added the possibility to force the escaping of a string already marked as safe 2011-09-22 21:57:09 +02:00
Fabien Potencier d101a05976 added traits support for the parent function 2011-09-22 14:06:20 +02:00
Fabien Potencier 56f82db1a1 allowed empty templates to be used as traits 2011-09-22 11:51:48 +02:00
Fabien Potencier 4ea393adb0 added an exception for unclosed tags 2011-09-06 13:45:10 +02:00
Max Romanovsky 4b95621c0f Added: Countable interface support for empty test 2011-09-04 15:13:42 +03:00
Fabien Potencier cbbeb71e85 added more unit tests 2011-09-01 10:54:15 +02:00
Fabien Potencier 9c2065facc removed some loop variable when using an if statement in a for loop 2011-09-01 10:41:03 +02:00
Fabien Potencier f20450d13d fixed algorithm that determines if a template using inheritance is valid (no output between block definitions) 2011-09-01 08:13:26 +02:00
Fabien Potencier 598c70ba39 renamed a class in unit test to avoid confusion with PHPStorm 2011-08-31 11:10:12 +02:00
Fabien Potencier 4402ee2c1d added support for an array of templates to the "extends" tag 2011-08-27 20:34:02 +02:00
Fabien Potencier c56dd32f57 added a way to ignore a missing template when using the "include" tag 2011-08-27 14:02:05 +02:00
Fabien Potencier 35a8a0d155 added support for an array of templates to the include tag 2011-08-27 13:58:36 +02:00
Fabien Potencier c609060f94 added the "attribute" function to allow getting dynamic attributes on variables 2011-08-27 09:46:06 +02:00
Fabien Potencier 517c233679 added Twig_Loader_Chain 2011-08-24 12:56:57 +02:00
Fabien Potencier ae08b28787 renamed a test file 2011-08-24 12:54:04 +02:00
Fabien Potencier d6ebae56b7 added Twig_LoaderArray::setTemplate() 2011-08-24 12:17:36 +02:00
Fabien Potencier bac4974e25 changed unit tests so that they work for PHP 5.2 2011-08-08 23:00:24 +02:00
Fabien Potencier 7b5e5969a2 added an optimization for the set tag when used to capture a large chunk of static text 2011-08-07 19:08:15 +02:00
Fabien Potencier fd0573103e removed unneeded implementation of Template::getTemplateName() 2011-08-07 17:26:48 +02:00
Fabien Potencier 112a16bfde changed name regex to allow more characters (the same as PHP - works for blocks, tags, functions, filters, and macros - closes #376) 2011-08-07 10:07:35 +02:00
nikic da4d964047 Do not use Node_Expression_Name for function names, just use strings for those 2011-08-06 11:21:23 +02:00
Fabien Potencier 26d8aff746 refactored code 2011-08-06 10:44:55 +02:00
Fabien Potencier 440d13753a added the possibility to test for exceptions in integration tests 2011-08-06 09:49:38 +02:00
Fabien Potencier c201137f21 moved Template::getParent() logic to the base class 2011-08-06 09:09:18 +02:00
Fabien Potencier d306dabea3 fixed unit tests for previous merge 2011-08-06 08:35:41 +02:00
Fabien Potencier 1202b5fbe7 merged branch kotas/master (PR #362)
Commits
-------

f5b9df9 added `if` modifier support to for loop like {% for k in v if k is odd %}

Discussion
----------

[1.2] added `if` modifier support to for loop

Hi.

I'm one of Twig users who love it so much. :)

I've made a patch for adding `if` modifier support to `for` loop in Twig.

Example:
<pre>
{% for n in range(0, 5) if n is odd %}
  {{ n }}
{% endfor %}
</pre>

Output:
<pre>
1
3
5
</pre>

This idea comes from Python's list comprehensions. (like `[n for n in range(0,6) if n % 2 == 1]`)

Here is another example.

Before:
<pre>
{% set no_items = true %}
{% for item in items %}
  {% if item.available %}
    {% set no_items = false %}
    {{ item.name }}
  {% endif %}
{% endfor %}
{% if no_items %}
  No items available.
{% endif %}
</pre>

After:
<pre>
{% for item in items if item.available %}
  {{ item.name }}
{% else %}
  No items available.
{% endfor %}
</pre>

I hope you like it. But If not, just ignore this request. :)

Thanks.

---------------------------------------------------------------------------

by fabpot at 2011/06/24 01:33:33 -0700

I like it! I will schedule it for inclusion in Twig 1.2. Thanks.

---------------------------------------------------------------------------

by hhamon at 2011/06/26 16:43:26 -0700

+1

---------------------------------------------------------------------------

by nikic at 2011/06/27 00:42:14 -0700

I think the idea per se is interesting. But I just checked all Twig templates in my whole codebase and couldn't find any use for it. What was your practical use for this feature @kotas?

---------------------------------------------------------------------------

by kotas at 2011/06/27 01:52:48 -0700

@nikic My practical use is shown as the second example in the body of this pull request.

Sometimes you need to "filter" an array by seeing its element's property like "item.available" or by some condition like "item.price >= 500".

To do this, in the current version of Twig, you have to write "for" and "if" as nested scopes. And if you want to write {% else %} of the "for" loop, you have to make a temporary variable to see if all elements are skipped.

I think this feature is not essential, but makes templates clean.

---------------------------------------------------------------------------

by nikic at 2011/06/27 06:23:24 -0700

The thing about `else` seems plausible. +1

---------------------------------------------------------------------------

by chucktrukk at 2011/08/02 17:39:16 -0700

Also +1. that makes some very clean template code.
2011-08-06 08:34:15 +02:00
Fabien Potencier 26757ab327 simplified code for previous merge/commits 2011-07-27 11:23:08 +02:00
Martin Hason 3c5c51260e fixed optimization for rendering blocks with variable name 2011-07-27 08:19:59 +02:00
Fabien Potencier 6e97162de4 merged branch netzhuffle/master (PR #396)
Commits
-------

7b154d6 Switched a tab to four spaces
29d3cb2 Added testcase for #395
4fc7a8d Merge remote-tracking branch 'upstream/master'
c890cf2 Fixed existing tests
9822ac4 Changed Module.php to pass existing tests
fab8c72 fixed issue #395

Discussion
----------

Fix for issue #395

Fix for #395
I hope you can use it.

---------------------------------------------------------------------------

by fabpot at 2011/07/25 00:07:50 -0700

Can you add some unit tests?

---------------------------------------------------------------------------

by netzhuffle at 2011/07/25 13:57:55 -0700

Here you are.
2011-07-26 17:30:32 +02:00
Fabien Potencier 3ae35949ac removed comment 2011-07-26 08:07:02 +02:00
Fabien Potencier 7f5390a6a7 fixed compilation of templates when the body of a child template is not empty 2011-07-26 08:02:51 +02:00
Jannis Grimm 29d3cb2b91 Added testcase for #395 2011-07-25 22:55:53 +02:00
Jannis Grimm 4fc7a8d21b Merge remote-tracking branch 'upstream/master' 2011-07-25 22:32:17 +02:00
Jannis Grimm c890cf2b64 Fixed existing tests 2011-07-25 22:29:47 +02:00
Fabien Potencier ea83972869 fixed output when a macro throws an exception 2011-07-25 18:12:59 +02:00
Fabien Potencier 6783d5812b fixed a parsing problem when a large chunk of text is enclosed in a comment tag 2011-07-25 15:51:24 +02:00