Commit Graph

3891 Commits

Author SHA1 Message Date
Fabien Potencier b2dac7df50 deprecated using the spaceless tag at the root level of a child template (noop anyway) 2018-05-18 12:56:53 +02:00
Fabien Potencier 143e4f46f8 feature #2687 Deprecate the possibility to define a block in a non-capturing block from a child template (fabpot)
This PR was merged into the 2.x branch.

Discussion
----------

Deprecate the possibility to define a block in a non-capturing block from a child template

fixes #351, #541, #703, #988, #1639, #1685, #2393

One recurring issue (see the probably non-exhaustive list of issues references above) is a misunderstanding of how blocks work in a child template.

For instance, there is no way to define a `block` conditionally:

```twig
{% extends "layout" %}

{% if ... %}
    {% block content %}
        ...
    {% endblock %}
{% endif %}
```

And wrapping a `block` definition with a `spaceless` tag does not work:

```twig
{% extends "layout" %}

{% spaceless %}
    {% block content %}
        ...
    {% endblock %}
{% endspaceless %}
```

The issue is that the above templates compile just fine, but not in a way people expect. Basically, the condition would be empty.

Interestingly enough, wrapping a `block` definition might be useful/work as expected when used with "capturing" tags like `set`:

```twig
{% extends "layout" %}

{% set content %}
    {% block content %}
        ...
    {% endblock %}
{% endset %}
```

Not sure if that's useful, but here, the `block` tag will serve as the blog definition AND it will also be displayed in place. I would not recommend such usages.

This pull request deprecates the cases where the compiled template would never reflect the developer intent, but keeps the "working" scenarii as is.

I've been trying to fix that issue for **years**. Very happy to have found a simple solution without breaking anything that worked fine.

Commits
-------

9b938887 deprecated the possibility to define a block in a non-capturing block from a child template
2018-05-18 12:15:51 +02:00
Fabien Potencier 9b9388878a deprecated the possibility to define a block in a non-capturing block from a child template 2018-05-18 11:59:40 +02:00
Fabien Potencier 83601c5728 minor #2686 Move legacy tests that were not executed anymore in 2.x (fabpot)
This PR was merged into the 2.x branch.

Discussion
----------

Move legacy tests that were not executed anymore in 2.x

While working on some new deprecations, I noticed that some fixtures were in a directory that was not used anymore in 2.x. I've moved the relevant one back to the main Fixtures directory and remove the other one, which is not relevant anymore.

Commits
-------

c412d0f4 moved legacy tests that were not executed anymore in 2.x
2018-05-18 10:47:04 +02:00
Fabien Potencier c412d0f405 moved legacy tests that were not executed anymore in 2.x 2018-05-18 09:55:44 +02:00
Fabien Potencier b23e42fd83 Merge branch '1.x' into 2.x
* 1.x:
  fixed typo
2018-05-18 09:45:53 +02:00
Fabien Potencier b705a3a028 fixed typo 2018-05-18 09:45:47 +02:00
Fabien Potencier 44bb6cc9ac bumped version to 2.5.0 2018-05-18 09:34:00 +02:00
Fabien Potencier e83a58a517 updated CHANGELOG 2018-05-18 09:25:42 +02:00
Fabien Potencier eff4f9f622 Merge branch '1.x' into 2.x
* 1.x:
  fixed doc markup
  Fixed PHPDoc of Twig_Token::test
  added the Symfony ctype polyfill as a dependency
  Added missing edge-cases
2018-05-18 09:25:34 +02:00
Fabien Potencier f4c020923f fixed doc markup 2018-05-18 09:23:18 +02:00
Fabien Potencier f9638a0d14 fixed doc markup 2018-05-18 09:22:42 +02:00
Fabien Potencier 5f18e99163 minor #2678 Added missing edge-cases (ismael-miguel)
This PR was merged into the 1.x branch.

Discussion
----------

Added missing edge-cases

Discussion on: https://github.com/twigphp/Twig/issues/2677

Commits
-------

22739e7d Added missing edge-cases
2018-05-12 11:39:44 +02:00
Fabien Potencier ed02b30a17 minor #2681 Fixed PHPDoc of Twig_Token::test (lyrixx)
This PR was merged into the 1.x branch.

Discussion
----------

Fixed PHPDoc of Twig_Token::test

For exemple `Twig_TokenParser_Set` use `->test('endset')`

Commits
-------

35a1070a Fixed PHPDoc of Twig_Token::test
2018-05-02 17:04:18 +02:00
Grégoire Pineau 35a1070a62 Fixed PHPDoc of Twig_Token::test
For exemple Twig_TokenParser_Set use ->test('endset')
2018-05-02 16:04:55 +02:00
Fabien Potencier 257d0656cc minor #2680 Add the Symfony ctype polyfill as a dependency (fabpot)
This PR was merged into the 1.x branch.

