Commit Graph

643 Commits

Author SHA1 Message Date
Fabien Potencier bc30d9b7e2 merged branch Tobion/buildquery (PR #1009)
This PR was squashed before being merged into the master branch (closes #1009).

Commits
-------

fcf9525 let url_encode filter also accept array of query parameters

Discussion
----------

let url_encode filter also accept array of query parameters

BC break: no
feature addition: yes
tests pass: yes
documentation: yes

This is also supported in Jinja and so it's consistent: [jinja urlencode](http://modular.math.washington.edu/home/wstein/www/home/bjarke/sage-4.4.4/local/LIB/python/site-packages/Jinja-1.2-py2.6-linux-x86_64.egg/docs/html/builtins.html)
2013-02-26 14:03:39 +01:00
Tobias Schultze fcf9525dc3 let url_encode filter also accept array of query parameters 2013-02-26 14:03:39 +01:00
Fabien Potencier 7b11c6fd5e Merge remote-tracking branch 'lyrixx/feat-batch-ceil'
* lyrixx/feat-batch-ceil:
  Ceil the size in batch filter

Conflicts:
	test/Twig/Tests/Fixtures/filters/batch.test
2013-02-26 14:02:07 +01:00
Grégoire Pineau 50f5271ef0 Ceil the size in batch filter 2013-02-22 16:02:01 +01:00
Luiz “Felds” Liscia ccf3cd1c81 optimize batch function and add tests 2013-02-21 12:11:54 -03:00
Fabien Potencier a50bc8c95b added a batch filter 2013-02-21 07:38:58 +01:00
Fabien Potencier ac86c6368c changed an exception to be consistent with other ones (and also to better help debugging problems) 2013-02-17 20:51:08 +01:00
Fabien Potencier b5438c2745 added some unit tests for previous merge 2013-02-08 21:59:58 +01:00
Fabien Potencier fa0d1eec43 added some missing tests 2013-02-08 21:53:22 +01:00
Fabien Potencier 8b569e49a1 added a note about how to use quotes in strings (closes #973) 2013-02-08 19:58:08 +01:00
Jesper Ek 667b274b0d Added unit test for bug when calling getGlobals() before addGlobal() on Twig_Environment. 2013-02-08 00:08:43 +01:00
Fabien Potencier f8d4db4107 added the first and last filters (closes #951) 2013-01-26 16:59:11 +01:00
Fabien Potencier 5218db7796 added an exception when trying to render a template when no loader has been set (closes #975) 2013-01-26 16:09:24 +01:00
Fabien Potencier 19053ab492 merged branch markstory/object-constants (PR #961)
This PR was merged into the master branch.

Commits
-------

8bb953c Fix doc block for twig_constant.
c7dafb7 Update documentation for constant()
cb921ce Implement getting constants from objects.
998b367 Add tests for getting constants from instances.

Discussion
----------

Object constants

Implement the changes discussed in #954.
2013-01-15 20:54:16 +01:00
Fabien Potencier 5abad16081 relaxed globals management to avoid a BC break (closes #965) 2013-01-15 20:48:33 +01:00
Mark Story 998b367c0c Add tests for getting constants from instances. 2013-01-10 23:37:47 -05:00
Fabien Potencier d10ebfa3d4 added support for {{ some_string[:2] }} (closes #952) 2013-01-08 15:19:19 +01:00
Fabien Potencier 56bef3fa37 forbid mixed usage of raw/verbatim 2013-01-08 13:28:45 +01:00
Fabien Potencier cd4ab0fde6 renamed the raw tag to verbatim to avoid confusion with the raw filter 2013-01-05 08:57:34 +01:00
Fabien Potencier 720b71a0b8 fixed tests on PHP 5.2 2013-01-04 22:43:10 +01:00
Fabien Potencier 84504c3c39 fixed tests on PHP 5.2 2013-01-04 22:34:22 +01:00
Fabien Potencier e48b1f3bdf fixed registration of tests and functions as anonymous functions (closes #946) 2013-01-04 22:20:09 +01:00
dantleech 9f5fa532ef Upgrade problem 2013-01-02 16:57:55 +01:00
Fabien Potencier 2450f79a0e changed the way globals behave to be more BC with 1.11 and to avoid speed problems at runtime introduced in 4487387 (closes #932)
* Globals are now managed by themselves, independently of other elements
  contained in extensions

* A global variable value can now be changed after the runtime has been
  initialized (to be more BC with the way Twig 1.11 works)

* Extensions are not initialized anymore when rendering a template that
  is already in the cache (like in Twig 1.11)
2012-12-27 11:00:35 +01:00
Fabien Potencier a65e7e4e2e merged branch fabpot/render-function (PR #926)
This PR was merged into the master branch.

Commits
-------

f4f88a5 added an include function

Discussion
----------

added an include function

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

by stof at 2012-12-09T14:12:25Z

I see an issue with this naming: it will confuse Symfony users because of the ``render`` tag doing something different than the ``render`` function. And it will force to break BC for Silex users where the subrequest logic is using a ``render`` function right now

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

by fabpot at 2012-12-10T12:49:57Z

@stof: I know about the possible confusion. For Silex, as it is not stable yet, we don't need to keep BC. And I don't have any other better name. What I want to introduce next is a `render_request` function in both Silex and Symfony (which will do the same as the current render tag in Symfony and the render function in Silex).

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

by Taluu at 2012-12-10T14:13:31Z

Hi,

I may be absent-minded, but I don't really understand the difference between `render` function and the `include` tag... ?

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

by fabpot at 2012-12-10T14:16:09Z

@Taluu Using a function allows you to do whatever you want with the output (which is not possible with a tag), like a simple:

```jinja
{{ set content = render('some_template') }}
```

Also, semantically, using a tag to output some content is less correct.

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

by vicb at 2012-12-10T14:18:17Z

could it be named `include` ?

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

by tcz at 2012-12-10T14:18:40Z

I agree that it's confusing for Symfony users. It is the same as raw filter and raw tag. I would prefer execute as name or something like that

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

by Taluu at 2012-12-10T14:19:29Z

@fabpot so, does it means that it could replace the include tag ? Then, we could could name it `include` as @vicb suggested... ?

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

by titomiguelcosta at 2012-12-10T14:21:51Z

I agree with @stof, naming it render will be confusing, parse or execute or compile are other names that come to my mind for this purpose.

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

by silentworks at 2012-12-10T14:24:36Z

How about calling it `partial`? even though you are rendering a full template, it is being included in another so this could be seeing as a partial of that template.

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

by stof at 2012-12-10T14:26:05Z

@titomiguelcosta parse is totally wrong. The function is not parsing the string you give it. you don't pass the content of the template but its name. and ``compile`` is also wrong. It is not compiling a template but rendering it.

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

by jmather at 2012-12-10T14:30:53Z

I think `render` is probably the most appropriate name, but also may cause confusion, however I don't have another suggestion that is nearly as clear as to context and meaning.

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

by emgiezet at 2012-12-10T14:31:26Z

Can you pass the array of params as an argument to the `render` function?

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

by titomiguelcosta at 2012-12-10T14:31:59Z

@stof true that we pass the filename as argument, but we end up parsing the file.

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

by stof at 2012-12-10T14:32:48Z

@emgiezet you mean passing some variables available in the included template ? Sure you can. See the doc. the argument is named ``variables``

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

by stof at 2012-12-10T14:34:36Z

@titomiguelcosta But the goal of the function is not to parse the file (btw, it may not parse it if the template was already compiled in the cache). The goal is to render the template.

Btw, I agree with @jmather. As far as Twig is concerned, ``render`` is the best name. The only issue comes from the fact that Symfony already use a ``{% render %}`` tag with a different meaning

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

by emgiezet at 2012-12-10T14:39:02Z

@stof thx a lot didn't noticed the doc link. Maybe `render_partial` will be good in this case?

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

by tcz at 2012-12-10T14:44:13Z

In an ideal world the Symfony2 `render` tag would be renamed to `subrequest` or something like that and the new function in Twig would get the `render` name. The question is how many people use Twig because of Symfony2 and how many of them use it in itself (in my company we use standalone Twig for example).

I think it's important to avoid `raw`-style confusions for the former group.

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

by stof at 2012-12-10T15:16:28Z

@tcz The issue with renaming the tag in Symfony is that it would be a BC break. So we cannot simply drop the tag (we can provide a new name and deprecate the current one, but we would still keep it).

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

by Taluu at 2012-12-10T15:18:56Z

I think `partial` would be a good idea... But still, does it mean that the `include` tag would be deprecated in favor of `render` (or whatever the name will be) function ?

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

by tcz at 2012-12-10T15:19:49Z

@stof Yes :( hence my remark "in an ideal world"

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

by stof at 2012-12-10T15:27:52Z

@Taluu It depends if @fabpot wants to keep the compatibility with Jinja where possible (as it is where the ``include`` tag comes from)

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

by WouterJ at 2012-12-10T15:48:26Z

I like the function, but I don't like the name. I like the name `partial`.

I am a front-end developer from origin and all files you include in the base CSS stylesheet are called 'partials' in SASS or other preprosessors. Twig is used to make live easier for front-end developers and I think a function called `partial` is more familiair for them than `render`.

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

by silentworks at 2012-12-10T16:17:24Z

@stof I guess based on @fabpot wanting to keep Twig compatibility with Jinja, calling the tag `partial` rather than `render` shouldn't be a problem since Jinja doesn't have any of these.

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

by Taluu at 2012-12-10T16:19:25Z

@silentworks @stof was talking about my question, about why keep the `include` tag if the `render` (or whatever the name will be) is indeed inserted into Twig. :)

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

by stof at 2012-12-10T16:19:38Z

@silentworks I was not talking about the name of the function, but about the removal of the ``include`` tag

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

by silentworks at 2012-12-10T16:22:37Z

Thanks for clarity from both.

On the basis of keeping to conformity to Jinja, should this function not be a part of twig extensions rather than in the core?

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

by mvrhov at 2012-12-10T17:20:03Z

Well search and replace for symfony users when upgrading shouldn't be that hard so I'd say that we rename the symfony block into subrequest or sth similar.

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

by Taluu at 2012-12-10T17:26:22Z

If we were to follow your recommandations, we could say the same for all and every changes inducing a BC break huh...

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

by markstory at 2012-12-10T17:49:36Z

What about naming the function `include`?  It would share a name with the tag, but it also does the same type of thing as the tag.  The function has the advantage of having its return captured.  I think  `{{ include(template) }}` semantically does what it looks like it does when operating on the template object as well.

Other names that I think could fit well are `partial` and `display`. Render works well, but I understand people not wanting to overlap with existing symfony features that do very different things.

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

by Baachi at 2012-12-10T18:13:25Z

I think "partial" is a better name for this function and it would keep BC.
2012-12-25 11:06:30 +01:00
Fabien Potencier f4f88a51e2 added an include function 2012-12-17 08:43:49 +01:00
Fabien Potencier 27b384341c fixed regression 2012-12-11 15:22:37 +01:00
Fabien Potencier 811dfad7c2 added a syntax error when using a loop variable that is not defined (closes #925) 2012-12-10 21:06:39 +01:00
Fabien Potencier df13370b22 added a missing test 2012-12-06 08:16:15 +01:00
Fabien Potencier 33e690b4db fixed some tests when the extension is not enabled 2012-12-06 08:14:48 +01:00
Fabien Potencier 014f459b00 added some missing test for Template::getAttribute() 2012-12-06 08:10:02 +01:00
Fabien Potencier b92552f30e added missing tests for sandbox support in Template::getAttribute() 2012-12-01 19:21:32 +01:00
Fabien Potencier 35f611f22c added some missing tests for getAttribute (for isXXX methods) 2012-12-01 19:04:43 +01:00
Fabien Potencier 44873875ff reverted the early registration of extensions (extensions are now loaded as before -- as late as possible) -- closes #910 2012-11-30 21:04:23 +01:00
Fabien Potencier b58df0e1ae added some unit for previous merge 2012-11-26 11:25:49 +01:00
Fabien Potencier 0a7b37b8cc changed the way extension filters/tests/functions/node visitors/globals/token parsers are registered (they were loaded as late as possible, they are now loaded as early as possible) 2012-11-18 10:39:05 +01:00
Fabien Potencier 4647913e50 added the ability to set default values for macro arguments (closes #447) 2012-11-15 12:59:42 +01:00
Fabien Potencier a59dcde3c2 added support for named arguments for filters, tests, and functions 2012-11-15 10:23:32 +01:00
Fabien Potencier e1ad2bde9c moved filters/functions/tests syntax errors to the parser 2012-11-14 14:33:08 +01:00
Fabien Potencier f85076b091 added support for extended ternary operator syntaxes (closes #134) 2012-11-14 07:40:53 +01:00
Fabien Potencier 818f9c7e02 merged branch char101/fix-debug-lineno (PR #894)
This PR was squashed before being merged into the master branch (closes #894).

Commits
-------

7c5854b Fix twig error lineno off by 2

Discussion
----------

Fix twig error lineno off by 2

It seems to me that the lineno reported by Twig_Error is off by 2 from the real lineno in the generated PHP source

For example:

```
{% if true %}
Yes
{% endif %}
```

```php
<?php

/*  */
class __TwigTemplate_d41d8cd98f00b204e9800998ecf8427e extends Twig_Template
{
    public function __construct(Twig_Environment $env)
    {
        parent::__construct($env);

        $this->parent = false;

        $this->blocks = array(
        );
    }

    protected function doDisplay(array $context, array $blocks = array())
    {
        // line 1
        if (true) { // <- this is line 19
            // line 2
            echo "Yes // <- this is line 21
";
        }
    }

    public function getTemplateName()
    {
        return null;
    }

    public function isTraitable()
    {
        return false;
    }

    public function getDebugInfo()
    {
        return array (  19 => 2,  17 => 1,); // <- should be return array (  21 => 2,  19 => 1,);
    }
}
```

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

by char101 at 2012-11-08T08:23:57Z

Since `$compiler->addDebugInfo()` is called first before writing the node content, usually the number of lines in the PHP code is less than 2 (1 for the // lineno comment, and 1 for the generated content) than the line where the node content is written.
2012-11-08 10:22:28 +01:00
Charles 7c5854bba9 Fix twig error lineno off by 2 2012-11-08 10:22:28 +01:00
Fabien Potencier 615804bf74 fixed regression when calling a macro inside another one (closes #889) 2012-11-08 08:57:26 +01:00
Fabien Potencier d7fed092b1 fixed typo 2012-11-08 08:51:01 +01:00
Fabien Potencier 501791cf1a added a test for previous merge (refs #892) 2012-11-08 07:29:16 +01:00
Charles f397a8f79b Use ternary operator with PHP 5.4 when strict_variables is true 2012-11-08 07:21:48 +01:00
Fabien Potencier d4a8c8b2fb added tests for exceptions thrown in Twig_Template::getAttribute() 2012-11-06 08:40:39 +01:00
Fabien Potencier abec35b833 fixed macro compilation when a variable name is a PHP reserved keyword (closes #881) 2012-11-05 08:52:04 +01:00
Fabien Potencier a009821dd3 fixed CS 2012-11-03 08:27:41 +01:00
Fabien Potencier 96b3ce6bd6 merged branch fabpot/timezones (PR #876)
This PR was merged into the master branch.

Commits
-------

f99504a changed the date filter behavior to always apply the default timezone, except if false is passed as the timezone
d3b0cbd merged branch jmikola/patch-1 (PR #845)
a6a1ef0 Avoid setting timezones on DateIntervals

Discussion
----------

changed the date filter behavior to always apply the default timezone, except if false is passed as the timezone

This PR is based on #845, and addresses issue #778.

Right now, the timezone management when using the date filter is counter-intuitive. When you pass a DateTime object, the default timezone is not applied, but in all other cases, it is.

This PR makes the behavior more consistent by always applying the default timezone (which is probably what users want most of the time), and this can be disabled by explicitly passing ``false`` as the timezone value.

This is a BC break but I think that not many consciously rely on the current behavior.

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

by fabpot at 2012-10-30T15:49:13Z

@jmikola Can you have a look at this PR and tell me your opinion about this change?

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

by jmikola at 2012-11-02T20:17:30Z

@fabpot: Will take a look at this tonight. I missed the notifications as I was offline for a few days.

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

by jmikola at 2012-11-03T04:09:54Z

I read through all of the issues and PR's and this looks reasonable. Are we missing a test case for passing in a DateTime object with `false` for the timezone? I do see one example where we render the current date using the `'e'` format string and provide `false` for the timezone, but that's it.

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

by fabpot at 2012-11-03T07:09:08Z

ok, I've added an additional test just to be sure.
2012-11-03 08:09:43 +01:00