mirror of
https://github.com/twigphp/Twig.git
synced 2026-09-14 11:27:00 +00:00
Inline original source code in compiled templates
This commit is contained in:
committed by
Fabien Potencier
parent
7d21eb9984
commit
c9fb3730c2
@@ -593,7 +593,13 @@ class Twig_Environment
|
||||
public function compileSource($source, $name = null)
|
||||
{
|
||||
try {
|
||||
return $this->compile($this->parse($this->tokenize($source, $name)));
|
||||
$compiled = $this->compile($this->parse($this->tokenize($source, $name)), $source);
|
||||
|
||||
if (isset($source[0])) {
|
||||
$compiled .= '// '.str_replace(array("\r\n", "\r", "\n"), "\n// ", $source)."\n";
|
||||
}
|
||||
|
||||
return $compiled;
|
||||
} catch (Twig_Error $e) {
|
||||
$e->setTemplateFile($name);
|
||||
throw $e;
|
||||
|
||||
@@ -138,6 +138,14 @@ class Twig_Tests_EnvironmentTest extends PHPUnit_Framework_TestCase
|
||||
*/
|
||||
}
|
||||
|
||||
public function testCompileSource()
|
||||
{
|
||||
$twig = new Twig_Environment($this->getMock('Twig_LoaderInterface'));
|
||||
|
||||
$expected = file_get_contents(__DIR__.'/Fixtures/environment-compile.php');
|
||||
$this->assertSame($expected, $twig->compileSource("{{ foo }}\n{{ bar }}\n", 'index'));
|
||||
}
|
||||
|
||||
public function testExtensionsAreNotInitializedWhenRenderingACompiledTemplate()
|
||||
{
|
||||
$options = array('cache' => sys_get_temp_dir().'/twig', 'auto_reload' => false, 'debug' => false);
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
/* index */
|
||||
class __TwigTemplate_e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 extends Twig_Template
|
||||
{
|
||||
public function __construct(Twig_Environment $env)
|
||||
{
|
||||
parent::__construct($env);
|
||||
|
||||
$this->parent = false;
|
||||
|
||||
$this->blocks = array(
|
||||
);
|
||||
}
|
||||
|
||||
protected function doDisplay(array $context, array $blocks = array())
|
||||
{
|
||||
// line 1
|
||||
echo twig_escape_filter($this->env, (isset($context["foo"]) ? $context["foo"] : null), "html", null, true);
|
||||
echo "
|
||||
";
|
||||
// line 2
|
||||
echo twig_escape_filter($this->env, (isset($context["bar"]) ? $context["bar"] : null), "html", null, true);
|
||||
echo "
|
||||
";
|
||||
}
|
||||
|
||||
public function getTemplateName()
|
||||
{
|
||||
return "index";
|
||||
}
|
||||
|
||||
public function isTraitable()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public function getDebugInfo()
|
||||
{
|
||||
return array ( 23 => 2, 19 => 1,);
|
||||
}
|
||||
}
|
||||
// {{ foo }}
|
||||
// {{ bar }}
|
||||
//
|
||||
Reference in New Issue
Block a user