Commit d2de301e by Dayle Rees

added custom compilers to blade

Signed-off-by: Dayle Rees <thepunkfan@gmail.com>
parent 0824c871
...@@ -26,9 +26,17 @@ class Blade { ...@@ -26,9 +26,17 @@ class Blade {
'yield_sections', 'yield_sections',
'section_start', 'section_start',
'section_end', 'section_end',
'extra',
); );
/** /**
* An array of user defined compilers.
*
* @var array
*/
protected static $registered = array();
/**
* Register the Blade view engine with Laravel. * Register the Blade view engine with Laravel.
* *
* @return void * @return void
...@@ -65,6 +73,22 @@ class Blade { ...@@ -65,6 +73,22 @@ class Blade {
} }
/** /**
* Register a new blade compiler.
*
* <code>
* Blade::register(function($view) {
* return str_replace('thing', 'another_thing', $view);
* });
* </code>
*
* @param closure $compiler
*/
public static function register($compiler)
{
static::$registered[] = $compiler;
}
/**
* Determine if a view is "expired" and needs to be re-compiled. * Determine if a view is "expired" and needs to be re-compiled.
* *
* @param string $view * @param string $view
...@@ -387,6 +411,22 @@ class Blade { ...@@ -387,6 +411,22 @@ class Blade {
} }
/** /**
* Execute user defined compilers.
*
* @param string $value
* @return string
*/
protected static function compile_extra($value)
{
foreach (static::$registered as $compiler)
{
$value = $compiler($value);
}
return $value;
}
/**
* Get the regular expression for a generic Blade function. * Get the regular expression for a generic Blade function.
* *
* @param string $function * @param string $function
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment