Skip to content

Commit

Permalink
configurable token filters
Browse files Browse the repository at this point in the history
  • Loading branch information
ikkez committed Apr 20, 2015
1 parent 5ecb68f commit f304c29
Showing 1 changed file with 21 additions and 13 deletions.
34 changes: 21 additions & 13 deletions base.php
Original file line number Diff line number Diff line change
Expand Up @@ -2434,16 +2434,6 @@ function($val) use($fw) {
);
}

/**
* build an url from alias name
* @return string
* @param $key string
* @param $arg string
**/
function alias($key,$arg=null) {
return Base::instance()->alias($key,$arg);
}

/**
* Create sandbox for template execution
* @return string
Expand Down Expand Up @@ -2520,7 +2510,14 @@ class Preview extends View {

protected
//! MIME type
$mime;
$mime,
//! token filter
$filter = array(
'esc'=>'$this->esc',
'raw'=>'$this->raw',
'alias'=>'\Base::instance()->alias',
'format'=>'\Base::instance()->format'
);

/**
* Convert token to variable
Expand All @@ -2532,6 +2529,18 @@ function token($str) {
Base::instance()->compile($str)));
}

/**
* register token filter
* @param string $key
* @param string $func
* @return array
*/
function filter($key=NULL,$func=NULL) {
if (!$key)
return array_keys($this->filter);
$this->filter[$key]=$func;
}

/**
* Assemble markup
* @return string
Expand All @@ -2549,8 +2558,7 @@ function($expr) use($self) {
$str,$parts)) {
$str=$parts[1];
foreach (Base::instance()->split($parts[2]) as $func)
$str=(($func=='format')?'\Base::instance()':'$this').
'->'.$func.'('.$str.')';
$str=$this->filter[$func].'('.$str.')';
}
return '<?php echo '.$str.'; ?>'.
(isset($expr[3])?$expr[3]."\n":'');
Expand Down

0 comments on commit f304c29

Please sign in to comment.