Discussion
----------

Add the Symfony ctype polyfill as a dependency

Commits
-------

5b9a70b3 added the Symfony ctype polyfill as a dependency
2018-05-02 07:48:32 +02:00
Fabien Potencier 5b9a70b3a3 added the Symfony ctype polyfill as a dependency 2018-05-01 21:12:10 +02:00
ismael-miguel 22739e7d13 Added missing edge-cases
Discussion on: https://github.com/twigphp/Twig/issues/2677
2018-04-25 20:48:23 +01:00
Fabien Potencier 055dea2c6d use HTTPS whenever possible 2018-04-20 08:10:29 +02:00
Fabien Potencier 07e0ed7f06 removed extra whitespaces 2018-04-20 08:09:57 +02:00
Fabien Potencier 094c22c5fd Merge branch '1.x' into 2.x
* 1.x:
  use HTTPS whenever possible
2018-04-20 08:09:12 +02:00
Fabien Potencier 4f57c6eab8 use HTTPS whenever possible 2018-04-20 08:05:14 +02:00
Fabien Potencier ed1ce4d0d1 fixed website URL 2018-04-20 07:28:22 +02:00
Fabien Potencier 47b5707f03 Merge branch '1.x' into 2.x
* 1.x:
  fixed website URL
  Fix cache update after uploading the template file (when auto-update is enabled).
  Small optimization for Twig_NodeTraverser::traverseForVisitor
  Add JSON escape strategy
