Пример #1
0
 function compile($file_name)
 {
     $source_file_path = $this->template_locator->locateSourceTemplate($file_name);
     if (empty($source_file_path)) {
         throw new WactException('Template source file not found', array('file_name' => $file_name));
     }
     $root_node = new WactCompileTreeRootNode(new WactSourceLocation($source_file_path, ''));
     $this->parseTemplate($file_name, $root_node);
     $root_node->prepare();
     $compiled_file_path = $this->template_locator->locateCompiledTemplate($file_name);
     $generated_code = $this->_generateTemplateCode(md5($compiled_file_path), $root_node);
     self::writeFile($compiled_file_path, $generated_code);
 }
 /**
  * Used to parse the source template.
  * Initially invoked by the CompileTemplate function,
  * the first component argument being a WactCompileTreeRootNode.
  */
 function parse($file_name, $compile_tree_root_node)
 {
     $source_file_path = $this->template_locator->locateSourceTemplate($file_name);
     if (empty($source_file_path)) {
         throw new WactException('Template source file not found', array('file_name' => $file_name));
     }
     $tag_count_before_parse = $this->tree_builder->getExpectedTagCount();
     $this->tree_builder->setCursor($compile_tree_root_node);
     $this->changeToComponentParsingState();
     $parser = new WactHTMLParser($this);
     $template = $this->template_locator->readTemplateFile($source_file_path);
     $parser->parse($template, $source_file_path);
     if ($tag_count_before_parse != $this->tree_builder->getExpectedTagCount()) {
         $location = $this->tree_builder->getExpectedTagLocation();
         throw new WactException('Missing close tag', array('tag' => $this->tree_builder->getExpectedTag(), 'file' => $location->getFile(), 'line' => $location->getLine()));
     }
 }