396 Commits

Author SHA1 Message Date
Fabien Potencier 26db550230 merged branch blaugueux/master (PR #736)
Commits
-------

c53a02d Fixed DateTimeZone support in date filter.

Discussion
----------

Fixed DateTimeZone support in date filter.

Now $date converted to a DateTime has a DateTimeZone in every case.

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

by fabpot at 2012-05-28T19:20:47Z

Can you add some unit tests to avoid regression to happen later? Thanks.

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

by blaugueux at 2012-05-29T07:52:58Z

@fabpot Here they are.

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

by fabpot at 2012-05-29T10:29:28Z

Great! Can you add a note in the CHANGELOG file and then squash your commit before I merge? Thanks.

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

by blaugueux at 2012-05-29T12:52:22Z

Changelog added. First squash of my life, i cannot say if it's good :(

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

by stof at 2012-05-29T12:55:26Z

it is not. you merged your remote branch instead of forcing the push

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

by blaugueux at 2012-05-29T17:12:05Z

Ok @stof, thanks for your help. I think it's good now.

@fabpot Is it ok for you ?
2012-05-29 20:09:42 +02:00
Benjamin Laugueux c53a02de1a Fixed DateTimeZone support in date filter.
Prevents the DateTime object to be updated when changing the DateTimeZone.

Unit tests added.

Updated changelog.
2012-05-29 19:09:23 +02:00
Maarten de Keizer f0a0036892 Add abs filter
including unit test and documentation
2012-05-28 22:27:26 +02:00
Fabien Potencier 573a360971 fixed a regression when using a number in template attributes (closes #733) 2012-05-23 07:50:43 +02:00
Fabien Potencier 7f06c12c53 fixed tests for PHP 5.2 2012-05-16 17:00:05 +02:00
Fabien Potencier 8ec73cf475 fixed a regression introduced by aa6b835816 2012-05-16 16:19:00 +02:00
Fabien Potencier 52cc3817a8 added tests for bitwise operators 2012-05-08 08:30:42 +02:00
Christophe Coevoet a16446913a Added a failing test demonstrating the bug with DateTime and timezones
PHP DateTime objects are mutable so changing the timezone when displaying
it affects the following code whereas it does not occur for other
supported formats.
2012-05-03 22:20:20 +02:00
Fabien Potencier 635bafd46e fixed embed compilation when used more than once in a template (closes #714) 2012-04-27 09:16:28 +02:00
Fabien Potencier 75d97b4a27 made the autoescape tag argument optional (defaults to 'html') 2012-04-25 18:22:58 +02:00
Fabien Potencier 9ecf090ae8 simplified usage of the autoescape tag; the only argument is now the escaping strategy or false 2012-04-25 07:30:52 +02:00
Fabien Potencier 1f00c33acd added a way to dynamically change the auto-escaping strategy according to the template filename 2012-04-25 07:12:38 +02:00
Fabien Potencier 49c5d51eac merged branch fabpot/inline (PR #709)
Commits
-------

07f13df fixed typo
0f623a1 added the parent as an argument to the embed tag (removes the need to use extends)
fab21d8 renamed the inline tag to embed
1b54780 tweaked examples
955726a changed the inline examples to not use even/odd to avoid confustion
fb07f3a renamed indice to index
fafde80 added more info in the docs
2fa8224 added the inline tag

Discussion
----------

added the inline tag

At Sensio, we manage websites with many mostly-static pages that share almost the same structure (with different content of course), but with some subtle differences. After trying many different possibilities (external templates, inheritance, macros, and some ugly ones that I won't even tell you about ;)) to structure our templates, we came to the conclusion that we needed a new concept.

This new concept is implemented via a new tag, `inline`, which I want to include in Twig 1.8 (not for the upcoming 1.7 which is due this week). But before merging this code into master, I want to gather some feedback from the community. One of my questions being: Will you use this new possibility?

I won't tell you more here as the tag is fully documented in the diff.

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

by oojacoboo at 2012-04-23T17:58:59Z

odd/even?  What other potential uses do you see?  I think I can see a couple, but generally speaking, unless it's a content site (ie. blog), the odd/even isn't very useful.  Reusing blocks even with minor customizations on a per page level is highly needed for our development processes, but an odd/even scenario is certainly not.

Maybe I'm missing something here.  What about passing attributes to a block or something?

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

by fabpot at 2012-04-23T18:02:51Z

@oojacoboo odd/even is just an example. Of course, this is not a real use case, this was just an attempt to find an example.

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

by stof at 2012-04-23T18:03:53Z

@oojacoboo there is no reference to odd/even in the code, only in the doc

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

by simensen at 2012-04-23T18:20:10Z

I think that it would be useful in some cases. I can't think of any places I could use it *right now* but I know I've had to jump through hoops on more than a few occasions to get things to work correctly. Being able to keep functionality like this in mind at the design stage might have made things easier in a few of those cases.

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

by lyrixx at 2012-04-23T18:21:34Z

I think it's a good idea.

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

by tyomo4ka at 2012-04-23T18:25:07Z

I think it will be great. Each time when I need to include templat that simple extends another one and replace one small block I think: "Why I should to create new template for it?". Thanks, @fabpot

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

by bmatzner at 2012-04-23T18:28:23Z

Right on. +1

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

by cranberyxl at 2012-04-23T18:40:17Z

I believe the concept is a good one, but the example using even and odd will confuse frontend developers because it's usually used in the context of loops and table striping. even changing it to styleA.twig and styleB.twig would be more understandable.

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

by lyrixx at 2012-04-23T19:01:32Z

@cranberyxl  +1

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

by fabpot at 2012-04-23T19:24:21Z

ok, I've just changed the examples to not used even/odd.

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

by jorgelbg at 2012-04-23T19:27:53Z

I think that the inline tag is a valid concept, but still I can't get it landed on a real case!

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

by sirowl at 2012-04-23T19:35:07Z

As a webdesigner with a steady foundation in CSS I find the term inline very confusing, I had to consult a developer to actually understand what was the idea of the tag as I so heavily associated it with CSS's terminology of inline.
The CSS terminololigy got me on the wrong track in terms of what the tag was supposed to be used for.
I have no good suggestion for a name for it, but inline could probably get very confusing for a lot of webdesigners making use of twig.

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

by fabpot at 2012-04-23T19:41:48Z

@sirowl `inline` was the best term I could come up with but I'm open to any other suggestion.

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

by sirowl at 2012-04-23T19:47:30Z

The best I could come up with is embed, as it is an embedded document of sorts.. or something along those lines.

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

by bschussek at 2012-04-23T19:48:54Z

I like `embed`.

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

by bmatzner at 2012-04-23T19:55:37Z

Hi Fabien, inline makes sense to me, although I understand @sirowl's comment, but I even find the concept quite comparable to the CSS display:block/display:inline logic. @sirowl's suggestion of "embed" would be just as fine, as it's just a matter of learning what this particular tag refers to. The ambiguation against the import tag is probably the most crucial, explaining the advantages of "inline" (or whatever) over doing an import

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

by Baachi at 2012-04-23T20:03:26Z

I lke ```embed```, too.

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

by Nami-Doc at 2012-04-23T20:11:42Z

I like `embed`, but `inline` is fine too.

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

by tijuan at 2012-04-23T20:36:39Z

I like the feature
I like embed

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

by pulse00 at 2012-04-23T20:56:41Z

+1 for `embed`

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

by mickaelandrieu at 2012-04-24T00:35:01Z

I like embed, inline for me is an CSS behavior

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

by matheo at 2012-04-24T04:29:05Z

+1 for `embed`

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

by fabpot at 2012-04-24T05:35:06Z

I've just renamed the `inline` tag to `embed`.

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

by sirowl at 2012-04-24T06:55:17Z

@fabpot agreed, much more clear to me now. Look forward to using it.

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

by pvanliefland at 2012-04-24T07:20:35Z

I would like to use this feature as well

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

by tristanbes at 2012-04-24T07:38:57Z

So if I take another example, to help me understand better

I do have a common structure stated as follows :
   ```
 <body>
    <div class="row">
        <div class="main">
            <div id="homepage">
               {% block content %}
            </div>
       </div>
    </div>
    </body>
```
Let's say for the other pages, the `id="homepage"` is replaced by `id="innerPage"` `id="specialLayout"`

So far I created 3 base template with those changes, so with the new `embed` tag, does this concept fits here or I misunderstood the function of `embed` feature ?

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

by ruian at 2012-04-24T07:47:38Z

@tristanbes with `embed`, you can "include" another twig template and modify directly these differents `block`.
If you want to understand you can read `embed` tests https://github.com/fabpot/Twig/blob/0f623a11129ce28a897dbd5b812241d8b3ea9730/test/Twig/Tests/Fixtures/tags/embed/

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

by samuelmichaud at 2012-04-24T08:02:42Z

Yes ! I will definitely use this ! Thanks

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

by michelsalib at 2012-04-24T08:05:47Z

As @samuelmichaud said we have some uses cases (such as menu generation, breadcrumbs or quick action embedding). So this feature makes total sense.
2012-04-24 13:09:06 +02:00
Fabien Potencier 07f13dfcb8 fixed typo 2012-04-24 10:36:52 +02:00
Fabien Potencier 0f623a1112 added the parent as an argument to the embed tag (removes the need to use extends) 2012-04-24 08:31:52 +02:00
Fabien Potencier fab21d8a76 renamed the inline tag to embed 2012-04-24 07:35:39 +02:00
Martin Hasoň 623fac04be Fixed test for "dump" function if xdebug>2.2 is loaded 2012-04-23 23:34:04 +02:00
Fabien Potencier 2fa8224be4 added the inline tag 2012-04-23 19:39:43 +02:00
Fabien Potencier cf73b64556 added unit tests to prove the issue with the current introspection exception code 2012-04-21 19:43:26 +02:00
Fabien Potencier b20a74868b removed the array test and rename the traversable test to iterable 2012-04-20 20:12:41 +02:00
Fabien Potencier da9d2eb834 merged branch Seldaek/isarray (PR #700)
Commits
-------

c88f8e5 Micro-optimizations
70cca66 Simplify code
d78ed66 Add traversable test
5fd2f98 Add docs
b2e1675 Add is array test

Discussion
----------

is array/traversable tests

It's sometimes necessary to display arbitrary data to be able to know if we should recurse or not.

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

by stof at 2012-04-13T12:13:11Z

I'm not sure about the need for ``is array``. All Twig functions related to arrays also support traversable objects

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

by Seldaek at 2012-04-13T12:23:32Z

Well, I like to have both for explicitness and also because I would try is array without looking at the docs, and I don't think it's right to make is array return true for traversables.

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

by fabpot at 2012-04-20T09:38:33Z

One of the main goal of Twig is to abstract the "real" type of the variables. We have already discussed the introduction of many tests like these ones and I have always rejected them.

As many people seems to have a need for them (especially for arrays), I would consider adding the `traversable` test. But as @stof said, Twig tries to blur the difference between traversable objects and arrays, so I'm -1 for adding another test for arrays.

`traversable` is probably not the best name for web designers but I don't know what else we can use here.

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

by stof at 2012-04-20T09:41:05Z

In Jinja, there is a built-in test for this using ``iterable``: http://jinja.pocoo.org/docs/templates/#builtin-tests

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

by Seldaek at 2012-04-20T09:41:32Z

Ok. I can live with dropping the array test. Now for the name,  `is forloopable`? I am kind of at a loss as well apart from traversable. I think if it's clearly mentioned in the docs it's ok.

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

by Seldaek at 2012-04-20T09:52:12Z

iterable sounds ok to me, but just as confusing as traversable I guess to the unknowing. A sidenote, if I update the PR, any objection to adding the "undefined" test as well?

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

by fabpot at 2012-04-20T10:01:27Z

Let's use `iterable` as this is what Jinja already uses. Why would you want an `undefined` test as we already have `defined`? (`if foo is not defined` works well enough)

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

by Seldaek at 2012-04-20T11:16:26Z

I just saw jinja had it on that page, and I thought why not add it too? Still not a huge fan of the "not" for negation.

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

by fabpot at 2012-04-20T12:18:17Z

Well, let's first finish the `iterable` test first and let's discuss `undefined` in another PR or issue.

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

by fabpot at 2012-04-20T17:10:28Z

I can finish the PR is you want.

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

by Seldaek at 2012-04-20T17:13:11Z

If you like sure, it's mostly deleting code anyway. I just have to finish some work stuff now..
2012-04-20 20:09:05 +02:00
Fabien Potencier 944a014636 renamed preserve_safety to preserves_safety to be consisten with needs_context and needs_environment 2012-04-20 19:04:30 +02:00
Fabien Potencier 43245cbd34 merged branch stof/preserve_safe (PR #684)
Commits
-------

0cbf5a0 Added an option to mark filters as preserving the safeness

Discussion
----------

Added an option to mark filters as preserving the safeness

Closes #678

I haven't written a test for this yet as I don't know how to provide a stub filter (as none of the core filters use this option) for the setup of the testsuite.

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

by fabpot at 2012-04-07T20:15:36Z

@stof: Can you also add some information in the phpdoc with an example so that people understand more easily when and why you would want to use this new option? Thanks.

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

by fabpot at 2012-04-07T20:16:36Z

Also, adding a unit test that demonstrates the bug you had in #678 would be good.

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

by stof at 2012-04-20T08:33:58Z

@fabpot none of the core filters are using this options, so what is the right way to add a test ?

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

by fabpot at 2012-04-20T08:36:26Z

by defining a filter in the test that uses it.

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

by stof at 2012-04-20T08:39:06Z

but is it possible to register a filter from the tests with the custom stuff used by Twig ?

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

by fabpot at 2012-04-20T08:48:06Z

in integrationTest.php, we already have quite a few functions and filters registered. I would just be a matter of adding a new one.

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

by stof at 2012-04-20T16:17:01Z

@fabpot renamed, tested and squashed
2012-04-20 19:02:27 +02:00
Christophe Coevoet 0cbf5a004c Added an option to mark filters as preserving the safeness
Closes #678
2012-04-20 16:23:51 +02:00
Fabien Potencier 0add6e2377 added an error when defining two blocks with the same name in a template (closes #701) 2012-04-20 11:17:22 +02:00
Fabien Potencier 6cf147dc99 added some missing tests for nested blocks 2012-04-20 10:56:03 +02:00
Jordi Boggiano d78ed667ad Add traversable test 2012-04-13 13:05:17 +02:00
Jordi Boggiano b2e1675f0c Add is array test 2012-04-13 12:57:54 +02:00
Fabien Potencier 4e28408ce1 fixed a PHP notice when trying to access a key on a non-object/array variable 2012-04-12 14:36:25 +02:00
Tobias Schultze 27064127ad fixed random function when charset is null 2012-04-09 09:26:53 +02:00
Fabien Potencier 1b47b40104 enhanced error reporting when the template file is an instance of SplFileInfo 2012-04-08 14:12:00 +02:00
Fabien Potencier c6bf195e21 added a unit test to demonstrate the need to pass blocks when calling renderBlock|displayBlock 2012-04-07 22:40:59 +02:00
Fabien Potencier f2f1f32b41 added Twig_Environment::mergeGlobals() 2012-04-03 19:13:43 +02:00
Fabien Potencier 3398b38cf0 fixed a regression when a template only extends another one without defining any blocks (closes #683) 2012-04-03 19:13:30 +02:00
Fabien Potencier 8f242ca858 made usage of mergeContextWithGlobals in macros 2012-04-03 09:45:11 +02:00
Fabien Potencier e9c1433a99 renamed a test 2012-04-03 09:07:04 +02:00
Fabien Potencier 1f6e640d96 added compilation checks to avoid misuses of the sandbox tag 2012-04-03 09:03:41 +02:00
Fabien Potencier 2055f567f9 fixed Twig unit tests when a template must throw an exception 2012-04-03 08:59:31 +02:00
Fabien Potencier 3f962ba89e enhance error reporting in Twig unit tests 2012-04-03 08:49:35 +02:00
Fabien Potencier 1e9a1ae0be optimized parent template creation when the template does not use dynamic inheritance 2012-03-31 15:21:57 +02:00
Fabien Potencier 90931b0a27 fixed compilation of numeric values used in templates when using a locale where the decimal separator is not a dot 2012-03-19 00:08:15 +01:00
Fabien Potencier 96632fb481 simplified tests 2012-03-18 03:33:46 +01:00
Fabien Potencier 49ee8d6e41 made the strategy used to guess the real template file name and line number in exception messages much faster and more accurate (refs #647) 2012-03-18 03:33:46 +01:00
Fabien Potencier 50e73b20cb fixed sandbox mode when used with inheritance (closes #656)
The checkSecurity() method must be called by each template as we are not
using inheritance.
2012-03-17 17:11:40 +01:00
Fabien Potencier c0a9c8bb3e added preserveKeys support for the slice filter (closes #669) 2012-03-17 12:42:13 +01:00
Fabien Potencier a3310e75a1 fixed the date filter when a DateTime instance is passed with a specific timezone (closes #660) 2012-03-15 17:24:51 +01:00
Christophe Coevoet d942d11f2f Added a trim filter
Closes #634
2012-03-12 14:56:44 +01:00
Fabien Potencier 9573f2213c added some unit tests 2012-02-28 23:19:50 +01:00
Jordi Boggiano e4590d0cd8 Avoid creating unnecessary Twig_Markup instances, allows testing for falsiness of empty output 2012-02-17 15:56:34 +01:00
Fabien Potencier 4478816e41 removed usage of assertInstanceOf as if is not available when using PHPUnit on PHP 5.2.* 2012-02-06 18:16:12 +01:00