Add tag filter. Move benchmark to another project

This commit is contained in:
Ivan Shalganov
2013-10-08 17:48:23 +04:00
parent 24f22f8f43
commit 6fec661ea7
23 changed files with 182 additions and 5310 deletions

View File

@@ -79,6 +79,11 @@ class Fenom
*/
public $filters = array();
/**
* @var callable[]
*/
public $tag_filters = array();
/**
* @var callable[]
*/
@@ -349,6 +354,22 @@ class Fenom
return $this->filters;
}
/**
* @param callable $cbcd
* @return self
*/
public function addTagFilter($cb)
{
$this->tag_filters[] = $cb;
return $this;
}
public function getTagFilters()
{
return $this->tag_filters;
}
/**
* Add modifier
*

View File

@@ -139,9 +139,10 @@ class Template extends Render
*/
public function __construct(Fenom $fenom, $options)
{
$this->_fenom = $fenom;
$this->_options = $options;
$this->_filters = $this->_fenom->getFilters();
$this->_fenom = $fenom;
$this->_options = $options;
$this->_filters = $this->_fenom->getFilters();
$this->_tag_filters = $this->_fenom->getTagFilters();
}
/**
@@ -248,6 +249,11 @@ class Template extends Render
$this->_appendText($tag);
}
} else {
if($this->_tag_filters) {
foreach($this->_tag_filters as $filter) {
$_tag = call_user_func($filter, $_tag, $this);
}
}
$tokens = new Tokenizer($_tag); // tokenize the tag
if ($tokens->isIncomplete()) { // all strings finished?
$need_more = true;
@@ -607,6 +613,7 @@ class Template extends Render
* Parse expressions. The mix of operators and terms.
*
* @param Tokenizer $tokens
* @return string
* @throws Error\UnexpectedTokenException
*/
public function parseExpr(Tokenizer $tokens)