function test_tokenize_blocks() { $this->assertEqual(array('{%comment%}'), LiquidTemplate::tokenize('{%comment%}')); $this->assertEqual(array(' ', '{%comment%}', ' '), LiquidTemplate::tokenize(' {%comment%} ')); $this->assertEqual(array(' ', '{%comment%}', ' ', '{%endcomment%}', ' '), LiquidTemplate::tokenize(' {%comment%} {%endcomment%} ')); $this->assertEqual(array(' ', '{% comment %}', ' ', '{% endcomment %}', ' '), LiquidTemplate::tokenize(" {% comment %} {% endcomment %} ")); }
/** * Parses the tokens * * @param array $tokens */ public function parse(&$tokens) { if (!isset($this->_fileSystem)) { throw new LiquidException("No file system"); } // read the source of the template and create a new sub document $source = $this->_fileSystem->readTemplateFile($this->_templateName); // tokens in this new document $maintokens = LiquidTemplate::tokenize($source); $eRegexp = new LiquidRegexp('/^' . LIQUID_TAG_START . '\\s*extends (.*)?' . LIQUID_TAG_END . '$/'); foreach ($maintokens as $maintoken) { if ($eRegexp->match($maintoken)) { $m = $eRegexp->matches[1]; break; } } if (isset($m)) { $rest = array_merge($maintokens, $tokens); } else { $childtokens = $this->_findBlocks($tokens); $blockstartRegexp = new LiquidRegexp('/^' . LIQUID_TAG_START . '\\s*block (\\w+)\\s*(.*)?' . LIQUID_TAG_END . '$/'); $blockendRegexp = new LiquidRegexp('/^' . LIQUID_TAG_START . '\\s*endblock\\s*?' . LIQUID_TAG_END . '$/'); $b = array(); $name = null; $rest = array(); $aufzeichnen = false; for ($i = 0; $i < count($maintokens); $i++) { if ($blockstartRegexp->match($maintokens[$i])) { $name = $blockstartRegexp->matches[1]; if (isset($childtokens[$name])) { $aufzeichnen = true; array_push($rest, $maintokens[$i]); foreach ($childtokens[$name] as $item) { array_push($rest, $item); } } } if (!$aufzeichnen) { array_push($rest, $maintokens[$i]); } if ($blockendRegexp->match($maintokens[$i]) && $aufzeichnen === true) { $aufzeichnen = false; array_push($rest, $maintokens[$i]); } } } $this->_hash = md5($source); $cache = LiquidTemplate::getCache(); if (isset($cache)) { if (($this->_document = $cache->read($this->_hash)) != false && $this->_document->checkIncludes() != true) { } else { $this->_document = new LiquidDocument($rest, $this->_fileSystem); $cache->write($this->_hash, $this->_document); } } else { $this->_document = new LiquidDocument($rest, $this->_fileSystem); } }
/** * Parses the tokens * * @param array $tokens */ public function parse(&$tokens) { if (!isset($this->file_system)) { throw new LiquidException("No file system"); } // read the source of the template and create a new sub document $source = $this->file_system->read_template_file($this->template_name); $this->_hash = md5($source); $cache = LiquidTemplate::getCache(); if (isset($cache)) { if (($this->document = $cache->read($this->_hash)) != false && $this->document->checkIncludes() != true) { } else { $this->document = new LiquidDocument(LiquidTemplate::tokenize($source), $this->file_system); $cache->write($this->_hash, $this->document); } } else { $this->document = new LiquidDocument(LiquidTemplate::tokenize($source), $this->file_system); } }
/** * Parses the given source string * * @param string $source */ function parse($source) { $this->root = new LiquidDocument(LiquidTemplate::tokenize($source), $this->file_system); }
/** * Parses the given source string * * @param string $source */ public function parse($source) { $cache = self::$_cache; new dBug($cache, "source cache"); if (isset($cache)) { if (($this->_root = $cache->read(md5($source))) != false && $this->_root->checkIncludes() != true) { } else { $this->_root = new LiquidDocument(LiquidTemplate::tokenize($source), $this->_fileSystem); $cache->write(md5($source), $this->_root); } } else { new dBug(LiquidTemplate::tokenize($source), "Tokenized Source"); new dBug($this->_fileSystem, "File System"); $this->_root = new LiquidDocument(LiquidTemplate::tokenize($source), $this->_fileSystem); new dBug($this->_root, "Document Root"); } exit; return $this; }
/** * Parses the given source string * * @param string $source */ public function parse($source) { $cache = self::$_cache; if (isset($cache)) { if (($this->_root = $cache->read(md5($source))) != false && $this->_root->checkIncludes() != true) { } else { $this->_root = new LiquidDocument(LiquidTemplate::tokenize($source), $this->_fileSystem); $cache->write(md5($source), $this->_root); } } else { $this->_root = new LiquidDocument(LiquidTemplate::tokenize($source), $this->_fileSystem); } return $this; }
/** * Parses the tokens * * @param array $tokens */ function parse($tokens) { if (!isset($this->file_system)) { trigger_error("No file system", E_USER_ERROR); } // read the source of the template and create a new sub document $source = $this->file_system->read_template_file($this->template_name); $tokens = LiquidTemplate::tokenize($source); $this->document = new LiquidDocument($tokens, $this->file_system); }