Commit Graph

1813 Commits

Author SHA1 Message Date
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 c6445fb5cd merged branch fabpot/first-last (PR #977)
This PR was merged into the master branch.

Commits
-------

f8d4db4 added the first and last filters (closes #951)

Discussion
----------

added the first and last filters (closes #951)

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

by acasademont at 2013-01-26T20:45:23Z

👍 great! Using twig_slice is a nice thing, we can have string and traversable objects work also with the new filters

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

by jankramer at 2013-01-30T17:39:31Z

👍 Was actually just looking for this :) When do you think you'll merge this feature into master?
2013-02-01 10:44:45 +01:00
Fabien Potencier 81af6a1fd1 removed list of built-in items in the docs in favor of a link (easier to maintain and better for discoverability) 2013-01-31 11:19:12 +01:00
Fabien Potencier f2c95b34da merged branch javiereguiluz/doc_fixes (PR #982)
This PR was merged into the master branch.

Commits
-------

aac6cb6 Fixes and minor additions to the docs.

Discussion
----------

Fixes and minor additions to the docs.
2013-01-31 09:44:01 +01:00
Javier Eguiluz aac6cb613c Fixes and minor additions to the docs. 2013-01-31 09:30:58 +01:00
Fabien Potencier eaadcca54b merged branch eXtreme/patch-1 (PR #978)
This PR was merged into the master branch.

Commits
-------

8f28e78 Missing code-block in doc/templates.rst

Discussion
----------

Missing code-block in doc/templates.rst

Little tweak for docs.
2013-01-27 17:32:04 +01:00
Jacek Jędrzejewski 8f28e7890e Missing code-block in doc/templates.rst 2013-01-27 11:29:20 +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 88cefd3712 tweaked previous merge 2013-01-26 15:57:10 +01:00
Fabien Potencier c3a9c53882 merged branch rybakit/constant (PR #966)
This PR was merged into the master branch.

Commits
-------

a1b7ec5 Tweak twig_constant()

Discussion
----------

Tweak twig_constant()

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

by Tobion at 2013-01-16T10:52:56Z

Why is it better? The old version returns earlier.

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

by rybakit at 2013-01-16T11:25:39Z

It's better for several reasons, imho:
1. Negation has gone, which is better for perception
2. Single function exit point
3. The same functionality in less code

And what do you mean by "The old version returns earlier"?

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

by Tobion at 2013-01-16T13:33:22Z

It means the old version uses a variable less and we prefer early return statements when possible.

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

by rybakit at 2013-01-16T14:24:26Z

@Tobion, but how could it be "earlier"? In both cases the ```return``` statement goes exactly after the condition check:

1)
```php
if (!$object) {                   // 1. check condition
    return constant($constant);   // 2. return result
}
```
2)
```php
if ($object) {                    // 1. check condition
    // ...
}

return constant($constant);       // 2. return result
```
Do you want to say that case 1) is faster?
2013-01-26 15:56:04 +01:00
Fabien Potencier 93c6a8dedc merged branch iamdto/master (PR #969)
This PR was merged into the master branch.

Commits
-------

9d25425 Fixed typo that messes up with syntax highlighting

Discussion
----------

[Documentation] Fixed typo
2013-01-18 10:58:04 +01:00
iamdto 9d25425d95 Fixed typo that messes up with syntax highlighting 2013-01-18 10:43:17 +01:00
Fabien Potencier 3225226e0b removed SVN instructions 2013-01-16 14:37:25 +01:00
Fabien Potencier e8799d6807 merged branch bamarni/patch-1 (PR #967)
This PR was merged into the master branch.

Commits
-------

d5de5e6 [doc] Installation - recommended Composer instead of tarball

Discussion
----------

[doc] Installation - recommended Composer instead of tarball
2013-01-16 14:36:45 +01:00
Bilal Amarni d5de5e6d3b [doc] Installation - recommended Composer instead of tarball 2013-01-16 14:17:17 +01:00
Eugene Leonovich a1b7ec56e6 Tweak twig_constant() 2013-01-16 09:40:49 +01:00
Fabien Potencier 2a7d317cf9 bumped version to 1.12.2-DEV 2013-01-15 21:09:30 +01:00
Fabien Potencier 7c124c94a5 prepared the 1.12.1 release v1.12.1 2013-01-15 21:03:52 +01:00
Fabien Potencier 7c2479d47b tweaked previous merge 2013-01-15 20:56:11 +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 8bb953cb65 Fix doc block for twig_constant. 2013-01-11 09:44:29 -05:00
Mark Story c7dafb7e20 Update documentation for constant() 2013-01-10 23:40:58 -05:00
Mark Story cb921ce602 Implement getting constants from objects. 2013-01-10 23:38:01 -05:00
Mark Story 998b367c0c Add tests for getting constants from instances. 2013-01-10 23:37:47 -05:00
Fabien Potencier 3111e1265d merged branch Taluu/patch-1 (PR #953)
This PR was merged into the master branch.

Commits
-------

79c34d8 Update CHANGELOG

Discussion
----------

Update CHANGELOG

Fixes the year for the latest releases

We're not in 2012 anymore. I think.
2013-01-08 17:56:12 +01:00
Baptiste Clavié 79c34d81af Update CHANGELOG
Fixes the year for the latest releases
2013-01-08 16:49:06 +01:00
Fabien Potencier d10ebfa3d4 added support for {{ some_string[:2] }} (closes #952) 2013-01-08 15:19:19 +01:00
Fabien Potencier ad31e1765a bumped version to 1.12.1-DEV 2013-01-08 15:08:36 +01:00
Fabien Potencier 19c860742b prepared the 1.12.0 release v1.12.0 2013-01-08 14:42:43 +01:00
Fabien Potencier 9e9a6a093b tweaked CHANGELOG 2013-01-08 14:40:54 +01:00
Fabien Potencier 56bef3fa37 forbid mixed usage of raw/verbatim 2013-01-08 13:28:45 +01:00
Fabien Potencier ddd4b732f9 merged branch fabpot/verbatim (PR #947)
This PR was merged into the master branch.

Commits
-------

cd4ab0f renamed the raw tag to verbatim to avoid confusion with the raw filter

Discussion
----------

renamed the raw tag to verbatim to avoid confusion with the raw filter

In Twig, we have a `raw` tag and a raw filter. Unfortunately, they are totally unrelated and that is confusing.

I propose to rename the `raw` tag to `verbatim`. Of course, for BC reasons, the old `raw` tag will be kept around for the foreseeable future as an alias to `verbatim`.

For the record, `raw` is used by Jinja (http://jinja.pocoo.org/docs/templates/#escaping), whereas `verbatim` was introduced in Django in 1.5 (https://docs.djangoproject.com/en/dev/releases/1.5/#verbatim-template-tag).
2013-01-05 11:14:46 +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
Fabien Potencier 7d3b8d78b0 updated license year 2013-01-04 17:54:54 +01:00
Fabien Potencier 037b5be972 Revert "merged branch za-creature/patch-1 (PR #943)"
This reverts commit dc565f781f, reversing
changes made to 8447ca1718.
2013-01-02 17:15:41 +01:00
Fabien Potencier dc565f781f merged branch za-creature/patch-1 (PR #943)
This PR was merged into the master branch.

Commits
-------

15be13c Update lib/Twig/Autoloader.php

Discussion
----------

Update lib/Twig/Autoloader.php

Added the ability to register the autoloader at the top of the stack, useful in some situations.

Specifically, I need this because I want the last autoload function registered in my application to throw an exception instead of producing a class not found error, and I need *that* autoloader to be registered before twig's.
2013-01-02 16:58:50 +01:00
Fabien Potencier 8447ca1718 merged branch dantleech/globals_not_array (PR #944)
This PR was squashed before being merged into the master branch (closes #944).

Commits
-------

9f5fa53 Upgrade problem

Discussion
----------

Upgrade problem

Hi

When upgrading to HEAD I got the error

Warning: array_key_exists() expects parameter 2 to be array, null given
in /home/daniel/www/DCMS/vendor/twig/twig/lib/Twig/Environment.php line
975

Caused by adding globals in the initRuntime method in my extensions.

This patch makes addGlobal handle the case where Envieonment::$globals is null.

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

by stof at 2012-12-31T14:33:17Z

Your patch does not work properly. It will allow setting the ``bar`` global when you have not called ``getGlobals`` yet now (which is why your new test is failing on Travis)

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

by dantleech at 2012-12-31T14:45:28Z

Yes, sorry, I pushed the wrong version of Environment.php. Tests should pass now.

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

by stof at 2012-12-31T14:55:29Z

I think you are now forbidding to replace an existing global without calling ``getGlobals`` first when the runtime is initialized

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

by dantleech at 2012-12-31T15:12:20Z

I think that this is the correct logic.

Throw the Exception "Unable to add global "%s" as the runtime or  the extensions have already been initialized" IF the global has not already been registered.

So, if ``$globals === null`` then this is indeed the case. The logic is the same, it just supports the default NULL value for $globals. I think.

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

by stof at 2012-12-31T15:52:50Z

no, if ``$globals === null``, it means you have not yet loaded all the globals registered previously, so you cannot know if it has already been registered this way. What you need to do is calling ``initGlobals`` in this case to be sure they are initialized

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

by dantleech at 2013-01-01T09:18:45Z

ok. updated, I think I understand -- so it is required to use ``getGlobals`` to register globals, but we cannot add globals after/during ``initRuntime``. But we could replace them:

````php
public function getGlobals()
{
   return array(
     'existing' => $this->someGlobal
   );
}
pubic function initRuntime(\Twig_Environment $e)
{
  $e->addGlobal('existing', $this->foo);  // OK
  $e->addGlobal('non-existing', $this->bar);  // FAIL
}
````

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

by darklow at 2013-01-02T15:11:46Z

This error also gives us lot of headaches, after any twig file changed first reload, got this error on array_key_exists.
Hopefully this PR could be verified and approved. Thank you.
2013-01-02 16:57:55 +01:00
dantleech 9f5fa532ef Upgrade problem 2013-01-02 16:57:55 +01:00
Fabien Potencier 25f7b0c7eb bumped version to 1.12.0-DEV 2012-12-30 21:07:31 +01:00
Fabien Potencier b0082d2d6b prepared the 1.12.0-RC1 release v1.12.0-RC1 2012-12-30 20:59:54 +01:00
za-creature 15be13c081 Update lib/Twig/Autoloader.php
Added the ability to register the autoloader at the top of the stack, useful in some situations.
2012-12-30 21:46:06 +02:00
Fabien Potencier 10cdd2f592 fixed typo in the docs 2012-12-30 17:18:01 +01:00
Fabien Potencier 45850f554f fixed wrong version in the docs 2012-12-30 16:51:58 +01:00
Fabien Potencier 1b1a6e7de0 merged branch fabpot/performance-fix (PR #941)
This PR was merged into the master branch.

Commits
-------

2450f79 changed the way globals behave to be more BC with 1.11 and to avoid speed problems at runtime introduced in 4487387 (closes #932)

Discussion
----------

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 17:33:50 +01:00
Fabien Potencier 5b6647d3e2 removed PEAR related code 2012-12-27 14:40:31 +01:00