2018-04-20 07:27:39 +02:00
Fabien Potencier 28690681d1 fixed website URL 2018-04-20 07:23:43 +02:00
Fabien Potencier d11c1f1a69 minor #2670 Fix partial template caching after update when auto_reload is on (ay-git)
This PR was submitted for the 2.x branch but it was merged into the 1.x branch instead (closes #2670).

Discussion
----------

Fix partial template caching after update when auto_reload is on

**Description of the bug:**
This bug manifests itself on production servers.
And with a high load the probability of getting on this bug tends to 100%
The bug results in the caching of a partial template and the failure of a part of the site working with this template. Can only be corrected by deleting the cache.

**What's happening:**
If in the process of uploading the template file, a render() is called, the partially uploaded file gets into the cache and after the template file is fully uploaded, the cache is not updated anymore.

**How to demonstrate:**
To demonstrate the bug, you can create 2 files:
File simulating the download of a file to the server (twig_test_write.php):

```
$classTwig = new Twig_Environment( new Twig_Loader_Filesystem(__DIR__."/../../site_templates/"), array(
	'cache' => __DIR__.'/../../site_templates_cache',
	'auto_reload'=>true
));

file_put_contents(__DIR__."/../../site_templates/"."test.twig","\n<br>Template start write to filesystem");

echo $classTwig->render("test.twig", array());

file_put_contents(__DIR__."/../../site_templates/"."test.twig"," - Template end write to filesystem",FILE_APPEND);

```

File for template rendering (twig_test_read.php):
```
$classTwig = new Twig_Environment( new Twig_Loader_Filesystem(__DIR__."/../../site_templates/"), array(
	'cache' => __DIR__.'/../../site_templates_cache',
	'auto_reload'=>true
));

echo $classTwig->render("test.twig", array());
```

Result executeing file twig_test_write.php:
```
Template start write to filesystem
```

Result executeing file twig_test_read.php:
```
Template start write to filesystem
```

**After this fix:**
Result executeing file twig_test_read.php:
```
Template start write to filesystem - Template end write to filesystem
```

Commits
-------

50d990e2 Fix cache update after uploading the template file (when auto-update is enabled).
2018-04-19 10:56:23 +02:00
AY_W 50d990e23d Fix cache update after uploading the template file (when auto-update is enabled).
If in the process of uploading the template file, a render() is called, the partially uploaded file gets into the cache and after the template file is fully uploaded, the cache is not updated anymore.
2018-04-19 10:56:18 +02:00
Fabien Potencier 9402071768 minor #2676 Fix links to repository in documentation (julienfalque)
This PR was merged into the 2.x branch.

Discussion
----------

Fix links to repository in documentation

Commits
-------

e691f2a5 Fix links to repository in documentation
2018-04-19 10:52:30 +02:00
Julien Falque e691f2a53f Fix links to repository in documentation 2018-04-16 11:58:53 +02:00
Fabien Potencier b4758ab491 minor #2672 Reword installation docs (fabpot)
This PR was merged into the 2.x branch.

Discussion
----------

Reword installation docs

One must use Composer with Twig 2.x.

Commits
-------

ff9070f6 reworded installation docs
2018-04-03 18:31:00 +02:00
Fabien Potencier ff9070f6d5 reworded installation docs 2018-04-03 17:59:20 +02:00
Fabien Potencier 1dcb150c94 bumped version to 2.4.9-DEV 2018-04-02 11:25:02 +02:00
Fabien Potencier 7b604c89da prepared the 2.4.8 release v2.4.8 2018-04-02 11:24:19 +02:00
Fabien Potencier e30cc13489 bug #2671 Fix regression (fabpot)
This PR was merged into the 2.x branch.

Discussion
----------

Fix regression

closes #2669, closes #2657

Commits
-------

0c2cdf2f fixed regression
2018-04-02 11:10:47 +02:00
Fabien Potencier 0c2cdf2f46 fixed regression 2018-04-02 11:08:39 +02:00
Fabien Potencier 8de61cef41 simplified tests 2018-04-02 10:24:25 +02:00
Fabien Potencier 3bc9686dc5 minor #2668 Small optimization for Twig_NodeTraverser::traverseForVisitor (covex-nn)
This PR was merged into the 1.x branch.

Discussion
----------

Small optimization for Twig_NodeTraverser::traverseForVisitor

During traversing a node tree `Twig_NodeTraverser::traverseForVisitor` (`Twig_NodeVisitorInterface::leaveNode`) often returns a same child node (a same object). So, there is no need to set it back to its parent.

This PR adds a check if a child node was changed. With this check a lot of calls to `Twig_Node::setNode` will be skipped.

Closes #2665

Commits
-------

555d01f3 Small optimization for Twig_NodeTraverser::traverseForVisitor
2018-04-01 20:24:34 +02:00
Andrey F. Mindubaev 555d01f327 Small optimization for Twig_NodeTraverser::traverseForVisitor 2018-03-26 09:53:48 +03:00
Fabien Potencier ce4aff66cc bug #2581 Add JSON escape strategy (c960657)
This PR was squashed before being merged into the 1.x branch (closes #2581).

Discussion
----------

Add JSON escape strategy

The `js` escape strategy used `\xNN`-style escape sequences. This is not allowed in JSON, only `\uNNNN` is allowed.

This PR adds a new escape strategy, `json` that is similar to `js` except that it does not use `\xNN` but uses `\uNNNN` instead.

I know that I can use `json_decode()`, but it came as a surprise to me that `escape('js')` did not work. You probably shouldn't be generating JSON structures in your templates, but sometimes it comes in handy. My use-case was generating a piece of [JSON-LD](https://json-ld.org).

A different approach that would perhaps be less confusing to users would be to change `js` to not use `\xNN`. This output is still valid JavaScript, it just uses two more bytes per occurrence. Let me know what you think.

Commits
-------

5c7b080b Add JSON escape strategy
2018-03-25 10:27:49 +02:00
Christian Schmidt 5c7b080b31 Add JSON escape strategy 2018-03-25 10:27:41 +02:00
Fabien Potencier 092871ad2d bumped version to 2.4.8-DEV 2018-03-20 05:31:47 +01:00
Fabien Potencier 69aacd44db prepared the 2.4.7 release v2.4.7 2018-03-20 05:31:17 +01:00
Fabien Potencier 60e41dfb91 updated CHANGELOG 2018-03-20 05:30:51 +01:00
Fabien Potencier 5efe582628 Merge branch '1.x' into 2.x
* 1.x:
  bumped version to 1.35.4-DEV
  prepared the 1.35.3 release
  updated CHANGELOG
2018-03-20 05:30:31 +01:00
Fabien Potencier c35ad8c4e3 bumped version to 1.35.4-DEV 2018-03-20 05:26:35 +01:00
Fabien Potencier b48680b6eb prepared the 1.35.3 release v1.35.3 2018-03-20 05:25:58 +01:00
Fabien Potencier dc53726ff0 updated CHANGELOG 2018-03-20 05:25:36 +01:00
Fabien Potencier f7f866e5fd Merge branch '1.x' into 2.x
* 1.x:
  fixed block names unicity
2018-03-20 05:05:46 +01:00
Fabien Potencier 4b14c38ad5 bug #2664 Fix block names unicity (fabpot)
This PR was merged into the 1.x branch.

Discussion
----------

Fix block names unicity

closes #2658

Commits
-------

6da72c6d fixed block names unicity
2018-03-20 05:05:35 +01:00
Fabien Potencier 6da72c6d8c fixed block names unicity 2018-03-20 04:57:51 +01:00