From 550586745db321c5ee9b0a4bef4cd7998793b023 Mon Sep 17 00:00:00 2001 From: squidfunk Date: Tue, 12 Sep 2017 12:19:16 +0200 Subject: [PATCH 1/2] Removed trailing whitespace on empty lines --- .../Twig/Loaders/FilesystemLoader.php | 26 ++-- .../Twig/Loaders/PatternLoader.php | 26 ++-- .../Twig/Loaders/StringLoader.php | 28 ++-- .../Loaders/Twig/PatternPartialLoader.php | 88 +++++------ .../PatternEngine/Twig/PatternEngineRule.php | 10 +- .../PatternEngine/Twig/TwigUtil.php | 146 +++++++++--------- 6 files changed, 162 insertions(+), 162 deletions(-) diff --git a/src/PatternLab/PatternEngine/Twig/Loaders/FilesystemLoader.php b/src/PatternLab/PatternEngine/Twig/Loaders/FilesystemLoader.php index 38f99bd..5ce97a8 100644 --- a/src/PatternLab/PatternEngine/Twig/Loaders/FilesystemLoader.php +++ b/src/PatternLab/PatternEngine/Twig/Loaders/FilesystemLoader.php @@ -18,36 +18,36 @@ use \PatternLab\PatternEngine\Twig\TwigUtil; class FilesystemLoader extends Loader { - + /** * Load a new Twig instance that uses the File System Loader */ public function __construct($options = array()) { - + // set-up default vars $twigDebug = Config::getOption("twigDebug"); - + // set-up the paths to be searched for templates $filesystemLoaderPaths = array(); $filesystemLoaderPaths[] = $options["templatePath"]; $filesystemLoaderPaths[] = $options["partialsPath"]; - + // see if source/_macros exists. if so add it to be searchable $macrosPath = Config::getOption("sourceDir").DIRECTORY_SEPARATOR."_macros"; if (is_dir($macrosPath)) { $filesystemLoaderPaths[] = $macrosPath; } - + // see if source/_layouts exists. if so add it to be searchable $layoutsPath = Config::getOption("sourceDir").DIRECTORY_SEPARATOR."_layouts"; if (is_dir($layoutsPath)) { $filesystemLoaderPaths[] = $layoutsPath; } - + // set-up Twig $twigLoader = new \Twig_Loader_Filesystem($filesystemLoaderPaths); $instance = new \Twig_Environment($twigLoader, array("debug" => $twigDebug)); - + // customize Twig TwigUtil::setInstance($instance); TwigUtil::loadFilters(); @@ -57,7 +57,7 @@ public function __construct($options = array()) { TwigUtil::loadDateFormats(); TwigUtil::loadDebug(); TwigUtil::loadMacros(); - + // set-up the dispatcher $dispatcherInstance = Dispatcher::getInstance(); $dispatcherInstance->dispatch("twigLoader.customize"); @@ -65,9 +65,9 @@ public function __construct($options = array()) { // get the instance $this->instance = TwigUtil::getInstance(); - + } - + /** * Render a template * @param {Array} the options to be rendered by Twig @@ -75,9 +75,9 @@ public function __construct($options = array()) { * @return {String} the rendered result */ public function render($options = array()) { - + return $this->instance->render($options["template"].".".Config::getOption("patternExtension"), $options["data"]); - + } - + } diff --git a/src/PatternLab/PatternEngine/Twig/Loaders/PatternLoader.php b/src/PatternLab/PatternEngine/Twig/Loaders/PatternLoader.php index fa2ce2f..ee2e91d 100644 --- a/src/PatternLab/PatternEngine/Twig/Loaders/PatternLoader.php +++ b/src/PatternLab/PatternEngine/Twig/Loaders/PatternLoader.php @@ -21,25 +21,25 @@ use \PatternLab\PatternEngine\Twig\TwigUtil; class PatternLoader extends Loader { - + /** * Load a new Twig instance that uses the Pattern Loader */ public function __construct($options = array()) { - + // set-up default vars $twigDebug = Config::getOption("twigDebug"); $twigAutoescape = Config::getOption("twigAutoescape"); - + // go through various places where things can exist $filesystemLoaderPaths = array(); - + // see if source/_macros exists $macrosPath = Config::getOption("sourceDir").DIRECTORY_SEPARATOR."_macros"; if (is_dir($macrosPath)) { $filesystemLoaderPaths[] = $macrosPath; } - + // see if source/_layouts exists. if so add it to be searchable $layoutsPath = Config::getOption("sourceDir").DIRECTORY_SEPARATOR."_layouts"; if (is_dir($layoutsPath)) { @@ -60,7 +60,7 @@ public function __construct($options = array()) { $filesystemLoaderPaths[] = $object->getPathname(); } } - + // set-up the loader list in order that they should be checked // 1. Patterns 2. Filesystem 3. String $loaders = array(); @@ -85,11 +85,11 @@ public function __construct($options = array()) { // This *must* go last or no loaders after will work ~ https://github.com/symfony/symfony/issues/10865 // @todo Remove `Twig_Loader_String` - if a Twig include path is wrong, this outputs the string anyway with no error ~ https://github.com/symfony/symfony/issues/10865 $loaders[] = new \Twig_Loader_String(); - + // set-up Twig $twigLoader = new \Twig_Loader_Chain($loaders); $instance = new \Twig_Environment($twigLoader, array("debug" => $twigDebug, "autoescape" => $twigAutoescape)); - + // customize Twig TwigUtil::setInstance($instance); TwigUtil::loadFilters(); @@ -105,9 +105,9 @@ public function __construct($options = array()) { // get the instance $this->instance = TwigUtil::getInstance(); - + } - + /** * Render a pattern * @param {Array} the options to be rendered by Twig @@ -115,7 +115,7 @@ public function __construct($options = array()) { * @return {String} the rendered result */ public function render($options = array()) { - + $result = $this->instance->render($options["pattern"], $options["data"]); // This error handler catches files that didn't render using any of the loaders. // The most common scenario is when a file's contents get passed to and through `Twig_Loader_String` and @@ -127,7 +127,7 @@ public function render($options = array()) { } else { return $result; } - + } - + } diff --git a/src/PatternLab/PatternEngine/Twig/Loaders/StringLoader.php b/src/PatternLab/PatternEngine/Twig/Loaders/StringLoader.php index e81c9b7..ee284ee 100644 --- a/src/PatternLab/PatternEngine/Twig/Loaders/StringLoader.php +++ b/src/PatternLab/PatternEngine/Twig/Loaders/StringLoader.php @@ -18,30 +18,30 @@ use \PatternLab\PatternEngine\Twig\TwigUtil; class StringLoader extends Loader { - + /** * Load a new Twig instance that is just a vanilla Twig rendering engine for strings */ public function __construct($options = array()) { - + // set-up the defaults $twigDebug = Config::getOption("twigDebug"); - + // go through various places where things can exist $filesystemLoaderPaths = array(); - + // see if source/_macros exists $macrosPath = Config::getOption("sourceDir").DIRECTORY_SEPARATOR."_macros"; if (is_dir($macrosPath)) { $filesystemLoaderPaths[] = $macrosPath; } - + // see if source/_layouts exists. if so add it to be searchable $layoutsPath = Config::getOption("sourceDir").DIRECTORY_SEPARATOR."_layouts"; if (is_dir($layoutsPath)) { $filesystemLoaderPaths[] = $layoutsPath; } - + // set-up the loader list $loaders = array(); // add the paths to the filesystem loader if the paths existed @@ -49,11 +49,11 @@ public function __construct($options = array()) { $loaders[] = new \Twig_Loader_Filesystem($filesystemLoaderPaths); } $loaders[] = new \Twig_Loader_String(); - + // set-up Twig $twigLoader = new \Twig_Loader_Chain($loaders); $instance = new \Twig_Environment($twigLoader, array("debug" => $twigDebug)); - + // customize Twig TwigUtil::setInstance($instance); TwigUtil::loadFilters(); @@ -63,7 +63,7 @@ public function __construct($options = array()) { TwigUtil::loadDateFormats(); TwigUtil::loadDebug(); TwigUtil::loadMacros(); - + // set-up the dispatcher $dispatcherInstance = Dispatcher::getInstance(); $dispatcherInstance->dispatch("twigLoader.customize"); @@ -71,9 +71,9 @@ public function __construct($options = array()) { // get the instance $this->instance = TwigUtil::getInstance(); - + } - + /** * Render a string * @param {Array} the options to be rendered by Twig @@ -81,9 +81,9 @@ public function __construct($options = array()) { * @return {String} the rendered result */ public function render($options = array()) { - + return $this->instance->render($options["string"], $options["data"]); - + } - + } diff --git a/src/PatternLab/PatternEngine/Twig/Loaders/Twig/PatternPartialLoader.php b/src/PatternLab/PatternEngine/Twig/Loaders/Twig/PatternPartialLoader.php index 0f7fe06..607e9aa 100644 --- a/src/PatternLab/PatternEngine/Twig/Loaders/Twig/PatternPartialLoader.php +++ b/src/PatternLab/PatternEngine/Twig/Loaders/Twig/PatternPartialLoader.php @@ -16,15 +16,15 @@ use \PatternLab\PatternEngine\Util; class PatternPartialLoader implements \Twig_LoaderInterface, \Twig_ExistsLoaderInterface { - + /** Identifier of the main namespace. */ const MAIN_NAMESPACE = '__main__'; - + protected $paths = array(); protected $cache = array(); protected $patternPaths = array(); protected $extension = '.twig'; - + /** * Constructor. * @@ -35,12 +35,12 @@ public function __construct($paths = array(),$patternPaths = array()) { $this->setPaths($paths); } $options['patternPaths'] = $patternPaths['patternPaths']; - + // load some extra functions to help with manipulating pattern info $this->patternUtil = new Util($options); - + } - + /** * Returns the paths to the templates. * @@ -51,7 +51,7 @@ public function __construct($paths = array(),$patternPaths = array()) { public function getPaths($namespace = self::MAIN_NAMESPACE) { return isset($this->paths[$namespace]) ? $this->paths[$namespace] : array(); } - + /** * Returns the path namespaces. * @@ -62,7 +62,7 @@ public function getPaths($namespace = self::MAIN_NAMESPACE) { public function getNamespaces() { return array_keys($this->paths); } - + /** * Sets the paths where templates are stored. * @@ -73,13 +73,13 @@ public function setPaths($paths, $namespace = self::MAIN_NAMESPACE) { if (!is_array($paths)) { $paths = array($paths); } - + $this->paths[$namespace] = array(); foreach ($paths as $path) { $this->addPath($path, $namespace); } } - + /** * Adds a path where templates are stored. * @@ -91,14 +91,14 @@ public function setPaths($paths, $namespace = self::MAIN_NAMESPACE) { public function addPath($path, $namespace = self::MAIN_NAMESPACE) { // invalidate the cache $this->cache = array(); - + if (!is_dir($path)) { throw new \Twig_Error_Loader(sprintf('The "%s" directory does not exist.', $path)); } - + $this->paths[$namespace][] = rtrim($path, '/\\'); } - + /** * Prepends a path where templates are stored. * @@ -110,111 +110,111 @@ public function addPath($path, $namespace = self::MAIN_NAMESPACE) { public function prependPath($path, $namespace = self::MAIN_NAMESPACE) { // invalidate the cache $this->cache = array(); - + if (!is_dir($path)) { throw new \Twig_Error_Loader(sprintf('The "%s" directory does not exist.', $path)); } - + $path = rtrim($path, '/\\'); - + if (!isset($this->paths[$namespace])) { $this->paths[$namespace][] = $path; } else { array_unshift($this->paths[$namespace], $path); } - + } - + /** * {@inheritdoc} */ public function getSource($name) { return file_get_contents($this->findTemplate($name)); } - + /** * {@inheritdoc} */ public function getCacheKey($name) { return $this->findTemplate($name); } - + /** * {@inheritdoc} */ public function exists($name) { - + $name = $this->normalizeName($name); - + if (isset($this->cache[$name])) { return true; } - + try { $this->findTemplate($name); - + return true; } catch (\Twig_Error_Loader $exception) { return false; } } - + /** * {@inheritdoc} */ public function isFresh($name, $time) { return filemtime($this->findTemplate($name)) <= $time; } - + protected function findTemplate($name) { - + list($partialName,$styleModifier,$parameters) = $this->patternUtil->getPartialInfo($name); - + $name = $this->patternUtil->getFileName($partialName,$this->extension); - + $name = $this->normalizeName($name); - + if (isset($this->cache[$name])) { return $this->cache[$name]; } - + $this->validateName($name); - + $namespace = self::MAIN_NAMESPACE; $shortname = $name; if (isset($name[0]) && '@' == $name[0]) { if (false === $pos = strpos($name, '/')) { throw new \Twig_Error_Loader(sprintf('Malformed namespaced template name "%s" (expecting "@namespace/template_name").', $name)); } - + $namespace = substr($name, 1, $pos - 1); $shortname = substr($name, $pos + 1); } - + if (!isset($this->paths[$namespace])) { throw new \Twig_Error_Loader(sprintf('There are no registered paths for namespace "%s".', $namespace)); } - + foreach ($this->paths[$namespace] as $path) { if (is_file($path.'/'.$shortname)) { return $this->cache[$name] = $path.'/'.$shortname; } } - - + + throw new \Twig_Error_Loader(sprintf('Unable to find template "%s" (looked into: %s).', $partialName, implode(', ', $this->paths[$namespace]))); } - + protected function normalizeName($name) { return preg_replace('#/{2,}#', '/', strtr((string) $name, '\\', '/')); } - + protected function validateName($name) { - + if (false !== strpos($name, "\0")) { throw new \Twig_Error_Loader('A template name cannot contain NUL bytes.'); } - + $name = ltrim($name, '/'); $parts = explode('/', $name); $level = 0; @@ -224,12 +224,12 @@ protected function validateName($name) { } elseif ('.' !== $part) { ++$level; } - + if ($level < 0) { throw new \Twig_Error_Loader(sprintf('Looks like you try to load a template outside configured directories (%s).', $name)); } } - + } - + } diff --git a/src/PatternLab/PatternEngine/Twig/PatternEngineRule.php b/src/PatternLab/PatternEngine/Twig/PatternEngineRule.php index 0162285..f8668bd 100644 --- a/src/PatternLab/PatternEngine/Twig/PatternEngineRule.php +++ b/src/PatternLab/PatternEngine/Twig/PatternEngineRule.php @@ -15,14 +15,14 @@ use \PatternLab\PatternEngine\Rule; class PatternEngineRule extends Rule { - + public function __construct() { - + parent::__construct(); - + $this->engineProp = "twig"; $this->basePath = "\PatternLab\PatternEngine\Twig"; - + } - + } diff --git a/src/PatternLab/PatternEngine/Twig/TwigUtil.php b/src/PatternLab/PatternEngine/Twig/TwigUtil.php index 64f97da..b7db10e 100644 --- a/src/PatternLab/PatternEngine/Twig/TwigUtil.php +++ b/src/PatternLab/PatternEngine/Twig/TwigUtil.php @@ -17,7 +17,7 @@ use \Symfony\Component\Finder\Finder; class TwigUtil { - + protected static $instance = ''; protected static $loaders = array(); @@ -27,25 +27,25 @@ class TwigUtil { * @return {Instance} an instance of the Twig environment */ public static function getInstance() { - + if (empty(self::$instance)) { return false; } - + return self::$instance; - + } - + /** * Set an instance of the Twig environment * @param {Instance} an instance of the Twig environment */ public static function setInstance($instance = "") { - + if (empty($instance) || !method_exists($instance,'addGlobal')) { Console::writeError("please set the instance"); } - + self::$instance = $instance; } @@ -88,7 +88,7 @@ public static function addLoader($loader) { self::$loaders[] = $loader; } - + /** * Registering each directory under `_patterns/` as a namespace. For example, `_patterns/00-atoms/` as `@atoms` * @param {Instance} an instance of the filesystem Loader @@ -97,7 +97,7 @@ public static function addLoader($loader) { * @return {Instance} an instance of the filesystem Loader */ public static function addPaths($filesystemLoader, $patternSourceDir) { - + $finder = new Finder(); $finder->directories()->depth(0)->in($patternSourceDir); foreach ($finder as $file) { @@ -106,217 +106,217 @@ public static function addPaths($filesystemLoader, $patternSourceDir) { $patternTypePath = (((int)$patternBits[0] != 0) || ($patternBits[0] == '00')) ? $patternBits[1] : $pattern; $filesystemLoader->addPath($file->getPathName(), $patternTypePath); } - + return $filesystemLoader; - + } - + /** * Load custom date formats for Twig */ public static function loadDateFormats() { - + $dateFormat = Config::getOption("twigDefaultDateFormat"); $intervalFormat = Config::getOption("twigDefaultIntervalFormat"); - + if ($dateFormat && $intervalFormat && !empty($dateFormat) && !empty($intervalFormat)) { self::$instance->getExtension("core")->setDateFormat($dateFormat, $intervalFormat); } - + } - + /** * Enable the debug options for Twig */ public static function loadDebug() { - + if (Config::getOption("twigDebug")) { self::$instance->addExtension(new \Twig_Extension_Debug()); } - + } - + /** * Load filters for the Twig PatternEngine */ public static function loadFilters() { - + // load defaults $filterDir = Config::getOption("sourceDir").DIRECTORY_SEPARATOR."_twig-components/filters"; $filterExt = Config::getOption("twigFilterExt"); $filterExt = $filterExt ? $filterExt : "filter.php"; - + if (is_dir($filterDir)) { - + // loop through the filter dir... $finder = new Finder(); $finder->files()->name("*\.".$filterExt)->in($filterDir); $finder->sortByName(); foreach ($finder as $file) { - + // see if the file should be ignored or not $baseName = $file->getBasename(); if ($baseName[0] != "_") { - + include($file->getPathname()); - + // $filter should be defined in the included file if (isset($filter)) { self::$instance->addFilter($filter); unset($filter); } - + } - + } - + } - + } - + /** * Load functions for the Twig PatternEngine */ public static function loadFunctions() { - + // load defaults $functionDir = Config::getOption("sourceDir").DIRECTORY_SEPARATOR."_twig-components/functions"; $functionExt = Config::getOption("twigFunctionExt"); $functionExt = $functionExt ? $functionExt : "function.php"; - + if (is_dir($functionDir)) { - + // loop through the function dir... $finder = new Finder(); $finder->files()->name("*\.".$functionExt)->in($functionDir); $finder->sortByName(); foreach ($finder as $file) { - + // see if the file should be ignored or not $baseName = $file->getBasename(); if ($baseName[0] != "_") { - + include($file->getPathname()); - + // $function should be defined in the included file if (isset($function)) { self::$instance->addFunction($function); unset($function); } - + } - + } - + } - + } - + /** * Load macros for the Twig PatternEngine */ public static function loadMacros() { - + // load defaults $macroDir = Config::getOption("sourceDir").DIRECTORY_SEPARATOR."_macros"; $macroExt = Config::getOption("twigMacroExt"); $macroExt = $macroExt ? $macroExt : "macro.twig"; - + if (is_dir($macroDir)) { - + // loop through some macro containing dir and run... $finder = new Finder(); $finder->files()->name("*.".$macroExt)->in($macroDir); $finder->sortByName(); foreach ($finder as $file) { - + // see if the file should be ignored $baseName = $file->getBasename(); if ($baseName[0] != "_") { - + // add the macro to the global context self::$instance->addGlobal($file->getBasename(".".$macroExt), self::$instance->loadTemplate($baseName)); - + } - + } - + } - + } - + /** * Load tags for the Twig PatternEngine */ public static function loadTags() { - + // load defaults $tagDir = Config::getOption("sourceDir").DIRECTORY_SEPARATOR."_twig-components/tags"; $tagExt = Config::getOption("twigTagExt"); $tagExt = $tagExt ? $tagExt : "tag.php"; - + if (is_dir($tagDir)) { - + // loop through the tags and instantiate the class... $finder = new Finder(); $finder->files()->name("*\.".$tagExt)->in($tagDir); $finder->sortByName(); foreach ($finder as $file) { - + // see if the file should be ignored or not $baseName = $file->getBasename(); if ($baseName[0] != "_") { - + include($file->getPathname()); - + // Project_{filenameBase}_TokenParser should be defined in the include $className = "Project_".$file->getBasename(".".$tagExt)."_TokenParser"; self::$instance->addTokenParser(new $className()); - + } - + } - + } - + } - + /** * Load functions for the Twig PatternEngine */ public static function loadTests() { - + // load defaults $testDir = Config::getOption("sourceDir").DIRECTORY_SEPARATOR."_twig-components/tests"; $testExt = Config::getOption("twigTestExt"); $testExt = $testExt ? $testExt : "test.php"; - + if (is_dir($testDir)) { - + // loop through the test dir... $finder = new Finder(); $finder->files()->name("*\.".$testExt)->in($testDir); $finder->sortByName(); foreach ($finder as $file) { - + // see if the file should be ignored or not $baseName = $file->getBasename(); if ($baseName[0] != "_") { - + include($file->getPathname()); - + // $test should be defined in the included file if (isset($test)) { self::$instance->addTest($test); unset($test); } - + } - + } - + } - + } - + } From 14a4d539ab6030f74362c731545b69d78497e241 Mon Sep 17 00:00:00 2001 From: squidfunk Date: Tue, 12 Sep 2017 12:31:34 +0200 Subject: [PATCH 2/2] Proof-of-concept upgrade to Twig 2.x --- composer.json | 2 +- .../Twig/Loaders/PatternLoader.php | 21 ++----------------- .../Twig/Loaders/StringLoader.php | 7 +++---- .../Loaders/Twig/PatternPartialLoader.php | 9 +++++++- 4 files changed, 14 insertions(+), 25 deletions(-) diff --git a/composer.json b/composer.json index 2108fdc..b1ac152 100644 --- a/composer.json +++ b/composer.json @@ -25,7 +25,7 @@ }, "require": { "pattern-lab/core": "^2.0.0", - "twig/twig": "~1.0" + "twig/twig": "^2.0.0" }, "extra": { "patternlab": { diff --git a/src/PatternLab/PatternEngine/Twig/Loaders/PatternLoader.php b/src/PatternLab/PatternEngine/Twig/Loaders/PatternLoader.php index ee2e91d..21abc7d 100644 --- a/src/PatternLab/PatternEngine/Twig/Loaders/PatternLoader.php +++ b/src/PatternLab/PatternEngine/Twig/Loaders/PatternLoader.php @@ -81,11 +81,6 @@ public function __construct($options = array()) { // getting the loaders back $loaders = TwigUtil::getLoaders(); - // 3. add String loader - // This *must* go last or no loaders after will work ~ https://github.com/symfony/symfony/issues/10865 - // @todo Remove `Twig_Loader_String` - if a Twig include path is wrong, this outputs the string anyway with no error ~ https://github.com/symfony/symfony/issues/10865 - $loaders[] = new \Twig_Loader_String(); - // set-up Twig $twigLoader = new \Twig_Loader_Chain($loaders); $instance = new \Twig_Environment($twigLoader, array("debug" => $twigDebug, "autoescape" => $twigAutoescape)); @@ -105,7 +100,6 @@ public function __construct($options = array()) { // get the instance $this->instance = TwigUtil::getInstance(); - } /** @@ -115,19 +109,8 @@ public function __construct($options = array()) { * @return {String} the rendered result */ public function render($options = array()) { - - $result = $this->instance->render($options["pattern"], $options["data"]); - // This error handler catches files that didn't render using any of the loaders. - // The most common scenario is when a file's contents get passed to and through `Twig_Loader_String` and - // outputs the raw Twig file contents like `@atoms/buttons/button.twig`. - // @todo Remove this once `Twig_Loader_String` is removed. - if (strpos($result, "@") === 0) { - echo "Twig file not found: " . $result . "\n"; - exit(1); - } else { - return $result; - } - + $template = $this->instance->createTemplate($options["pattern"]); + return $template->render($options["data"]); } } diff --git a/src/PatternLab/PatternEngine/Twig/Loaders/StringLoader.php b/src/PatternLab/PatternEngine/Twig/Loaders/StringLoader.php index ee284ee..f9ce2fa 100644 --- a/src/PatternLab/PatternEngine/Twig/Loaders/StringLoader.php +++ b/src/PatternLab/PatternEngine/Twig/Loaders/StringLoader.php @@ -48,7 +48,7 @@ public function __construct($options = array()) { if (count($filesystemLoaderPaths) > 0) { $loaders[] = new \Twig_Loader_Filesystem($filesystemLoaderPaths); } - $loaders[] = new \Twig_Loader_String(); + $loaders[] = new \Twig_Loader_Array(); // set-up Twig $twigLoader = new \Twig_Loader_Chain($loaders); @@ -81,9 +81,8 @@ public function __construct($options = array()) { * @return {String} the rendered result */ public function render($options = array()) { - - return $this->instance->render($options["string"], $options["data"]); - + $template = $this->instance->createTemplate($options["string"]); + return $template->render($options["data"]); } } diff --git a/src/PatternLab/PatternEngine/Twig/Loaders/Twig/PatternPartialLoader.php b/src/PatternLab/PatternEngine/Twig/Loaders/Twig/PatternPartialLoader.php index 607e9aa..d5b891f 100644 --- a/src/PatternLab/PatternEngine/Twig/Loaders/Twig/PatternPartialLoader.php +++ b/src/PatternLab/PatternEngine/Twig/Loaders/Twig/PatternPartialLoader.php @@ -38,7 +38,6 @@ public function __construct($paths = array(),$patternPaths = array()) { // load some extra functions to help with manipulating pattern info $this->patternUtil = new Util($options); - } /** @@ -122,7 +121,15 @@ public function prependPath($path, $namespace = self::MAIN_NAMESPACE) { } else { array_unshift($this->paths[$namespace], $path); } + } + /** + * {@inheritdoc} + */ + public function getSourceContext($name) { + $path = $this->findTemplate($name); + $template = file_get_contents($path); + return new \Twig_Source($template, $name, $path); } /**