[feature/twig] Append assets_version to includejs tag

Some fixes for main template parser

PHPBB3-11598
This commit is contained in:
Nathaniel Guse 2013-06-24 22:37:58 -05:00
parent 814d57d201
commit 3ca99f8122
5 changed files with 49 additions and 12 deletions

View file

@ -20,6 +20,9 @@ class phpbb_template_twig_environment extends Twig_Environment
/** @var array */
protected $phpbbExtensions;
/** @var phpbb_config */
protected $phpbbConfig;
/** @var array **/
protected $namespaceLookUpOrder = array('__main__');
@ -62,6 +65,29 @@ class phpbb_template_twig_environment extends Twig_Environment
return $this;
}
/**
* Get phpBB config
*
* @return phpbb_config
*/
public function get_phpbb_config()
{
return $this->phpbbConfig;
}
/**
* Set phpBB config
*
* @param phpbb_config $config
* @return Twig_Environment
*/
public function set_phpbb_config($config)
{
$this->phpbbConfig = $config;
return $this;
}
/**
* Get the namespace look up order
*

View file

@ -9,6 +9,7 @@
class phpbb_template_twig_node_event extends Twig_Node
{
/** @var Twig_Environment */
protected $environment;
public function __construct(Twig_Node_Expression $expr, phpbb_template_twig_environment $environment, $lineno, $tag = null)

View file

@ -9,8 +9,13 @@
class phpbb_template_twig_node_includejs extends Twig_Node
{
public function __construct(Twig_Node_Expression $expr, $lineno, $tag = null)
/** @var Twig_Environment */
protected $environment;
public function __construct(Twig_Node_Expression $expr, phpbb_template_twig_environment $environment, $lineno, $tag = null)
{
$this->environment = $environment;
parent::__construct(array('expr' => $expr), array(), $lineno, $tag);
}
@ -23,10 +28,12 @@ class phpbb_template_twig_node_includejs extends Twig_Node
{
$compiler->addDebugInfo($this);
$config = $this->environment->get_phpbb_config();
$compiler
->write("\$context['SCRIPTS'] .= '<script type=\"text/javascript\" src=\"' . ")
->subcompile($this->getNode('expr'))
->raw(" . '\">';\n\n")
->raw(" . '?assets_version=" . $config['assets_version'] . "\"></script>';\n\n")
;
}
}

View file

@ -23,7 +23,7 @@ class phpbb_template_twig_tokenparser_includejs extends Twig_TokenParser
$stream = $this->parser->getStream();
$stream->expect(Twig_Token::BLOCK_END_TYPE);
return new phpbb_template_twig_node_includejs($expr, $token->getLine(), $this->getTag());
return new phpbb_template_twig_node_includejs($expr, $this->parser->getEnvironment(), $token->getLine(), $this->getTag());
}
/**

View file

@ -127,6 +127,9 @@ class phpbb_template_twig implements phpbb_template
$this->twig->set_phpbb_extensions($this->extension_manager->all_enabled());
}
// Set config
$this->twig->set_phpbb_config($this->config);
// Clear previous cache files (while WIP)
// @todo remove
$this->clear_cache();
@ -187,7 +190,7 @@ class phpbb_template_twig implements phpbb_template
// Add admin namespace
// @todo use phpbb_admin path
$loader->addPath($this->phpbb_root_path . 'adm/style/', 'admin');
$this->twig->getLoader()->addPath($this->phpbb_root_path . 'adm/style/', 'admin');
// Add all namespaces for all extensions
if ($this->extension_manager instanceof phpbb_extension_manager)
@ -439,16 +442,16 @@ class phpbb_template_twig implements phpbb_template
$vars['L_' . strtoupper($key)] = $value;
$vars['LA_' . strtoupper($key)] = addslashes($value);
}
$vars = array_merge(
$vars,
$this->context->get_rootref(),
array(
'_phpbb_blocks' => $this->context->get_tpldata(),
)
);
}
$vars = array_merge(
$vars,
$this->context->get_rootref(),
array(
'_phpbb_blocks' => $this->context->get_tpldata(),
)
);
// Must do this so that <!-- IF .blah --> works correctly
// (only for the base loops, the rest are properly handled by the begin node)
foreach ($this->context->get_tpldata() as $block_name => $block_values)