Commit Graph

513 Commits

Author SHA1 Message Date
Josh Turmel 6593761950 Allow setting of timezone on twig_date_format_filter method 2011-06-21 20:14:00 -07:00
Fabien Potencier 027f4890a7 fixed possible security problems with NUL bytes 2011-06-17 09:17:45 +02:00
Fabien Potencier 2c26e6776b releasing 1.1.0 RC2 2011-06-17 07:03:39 +02:00
Fabien Potencier a12aec38c3 added Twig_Error::getRawMessage() 2011-06-16 10:04:13 +02:00
Fabien Potencier 47818dd2a1 added an exception when the template passed to "use" is not a string 2011-06-16 09:57:17 +02:00
Fabien Potencier cf50380b8c merged branch nikic/nestedDefinedTestWithStrictVars (PR #359)
Commits
-------

f2a1c2b Refactor and add additional default filter tests
e760483 Make `a.b is defined` not throw an exception if a is not defined (in strict mode)

Discussion
----------

Make `a.b is defined` not throw an exception if a is not defined (in strict mode)

This commit does two things: Firstly (that's the main part) it makes `a.b is defined` not throw an error in strict mode if `a` is undefined (applies for `a.b.c` aso too) [fixes #337]. Additionally it allows `a.b|default` just like it is allowed to do `a|default`.

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

by fabpot at 2011/06/09 22:21:11 -0700

This is quite a big change. Can you add some tests?

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

by nikic at 2011/06/10 08:19:49 -0700

I added some more tests for the default filter in the fixtures. But I wasn't sure how I should test the default test's behavior in strict mode. If you could point me in the right direction here I would add those tests, too ;)
2011-06-16 09:41:50 +02:00
Fabien Potencier 403151ba48 merged branch arnaud-lb/line-numbers (PR #353)
Commits
-------

5ec1955 added {% line \d+ %} directive

Discussion
----------

added {% line \d+ %} directive

This directive allows to change the current line number in the tokenizer.

This allows to generate Twig code from some other Twig or partially-Twig script, and still get relevant line numbers in error messages, when the line numbers of the generated Twig script do not match those of the original script.

For example in the following script:

    foo
    {% line 10 %}
    bar
    {{ baz }}

`"foo"` is on line 1, `"bar"` is considered to be on line 10 and `{{ baz }}` is considered to be on line 11.

This is similar to `# line ...` directives in C.

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

by nikic at 2011/06/05 08:51:20 -0700

I don't quite yet understand it's use cases.

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

by arnaud-lb at 2011/06/05 09:17:57 -0700

The `{% line ... %}` directive is not meant to be used by humans, but rather by generators.

The use case is the same as [#line directives in C](http://gcc.gnu.org/onlinedocs/cpp/Line-Control.html): when you generate a C file from a template, you would prefer that the compiler refers to the line number of the template, instead of the line number of the generated file.

In my case, I built a [HAML compiler for php](https://github.com/arnaud-lb/MtHaml) which can target Twig as an output language. I use it as a Twig pre-processor so that it translates HAML scripts to Twig scripts on the fly in a custom Twig_Loader.

So I have scripts like that:

    %p
      test
    %div = foo.bar

which is compiled like that:

    <p>
      test
    </p>
    <div>
       {{ foo.bar }}
    </div>

If an error occurs in the execution of {{ foo.bar }}, Twig will throw an error refering to line 5 in the original script, which is wrong. A simple solution to this is the {% line %} directive:

    <p>
      test
    </p>
    <div>
    {% line 3 %}
       {{ foo.bar }}
    </div>

Now if an error occures in {{ foo.bar }}, the error will refer to line 3.

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

by nikic at 2011/06/05 09:33:26 -0700

Ah, okay, seems reasonable. Though I'm not sure whether it is appropriate to use the comment syntax to accomplish that.

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

by arnaud-lb at 2011/06/05 10:41:03 -0700

You are right, I changed the request to use the block syntax instead.
2011-06-16 09:31:53 +02:00
Fabien Potencier b340d98d98 added null as an alias for the none test 2011-06-14 08:19:32 +02:00
nikic e760483287 Make a.b is defined not throw an exception if a is not defined (in strict mode) 2011-06-09 20:50:48 +02:00
Fabien Potencier cd0e749308 added Twig_Loader_Filesystem::addPath() 2011-06-07 16:33:55 +02:00
Arnaud Le Blanc 5ec19550b2 added {% line \d+ %} directive 2011-06-05 19:38:12 +02:00
Fabien Potencier 7e457209f8 added missing debug info when using traits 2011-06-05 12:12:05 +02:00
Fabien Potencier 3cf357391a fixed Twig_Error when the exception is thrown from within the generated template 2011-06-05 12:07:30 +02:00
Fabien Potencier 9328df1940 updated VERSION 2011-05-28 17:35:04 +02:00
Fabien Potencier 3807548114 releasing 1.1.0 RC1 2011-05-28 17:34:18 +02:00
Fabien Potencier dbab43d81c Merge remote branch 'tna/default-filter'
* tna/default-filter:
  Moved default filter fix to its proper place
  Fixes default filter
2011-05-28 16:38:25 +02:00
Fabien Potencier 9c07baf8e5 fixed timezone when using the date filter with a UNIX timestamp (it now uses the default timezone instead of UTC to mimics the date() function behavior) 2011-05-28 16:36:42 +02:00
Jeremy Mikola d8eafa02f2 Date filter should treat strict integers as Unix timestamps (same as all-digit strings)
Without a string cast, ctype_digit() will return false for an integer.
2011-05-27 11:54:06 -07:00
Tobias Naumann 703a822da9 Moved default filter fix to its proper place 2011-05-26 17:03:41 +02:00
Tobias Naumann fc1af4b9b2 Fixes default filter 2011-05-26 11:14:22 +02:00
nikic f742efd602 Refactor GetAttr defined implementation to consider null defined 2011-05-24 12:48:47 +02:00
nikic b0a94baebd Fix regression in defined test for GetAttr. Fixes #319 2011-05-18 08:08:32 +02:00
Fabien Potencier 654468ff5d simplified code 2011-05-10 07:21:09 +02:00
Fabien Potencier 48f427ebd3 added a test for the raw tag 2011-05-09 17:47:21 +02:00
Fabien Potencier 93425b32cb fixed parsing problem when a large chunk of text is enclosed in a raw tag
This is a quick and ugly fix... This should be refactored later on
2011-05-09 17:35:11 +02:00
Fabien Potencier d88e7ca244 fixed CS 2011-05-09 16:41:39 +02:00
Fabien Potencier 17f814223b updated email address 2011-04-29 17:18:51 +02:00
Fabien Potencier 109ce30288 made a small speed optimization when using auto-escaping 2011-04-29 15:23:00 +02:00
Fabien Potencier e4d457e55c updated version 2011-04-29 12:45:10 +02:00
Joseph Bielawski e307cfab06 Compiler.php - CS fix 2011-04-29 02:59:03 -07:00
Joseph Bielawski a0709beee6 TokenParserBroker.php - CS fix 2011-04-29 02:57:54 -07:00
Joseph Bielawski fa93043bf3 Parser.php - CS fix 2011-04-29 02:56:34 -07:00
Joseph Bielawski c716b99278 Lexer.php - CS fix 2011-04-29 02:54:59 -07:00
Joseph Bielawski 68a39159b0 Environment.php - CS fix 2011-04-29 02:46:23 -07:00
Joseph Bielawski 475ec2db03 TokenParserBroker.php - CS fix 2011-04-29 02:42:36 -07:00
Joseph Bielawski 448106fa04 DRY optimization 2011-04-29 01:34:13 -07:00
Fabien Potencier 3930ba0f4e added some tests for the use tag 2011-04-29 09:43:23 +02:00
Fabien Potencier 4a7aaad594 added support for block renaming when importing traits
{% use 'TwigBundle:Form:div_layout.html.twig' with text_widget as foo_text_widget %}
2011-04-29 00:07:00 +02:00
Fabien Potencier 221eb48ea8 added support for traits (experimental)
Traits are "special" templates that define blocks that you can "include" in
other templates.

Let's take an example:

    {# 'foo' template defines the 'foo' block #}
    {% block 'foo' %}
        FOO
    {% endblock %}

    {# 'main' template defines the 'bar' block and include the 'foo' block from the 'foo' template #}
    {% extends 'base' %}

    {% use 'foo' %}

    {% block 'bar' %}
        BAR
    {% endblock %}

In the previous example, the 'main' template use the 'foo' one. It means that
the 'foo' block defined in the 'foo' template is available as if it were
defined in the 'main' template.

You can use as many 'use' statements as you want in a template:

    {% extends 'base' %}

    {% use 'foo' %}
    {% use 'bar' %}
    {% use 'foobar' %}

If two templates define the same block, the latest one wins. The template can
also overrides any block.

The 'use' tag also supports "dynamic" names:

    {% set foo = 'foo' %}

    {% use foo %}

The 'use' tag only imports a template if it does not extend another template,
if it does not define macros, and if the body is empty. But it can 'use' other
templates:

    {# 'foo' template #}
    {% block 'foo' %}
        FOO
    {% endblock %}

    {# 'bar' template #}
    {% use 'foo' %}

    {% block 'bar' %}
        BAR
    {% endblock %}

    {# 'main' template #}
    {% extends 'base' %}

    {% use 'bar' %}

In this example, the 'main' template has access to both 'foo' and 'bar'.

Traits are mainly useful when you consider blocks as reusable "functions";
like we do in Symfony2 forms or if you use Twig for code generation.
2011-04-28 16:22:09 +02:00
nikic 17af31b5b4 Use a type strict null check for GetAttr defined tests. Fixes #305 2011-04-28 13:17:49 +02:00
lenar 04fcc0ca76 fixes performance regression
The regression was introduced by 1e09c7b660.
2011-04-28 11:27:40 +03:00
Joseph Bielawski 2f5e0cacd4 Simplify fix. 2011-04-27 08:50:08 -07:00
Joseph Bielawski 36143a6b6c Fix for issue #307 2011-04-27 07:57:39 -07:00
Fabien Potencier 1e09c7b660 added template file information when an error occurs during compilation 2011-04-22 16:08:43 +02:00
Fabien Potencier 9d88081c94 tweaked Twig_Error to keep the passed line or template when passed in the constructor and findTemplateInfo() was not able to guess it better 2011-04-22 16:06:50 +02:00
Fabien Potencier 76205f1eaa added null as an alias to none and made TRUE, FALSE, and NONE equivalent to true, false, and none 2011-04-14 07:35:58 +02:00
Fabien Potencier 385dc39689 Merge remote branch 'markstory/whitespace'
* markstory/whitespace:
  Updating documentation for whitespace trim tags.
  Making trim tags consume all whitespace, both horizontal and vertical.
  Adding additional test suggested by nikic.
  Making a capturing group non capturing, as the group isn't used.
  Moving newline trimming into the regexp used to match end of tags.
  Applying changes suggested by nikic to simplify how end of comments are processed.
  Fixing some whitespace.
  Fixing typo.
  Adding a bit of documentation for whitespace trimming.
  Adding whitespace trimming support to other tag types (comments, variables) Refactoring how whitespace trimming is done, and moving it into a separate option that is combined with other tag types. Adding more tests. Refs #284
  Fixing use of non-existent method name.
  Adding a test case for mixing {%- and %} tags together.
  Adding a test that uses tabs. Added a test for trailing tabs and -%} Refs #284
  Implementing {%- which trims non-newline whitespace preceding it. Refs
2011-04-14 07:22:57 +02:00
Mark Story 99e3246c49 Making trim tags consume all whitespace, both horizontal and vertical. 2011-04-13 22:10:57 -04:00
Fabien Potencier d96dbb442f removed empty if 2011-04-12 16:04:26 +02:00
Fabien Potencier fbadd66852 tweaked error message when wrapping an external exception 2011-04-12 15:40:26 +02:00