mirror of
https://github.com/fenom-template/fenom.git
synced 2023-08-10 21:13:07 +03:00
Add tag filter. Move benchmark to another project
This commit is contained in:
@@ -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
|
||||
*
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user