Example #1
0
 /**
  * Function rummages through the template before it is compiled.  It searches
  * only for {{include}} blocks.  These are then embedded into the compiled output.
  * 
  * @param string $contents		Entire template as a string.
  * @return string				Entire source with included templates embedded.
  */
 private function _preProcessSource($contents)
 {
     $ldl = "{{";
     $rdl = "}}";
     $ld = preg_quote($ldl, "/");
     $rd = preg_quote($rdl, "/");
     //this will only match the include blocks
     $include_regex = "/{$ld}include file=[\"']?(.*?)[\"']?{$rd}/s";
     $matches = array();
     $count = preg_match_all($include_regex, $contents, $matches);
     //return input since there are no includes.
     if (!$count) {
         return $contents;
     }
     //section reads all of the include template into an array
     //it recursively precompiles other templates too.
     $includes = array();
     foreach ($matches[1] as $file) {
         if ($file == "*master*") {
             $file = $this->_saveName;
         }
         $filename = $this->_resource_manager->getTemplateFilename($file);
         $_contents = file_get_contents($filename);
         $includes[] = $this->_preProcessSource($_contents);
     }
     $include_split_regex = "/{$ld}include .*?{$rd}/s";
     $text_blocks = preg_split($include_split_regex, $contents);
     //reset the precompiled entries and weave thing together
     //next and current simply move through arrays without using an integer index
     $precompiled_source = "";
     reset($includes);
     foreach ($text_blocks as $text) {
         $precompiled_source .= $text;
         $precompiled_source .= current($includes);
         next($includes);
     }
     return $precompiled_source;
 }
Example #2
0
 /**
  * Compiles are templates in the template directory.  Used to avoid checking if compiled
  * files exist in a production environment.
  * 
  * @return bool		Always returns true.
  */
 public static function compileAllTemplates()
 {
     $template = new Template();
     $resource = new Template_ResourceManager($template);
     $files = $resource->getAllTemplateFiles();
     foreach ($files as $file) {
         echo $file . "<bR>";
         $compiler = new Template_Compiler($resource);
         $compiler->compile($file);
     }
     return true;
 }