From cd4ab0fde6eb691d0e4dc109d2b07d857ee02406 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Sat, 5 Jan 2013 08:55:59 +0100 Subject: [PATCH] renamed the raw tag to verbatim to avoid confusion with the raw filter --- CHANGELOG | 1 + doc/api.rst | 2 +- doc/tags/index.rst | 2 +- doc/tags/raw.rst | 16 ------ doc/tags/verbatim.rst | 24 ++++++++ doc/templates.rst | 3 +- lib/Twig/Lexer.php | 4 +- test/Twig/Tests/Fixtures/tags/verbatim/basic.test | 10 ++++ .../Fixtures/tags/verbatim/whitespace_control.test | 56 ++++++++++++++++++++ 9 files changed, 97 insertions(+), 21 deletions(-) delete mode 100644 doc/tags/raw.rst create mode 100644 doc/tags/verbatim.rst create mode 100644 test/Twig/Tests/Fixtures/tags/verbatim/basic.test create mode 100644 test/Twig/Tests/Fixtures/tags/verbatim/whitespace_control.test diff --git a/CHANGELOG b/CHANGELOG index a152b91..2fcd732 100644 --- a/CHANGELOG +++ b/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 diff --git a/doc/api.rst b/doc/api.rst index 73470c4..9160c3f 100644 --- a/doc/api.rst +++ b/doc/api.rst @@ -351,7 +351,7 @@ The ``core`` extension defines all the core features of Twig: * ``do`` * ``embed`` * ``flush`` - * ``raw`` + * ``verbatim`` * ``sandbox`` * ``use`` diff --git a/doc/tags/index.rst b/doc/tags/index.rst index fe0a00f..6dbc550 100644 --- a/doc/tags/index.rst +++ b/doc/tags/index.rst @@ -17,7 +17,7 @@ Tags use spaceless autoescape - raw + verbatim flush do sandbox diff --git a/doc/tags/raw.rst b/doc/tags/raw.rst deleted file mode 100644 index 4136c70..0000000 --- a/doc/tags/raw.rst +++ /dev/null @@ -1,16 +0,0 @@ -``raw`` -======= - -The ``raw`` 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 - - {% raw %} - - {% endraw %} diff --git a/doc/tags/verbatim.rst b/doc/tags/verbatim.rst new file mode 100644 index 0000000..fe61ca1 --- /dev/null +++ b/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 %} + + {% 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. \ No newline at end of file diff --git a/doc/templates.rst b/doc/templates.rst index 93f3108..a23fcb6 100644 --- a/doc/templates.rst +++ b/doc/templates.rst @@ -489,7 +489,8 @@ expression: {{ '{{' }} -For bigger sections it makes sense to mark a block :doc:`raw`. +For bigger sections it makes sense to mark a block +:doc:`verbatim`. Macros ------ diff --git a/lib/Twig/Lexer.php b/lib/Twig/Lexer.php index d77071d..86d9639 100644 --- a/lib/Twig/Lexer.php +++ b/lib/Twig/Lexer.php @@ -61,10 +61,10 @@ class Twig_Lexer implements Twig_LexerInterface $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', diff --git a/test/Twig/Tests/Fixtures/tags/verbatim/basic.test b/test/Twig/Tests/Fixtures/tags/verbatim/basic.test new file mode 100644 index 0000000..a95be55 --- /dev/null +++ b/test/Twig/Tests/Fixtures/tags/verbatim/basic.test @@ -0,0 +1,10 @@ +--TEST-- +"verbatim" tag +--TEMPLATE-- +{% verbatim %} +{{ foo }} +{% endverbatim %} +--DATA-- +return array() +--EXPECT-- +{{ foo }} diff --git a/test/Twig/Tests/Fixtures/tags/verbatim/whitespace_control.test b/test/Twig/Tests/Fixtures/tags/verbatim/whitespace_control.test new file mode 100644 index 0000000..eb61044 --- /dev/null +++ b/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*** -- 1.7.2.5