Add Twig cache generator and bypass escape option
- Add script to generate cache files for all Twig templates - Add option in Twig extension that bypass autoescaping Signed-off-by: Maurício Meneghini Fauth <mauriciofauth@gmail.com>
This commit is contained in:
parent
5b8415848a
commit
d71e097593
@ -58,8 +58,9 @@ class Template
|
||||
|
||||
$loader = new Twig_Loader_Filesystem(static::BASE_PATH);
|
||||
$this->twig = new Twig_Environment($loader, array(
|
||||
'debug' => false,
|
||||
'auto_reload' => true,
|
||||
'cache' => CACHE_DIR . 'twig',
|
||||
'debug' => false,
|
||||
));
|
||||
$this->twig->addExtension(new I18nExtension());
|
||||
$this->twig->addExtension(new UrlExtension());
|
||||
|
||||
@ -22,7 +22,7 @@ class I18nExtension extends Twig_Extensions_Extension_I18n
|
||||
*/
|
||||
public function getTokenParsers()
|
||||
{
|
||||
return array(new TokenParserTrans());
|
||||
return array(new i18n\TokenParserTrans());
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -17,28 +17,36 @@ use Twig_SimpleFunction;
|
||||
*/
|
||||
class UrlExtension extends Twig_Extension
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getFunctions()
|
||||
{
|
||||
return array(
|
||||
new Twig_SimpleFunction(
|
||||
'URL_getHiddenInputs',
|
||||
'PMA\libraries\URL::getHiddenInputs'
|
||||
'PMA\libraries\URL::getHiddenInputs',
|
||||
array('is_safe' => array('html'))
|
||||
),
|
||||
new Twig_SimpleFunction(
|
||||
'URL_getHiddenFields',
|
||||
'PMA\libraries\URL::getHiddenFields'
|
||||
'PMA\libraries\URL::getHiddenFields',
|
||||
array('is_safe' => array('html'))
|
||||
),
|
||||
new Twig_SimpleFunction(
|
||||
'URL_getCommon',
|
||||
'PMA\libraries\URL::getCommon'
|
||||
'PMA\libraries\URL::getCommon',
|
||||
array('is_safe' => array('html'))
|
||||
),
|
||||
new Twig_SimpleFunction(
|
||||
'URL_getCommonRaw',
|
||||
'PMA\libraries\URL::getCommonRaw'
|
||||
'PMA\libraries\URL::getCommonRaw',
|
||||
array('is_safe' => array('html'))
|
||||
),
|
||||
new Twig_SimpleFunction(
|
||||
'URL_getArgSeparator',
|
||||
'PMA\libraries\URL::getArgSeparator'
|
||||
'PMA\libraries\URL::getArgSeparator',
|
||||
array('is_safe' => array('html'))
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@ -1,11 +1,11 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* hold PMA\libraries\twig\NodeTrans class
|
||||
* hold PMA\libraries\twig\i18n\NodeTrans class
|
||||
*
|
||||
* @package PMA\libraries\twig
|
||||
* @package PMA\libraries\twig\i18n
|
||||
*/
|
||||
namespace PMA\libraries\twig;
|
||||
namespace PMA\libraries\twig\i18n;
|
||||
|
||||
use Twig_Compiler;
|
||||
use Twig_Extensions_Node_Trans;
|
||||
@ -15,7 +15,7 @@ use Twig_Node_Expression;
|
||||
/**
|
||||
* Class NodeTrans
|
||||
*
|
||||
* @package PMA\libraries\twig
|
||||
* @package PMA\libraries\twig\i18n
|
||||
*/
|
||||
class NodeTrans extends Twig_Extensions_Node_Trans
|
||||
{
|
||||
@ -1,11 +1,11 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* hold PMA\libraries\twig\TokenParserTrans class
|
||||
* hold PMA\libraries\twig\i18n\TokenParserTrans class
|
||||
*
|
||||
* @package PMA\libraries\twig
|
||||
* @package PMA\libraries\twig\i18n
|
||||
*/
|
||||
namespace PMA\libraries\twig;
|
||||
namespace PMA\libraries\twig\i18n;
|
||||
|
||||
use Twig_Extensions_TokenParser_Trans;
|
||||
use Twig_Token;
|
||||
@ -13,7 +13,7 @@ use Twig_Token;
|
||||
/**
|
||||
* Class TokenParserTrans
|
||||
*
|
||||
* @package PMA\libraries\twig
|
||||
* @package PMA\libraries\twig\i18n
|
||||
*/
|
||||
class TokenParserTrans extends Twig_Extensions_TokenParser_Trans
|
||||
{
|
||||
31
scripts/generate-twig-cache
Normal file
31
scripts/generate-twig-cache
Normal file
@ -0,0 +1,31 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4 ft=php: */
|
||||
define('PHPMYADMIN', 1);
|
||||
require_once 'vendor/autoload.php';
|
||||
require_once 'libraries/vendor_config.php';
|
||||
|
||||
use PMA\libraries\twig\I18nExtension;
|
||||
use PMA\libraries\twig\UrlExtension;
|
||||
|
||||
$tplDir = dirname(__FILE__) . '/../templates';
|
||||
$tmpDir = dirname(__FILE__) . '/../' . CACHE_DIR . 'twig';
|
||||
$loader = new Twig_Loader_Filesystem($tplDir);
|
||||
|
||||
// force auto-reload to always have the latest version of the template
|
||||
$twig = new Twig_Environment($loader, array(
|
||||
'cache' => $tmpDir,
|
||||
'auto_reload' => true
|
||||
));
|
||||
$twig->addExtension(new I18nExtension());
|
||||
$twig->addExtension(new UrlExtension());
|
||||
|
||||
// iterate over all templates
|
||||
foreach (new RecursiveIteratorIterator(
|
||||
new RecursiveDirectoryIterator($tplDir),
|
||||
RecursiveIteratorIterator::LEAVES_ONLY
|
||||
) as $file) {
|
||||
// force compilation
|
||||
if ($file->isFile() && $file->getExtension() == 'twig') {
|
||||
$twig->loadTemplate(str_replace($tplDir.'/', '', $file));
|
||||
}
|
||||
}
|
||||
@ -11,6 +11,9 @@ fi
|
||||
# Exit on failure
|
||||
set -e
|
||||
|
||||
# Generate Twig template cache
|
||||
php ./scripts/generate-twig-cache
|
||||
|
||||
# Update pot (template), ensure that advisor is at the end
|
||||
LOCS=`ls po/*.po | sed 's@.*/\(.*\)\.po@\1@'`
|
||||
xgettext \
|
||||
|
||||
Loading…
Reference in New Issue
Block a user