Skip to content

Commit

Permalink
merged branch fabpot/verbatim (PR #947)
Browse files Browse the repository at this point in the history
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).
  • Loading branch information
fabpot committed Jan 5, 2013
2 parents 720b71a + cd4ab0f commit ddd4b73
Show file tree
Hide file tree
Showing 9 changed files with 97 additions and 21 deletions.
1 change: 1 addition & 0 deletions CHANGELOG
@@ -1,5 +1,6 @@
* 1.12.0 (2012-XX-XX)

* renamed the raw tag to verbatim to avoid confusion with the raw filter (the raw tag still works though)
* fixed registration of tests and functions as anonymous functions
* fixed global management

Expand Down
2 changes: 1 addition & 1 deletion doc/api.rst
Expand Up @@ -351,7 +351,7 @@ The ``core`` extension defines all the core features of Twig:
* ``do``
* ``embed``
* ``flush``
* ``raw``
* ``verbatim``
* ``sandbox``
* ``use``

Expand Down
2 changes: 1 addition & 1 deletion doc/tags/index.rst
Expand Up @@ -17,7 +17,7 @@ Tags
use
spaceless
autoescape
raw
verbatim
flush
do
sandbox
Expand Down
16 changes: 0 additions & 16 deletions doc/tags/raw.rst

This file was deleted.

24 changes: 24 additions & 0 deletions doc/tags/verbatim.rst
@@ -0,0 +1,24 @@
``verbatim``
============

.. versionadded:: 1.12
The ``verbatim`` tag was added in Twig 1.12 (it was named ``raw`` before).

The ``verbatim`` tag marks sections as being raw text that should not be
parsed. For example to put Twig syntax as example into a template you can use
this snippet:

.. code-block:: jinja
{% verbatim %}
<ul>
{% for item in seq %}
<li>{{ item }}</li>
{% endfor %}
</ul>
{% endverbatim %}
.. note::

The ``verbatim`` tag works in the exact same way as the old ``raw`` tag,
but was renamed to avoid confusion with the ``raw`` filter.
3 changes: 2 additions & 1 deletion doc/templates.rst
Expand Up @@ -489,7 +489,8 @@ expression:
{{ '{{' }}
For bigger sections it makes sense to mark a block :doc:`raw<tags/raw>`.
For bigger sections it makes sense to mark a block
:doc:`verbatim<tags/verbatim>`.

Macros
------
Expand Down
4 changes: 2 additions & 2 deletions lib/Twig/Lexer.php
Expand Up @@ -61,10 +61,10 @@ public function __construct(Twig_Environment $env, array $options = array())
$this->regexes = array(
'lex_var' => '/\s*'.preg_quote($this->options['whitespace_trim'].$this->options['tag_variable'][1], '/').'\s*|\s*'.preg_quote($this->options['tag_variable'][1], '/').'/A',
'lex_block' => '/\s*(?:'.preg_quote($this->options['whitespace_trim'].$this->options['tag_block'][1], '/').'\s*|\s*'.preg_quote($this->options['tag_block'][1], '/').')\n?/A',
'lex_raw_data' => '/('.preg_quote($this->options['tag_block'][0].$this->options['whitespace_trim'], '/').'|'.preg_quote($this->options['tag_block'][0], '/').')\s*endraw\s*(?:'.preg_quote($this->options['whitespace_trim'].$this->options['tag_block'][1], '/').'\s*|\s*'.preg_quote($this->options['tag_block'][1], '/').')/s',
'lex_raw_data' => '/('.preg_quote($this->options['tag_block'][0].$this->options['whitespace_trim'], '/').'|'.preg_quote($this->options['tag_block'][0], '/').')\s*(?:endraw|endverbatim)\s*(?:'.preg_quote($this->options['whitespace_trim'].$this->options['tag_block'][1], '/').'\s*|\s*'.preg_quote($this->options['tag_block'][1], '/').')/s',
'operator' => $this->getOperatorRegex(),
'lex_comment' => '/(?:'.preg_quote($this->options['whitespace_trim'], '/').preg_quote($this->options['tag_comment'][1], '/').'\s*|'.preg_quote($this->options['tag_comment'][1], '/').')\n?/s',
'lex_block_raw' => '/\s*raw\s*(?:'.preg_quote($this->options['whitespace_trim'].$this->options['tag_block'][1], '/').'\s*|\s*'.preg_quote($this->options['tag_block'][1], '/').')/As',
'lex_block_raw' => '/\s*(?:raw|verbatim)\s*(?:'.preg_quote($this->options['whitespace_trim'].$this->options['tag_block'][1], '/').'\s*|\s*'.preg_quote($this->options['tag_block'][1], '/').')/As',
'lex_block_line' => '/\s*line\s+(\d+)\s*'.preg_quote($this->options['tag_block'][1], '/').'/As',
'lex_tokens_start' => '/('.preg_quote($this->options['tag_variable'][0], '/').'|'.preg_quote($this->options['tag_block'][0], '/').'|'.preg_quote($this->options['tag_comment'][0], '/').')('.preg_quote($this->options['whitespace_trim'], '/').')?/s',
'interpolation_start' => '/'.preg_quote($this->options['interpolation'][0], '/').'\s*/A',
Expand Down
10 changes: 10 additions & 0 deletions test/Twig/Tests/Fixtures/tags/verbatim/basic.test
@@ -0,0 +1,10 @@
--TEST--
"verbatim" tag
--TEMPLATE--
{% verbatim %}
{{ foo }}
{% endverbatim %}
--DATA--
return array()
--EXPECT--
{{ foo }}
56 changes: 56 additions & 0 deletions test/Twig/Tests/Fixtures/tags/verbatim/whitespace_control.test
@@ -0,0 +1,56 @@
--TEST--
"verbatim" tag
--TEMPLATE--
1***

{%- verbatim %}
{{ 'bla' }}
{% endverbatim %}

1***
2***

{%- verbatim -%}
{{ 'bla' }}
{% endverbatim %}

2***
3***

{%- verbatim -%}
{{ 'bla' }}
{% endverbatim -%}

3***
4***

{%- verbatim -%}
{{ 'bla' }}
{%- endverbatim %}

4***
5***

{%- verbatim -%}
{{ 'bla' }}
{%- endverbatim -%}

5***
--DATA--
return array()
--EXPECT--
1***
{{ 'bla' }}


1***
2***{{ 'bla' }}


2***
3***{{ 'bla' }}
3***
4***{{ 'bla' }}

4***
5***{{ 'bla' }}5***

0 comments on commit ddd4b73

Please sign in to comment.