/**
  * 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
     $dirPaths = array();
     $dirPaths[] = $options["templatePath"];
     $dirPaths[] = $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)) {
         $dirPaths[] = $macrosPath;
     }
     // see if source/_layouts exists. if so add it to be searchable
     $layoutsPath = Config::getOption("sourceDir") . DIRECTORY_SEPARATOR . "_layouts";
     if (is_dir($layoutsPath)) {
         $dirPaths[] = $layoutsPath;
     }
     // set-up Twig
     $twigLoader = new \Twig_Loader_Filesystem($dirPaths);
     $this->instance = new \Twig_Environment($twigLoader, array("debug" => $twigDebug));
     // customize Twig
     $this->instance = TwigUtil::loadFilters($this->instance);
     $this->instance = TwigUtil::loadFunctions($this->instance);
     $this->instance = TwigUtil::loadTags($this->instance);
     $this->instance = TwigUtil::loadTests($this->instance);
     $this->instance = TwigUtil::loadDateFormats($this->instance);
     $this->instance = TwigUtil::loadDebug($this->instance);
     $this->instance = TwigUtil::loadMacros($this->instance);
     $this->instance = TwigUtil::loadGlobalExtensions($this->instance);
     $this->instance = TwigUtil::setEscapingStrategy($this->instance);
 }
 /**
  * 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");
     // set-up the loader list
     $loaders = array();
     $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;
     }
     // add the paths to the filesystem loader if the paths existed
     if (count($filesystemLoaderPaths) > 0) {
         $loaders[] = new \Twig_Loader_Filesystem($filesystemLoaderPaths);
     }
     $loaders[] = new \Twig_Loader_String();
     // set-up Twig
     $twigLoader = new \Twig_Loader_Chain($loaders);
     $this->instance = new \Twig_Environment($twigLoader, array("debug" => $twigDebug));
     // customize the loader
     $this->instance = TwigUtil::loadFilters($this->instance);
     $this->instance = TwigUtil::loadFunctions($this->instance);
     $this->instance = TwigUtil::loadTags($this->instance);
     $this->instance = TwigUtil::loadTests($this->instance);
     $this->instance = TwigUtil::loadDateFormats($this->instance);
     $this->instance = TwigUtil::loadDebug($this->instance);
     $this->instance = TwigUtil::loadMacros($this->instance);
 }
 /**
  * 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");
     // set-up the loader list
     $loaders = array();
     $filesystemLoaderPaths = array();
     $loaders[] = new Twig_Loader_PatternPartialLoader(Config::getOption("patternSourceDir"), array("patternPaths" => $options["patternPaths"]));
     // 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;
     }
     // add source/_patterns subdirectories for Drupal theme template compatibility
     $patternSourceDir = Config::getOption("sourceDir") . DIRECTORY_SEPARATOR . "_patterns";
     $patternObjects = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($patternSourceDir), \RecursiveIteratorIterator::SELF_FIRST);
     $patternObjects->setFlags(\FilesystemIterator::SKIP_DOTS);
     // sort the returned objects
     $patternObjects = iterator_to_array($patternObjects);
     ksort($patternObjects);
     foreach ($patternObjects as $name => $object) {
         if ($object->isDir()) {
             $filesystemLoaderPaths[] = $object->getPathname();
         }
     }
     // add the paths to the filesystem loader if the paths existed
     if (count($filesystemLoaderPaths) > 0) {
         $loaders[] = new \Twig_Loader_Filesystem($filesystemLoaderPaths);
     }
     $loaders[] = new \Twig_Loader_String();
     // set-up Twig
     $twigLoader = new \Twig_Loader_Chain($loaders);
     $this->instance = new \Twig_Environment($twigLoader, array("debug" => $twigDebug, "autoescape" => $twigAutoescape));
     // customize Twig
     $this->instance = TwigUtil::loadFilters($this->instance);
     $this->instance = TwigUtil::loadFunctions($this->instance);
     $this->instance = TwigUtil::loadTags($this->instance);
     $this->instance = TwigUtil::loadTests($this->instance);
     $this->instance = TwigUtil::loadDateFormats($this->instance);
     $this->instance = TwigUtil::loadDebug($this->instance);
     $this->instance = TwigUtil::loadMacros($this->instance);
     // add node visitor
     $this->instance->addNodeVisitor(new IncludeNodeVisitor());
 }