Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge branch '1.x'
* 1.x:
  Fix two failed unit tests on Windows:
  updated CHANGELOG
  Reduce the name of the cache directories to 1 character
  clean ups
  bumped version to 1.18.2-DEV
  prepared the 1.18.1 release
  updated CHANGELOG
  Cleanup API - make the compiler happy
  Fixed memory leaks
  tweaked docs about the C extension
  removed an obsolete recipe

Conflicts:
	CHANGELOG
	doc/api.rst
	doc/recipes.rst
	ext/twig/php_twig.h
	lib/Twig/Environment.php
	lib/Twig/NodeTraverser.php
	lib/Twig/Template.php
  • Loading branch information
fabpot committed May 16, 2015
2 parents e8ab066 + ca76ad9 commit 56e515b
Show file tree
Hide file tree
Showing 28 changed files with 151 additions and 198 deletions.
7 changes: 6 additions & 1 deletion CHANGELOG
Expand Up @@ -8,8 +8,13 @@
* improved the performance of the filesystem loader
* removed features that were deprecated in 1.x

* 1.18.1 (2015-XX-XX)
* 1.18.2 (2015-XX-XX)

* optimized the number of inodes and the size of realpath cache when using the cache

* 1.18.1 (2015-04-19)

* fixed memory leaks in the C extension
* deprecated Twig_Loader_String
* fixed the slice filter when used with a SimpleXMLElement object
* fixed filesystem loader when trying to load non-files (like directories)
Expand Down
3 changes: 2 additions & 1 deletion doc/api.rst
Expand Up @@ -99,7 +99,8 @@ The following options are available:
callback cannot be a function name to avoid collision with built-in escaping
strategies); set it to ``false`` to disable auto-escaping. The ``filename``
escaping strategy determines the escaping strategy to use for a template
based on the template filename extension.
based on the template filename extension (this strategy does not incur any
overhead at runtime as auto-escaping is done at compilation time.)

* ``optimizations``: A flag that indicates which optimizations to apply
(default to ``-1`` -- all optimizations are enabled; set it to ``0`` to
Expand Down
7 changes: 5 additions & 2 deletions doc/installation.rst
Expand Up @@ -34,8 +34,11 @@ Installing the C extension
--------------------------

.. note::
The C extension is **optional** but as it brings some nice performance
improvements, you might want to install it in your production environment.

The C extension is **optional** but it brings some nice performance
improvements. Note that the extension is not a replacement for the PHP
code; it only implements a small part of the PHP code to improve the
performance at runtime; you must still install the regular PHP code.

Twig comes with a C extension that enhances the performance of the Twig
runtime engine; install it like any other PHP extensions:
Expand Down
47 changes: 0 additions & 47 deletions doc/recipes.rst
Expand Up @@ -316,53 +316,6 @@ This can be easily achieved with the following code::
return $node;
}

Using the Template name to set the default Escaping Strategy
------------------------------------------------------------

The ``autoescape`` option determines the default escaping strategy to use when
no escaping is applied on a variable. When Twig is used to mostly generate
HTML files, you can set it to ``html`` and explicitly change it to ``js`` when
you have some dynamic JavaScript files thanks to the ``autoescape`` tag:

.. code-block:: jinja
{% autoescape 'js' %}
... some JS ...
{% endautoescape %}
But if you have many HTML and JS files, and if your template names follow some
conventions, you can instead determine the default escaping strategy to use
based on the template name. Let's say that your template names always end
with ``.html`` for HTML files, ``.js`` for JavaScript ones, and ``.css`` for
stylesheets, here is how you can configure Twig::

class TwigEscapingGuesser
{
function guess($filename)
{
// get the format
$format = substr($filename, strrpos($filename, '.') + 1);

switch ($format) {
case 'js':
return 'js';
case 'css':
return 'css';
case 'html':
default:
return 'html';
}
}
}

$loader = new Twig_Loader_Filesystem('/path/to/templates');
$twig = new Twig_Environment($loader, array(
'autoescape' => array(new TwigEscapingGuesser(), 'guess'),
));

This dynamic strategy does not incur any overhead at runtime as auto-escaping
is done at compilation time.

Using a Database to store Templates
-----------------------------------

Expand Down
4 changes: 4 additions & 0 deletions ext/twig/php_twig.h
Expand Up @@ -21,11 +21,15 @@

extern zend_module_entry twig_module_entry;
#define phpext_twig_ptr &twig_module_entry
#ifndef PHP_WIN32
zend_module_entry *get_module(void);
#endif

#ifdef ZTS
#include "TSRM.h"
#endif

PHP_FUNCTION(twig_template_get_attributes);
PHP_RSHUTDOWN_FUNCTION(twig);

#endif

0 comments on commit 56e515b

Please sign in to comment.