Commit Graph

826 Commits

Author SHA1 Message Date
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 acd3663062 updated CHANGELOG 2011-08-27 11:11:38 +02:00
Fabien Potencier b5b25334fe merged branch jturmel/master (PR #403)
Commits
-------

c2c01de Add bitwise operators to core

Discussion
----------

Added bitwise operators (and, xor, or) to core

* Added bitwise operators (and, xor, or) to core

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

by nikic at 2011/08/02 21:02:14 -0700

I'm not sure bitwise ops really belong into a templateing language...

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

by jturmel at 2011/08/02 21:06:02 -0700

That's a general statement to make without knowing why it was implemented at all... no one is forced to use them, however when you do need them, them not being available makes you have relegate something that should be in the view in the particular case I needed them, to be done in a controller instead, which would be quite a bit nastier in my case.

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

by nikic at 2011/08/02 23:23:30 -0700

@jturmel: I do not doubt that there are some cases where bitwise operations are useful. I can't think of one of the top of my head, though I imagine that it could be useful when using bitwise right management or something like that. What I was trying to say is, that I don't really believe that there are enough significant use cases for bitwise ops to justify adding them to the core (I know, "You Don't Have To Use It!", but it isn't good to clutter the core with features nearly no one uses). Maybe you could give an example of what you needed them for?

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

by jturmel at 2011/08/02 23:41:36 -0700

It would be one thing if I was implementing some operator that didn't normally exist in PHP itself, but it seems a bit odd to even say that it's cluttering it up, it's 3 lines of code that add 3 missing standard operators from PHP.

Simply put, I have an object that gets passed to the template that has many properties, these properties are bit values, I need to do checks on them to select/deselect various checkboxes in a grid... this is the cleanest way to do it without mudding up controller code with view logic.

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

by jalliot at 2011/08/03 01:42:56 -0700

Why not adding ``<<`` and ``>>`` then @jturmel?
I don't have a particular use case but I think that if Twig includes those 3 operators, it should also support these 2 to be "complete". What do you think?

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

by jturmel at 2011/08/03 06:07:46 -0700

Of course, if you guys think we need the shifting operators as well, we can... but modifying data in the view seems much less practical than the one's I added, although I did miss NOT.

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

by jalliot at 2011/08/03 06:16:38 -0700

I forgot about ``~`` but sure it should be included as well.
As for ``<<`` and ``>>``, they could also be used for verifying grant access for example in some implementations.
``{% if some_var << some_other_var & 1 %}``
2011-08-27 11:10:29 +02:00
Fabien Potencier 4c1b45204b replace file_exists() by is_file() as this is semantically more correct (we don't want dirs to match) 2011-08-27 09:56:45 +02:00
Fabien Potencier 46c258d29d replaced usage of array_replace by array_merge (for 5.2 compatibility) 2011-08-27 09:46:10 +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 bdf8e69ab0 switcher PHPUnit colors to true 2011-08-24 12:15:02 +02:00
Fabien Potencier 7cd097391d merged branch videlalvaro/patch-1 (PR #419)
Commits
-------

0ef1cb0 Edited doc/templates.rst via GitHub

Discussion
----------

Edited doc/templates.rst via GitHub

I fixed a typo: Variables can by for Variables can be
2011-08-18 19:16:29 +02:00
Alvaro Videla 0ef1cb0c85 Edited doc/templates.rst via GitHub 2011-08-16 16:27:40 +03: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 dbeede7900 moved some logic to the constructor (that's allows visitors to have the real node that will be compiled) 2011-08-07 21:32:22 +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
Fabien Potencier 5233631af8 merged branch nikic/doNotUseNameNodeForFuncNames (PR #410)
Commits
-------

da4d964 Do not use Node_Expression_Name for function names, just use strings for those

Discussion
----------

Do not use Node_Expression_Name for function names

This patch remove the use of Node_Expression_Name for function names and instead uses normal strings for those. This is mainly to prevent problems with static analysis (e.g. using a loop() function would have triggered with_loop), but it also slightly reduces complexity.
2011-08-07 09:37:28 +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 652ac774d6 removed obsolete code 2011-08-06 10:56:03 +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 801f3e638c removed the possibility to use the extends tag from a block (as it is semantically incorrect and it probably does not work as you expect it to in this case) 2011-08-06 09:16:10 +02:00
Fabien Potencier c201137f21 moved Template::getParent() logic to the base class 2011-08-06 09:09:18 +02:00
Fabien Potencier 46eccb9ab5 added documentation for previous merge 2011-08-06 08:44:04 +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 e6dde1d6df added GtkSourceView support in doc 2011-08-06 08:16:57 +02:00
Fabien Potencier d55ca98bc3 merged branch igorw/recipes-highlight (PR #405)
Commits
-------

0580f19 fix highlighting of snippet in recipes doc

Discussion
----------

fix highlighting of snippet in recipes doc
2011-08-04 10:29:19 +02:00
Igor Wiedler 0580f192ca fix highlighting of snippet in recipes doc 2011-07-31 02:25:43 +02:00
Fabien Potencier f918219cf9 bumped version to 1.2.0-DEV 2011-07-30 10:10:16 +02:00
Fabien Potencier 396435ecd0 prepared 1.1.2 released v1.1.2 2011-07-30 09:53:59 +02:00
Fabien Potencier 9b73026e91 fixed Parser bug when a child node is null 2011-07-28 14:32:45 +02:00
Fabien Potencier ef485402e0 fixed Parser bug 2011-07-28 14:32:07 +02:00
Josh Turmel c2c01dedf8 Add bitwise operators to core
* Added bitwise operators (and, xor, or) to core
2011-07-27 23:06:42 -05:00
Fabien Potencier c7be5242c4 fixed unit test, updated CHANGELOG 2011-07-27 14:25:09 +02:00
Fabien Potencier 945579a8f6 merged branch JEDIBC/master (PR #401)
Commits
-------

755ea99 Correction of a BC break with json_encode and PHP 5.2.x

Discussion
----------

BC break with json_encode and php 5.2.x

Hi,

json_encode on php 5.2.x doesn't take the $options parameter wich result in a warning and the function return nothing.

Cheers.
2011-07-27 14:23:49 +02:00
JEDIBC 755ea99bd4 Correction of a BC break with json_encode and PHP 5.2.x 2011-07-27 12:25:24 +02:00
Fabien Potencier 26757ab327 simplified code for previous merge/commits 2011-07-27 11:23:08 +02:00
Fabien Potencier 21c96d1ef4 changed previous commit to preserve better BC 2011-07-27 10:12:28 +02:00
Fabien Potencier 56e2ca75fa fixed CS on template output 2011-07-27 09:44:25 +02:00
Fabien Potencier b4e9c0f6d8 updated CHANGELOG 2011-07-27 09:36:26 +02:00
Fabien Potencier 1f233ce06b fixed previous merge 2011-07-27 09:34:28 +02:00
Fabien Potencier a6726c7ddd merged branch hason/optimizer (PR #399)
Commits
-------

3c5c512 fixed optimization for rendering blocks with variable name

Discussion
----------

Fixed bug in optimization
2011-07-27 09:33:41 +02:00
Martin Hason 3c5c51260e fixed optimization for rendering blocks with variable name 2011-07-27 08:19:59 +02:00
Fabien Potencier d67832ea5d updated CHANGELOG 2011-07-26 17:36:37 +02:00
Fabien Potencier 74d2f76c23 fixed inherited templates when an empty body 2011-07-26 17:32:54 +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