Merge pull request #628 from daylerees/custom-blade
Blade::register() custom blade compilers.
This commit is contained in:
commit
a697781390
|
@ -26,8 +26,16 @@ class Blade {
|
||||||
'yield_sections',
|
'yield_sections',
|
||||||
'section_start',
|
'section_start',
|
||||||
'section_end',
|
'section_end',
|
||||||
|
'extensions',
|
||||||
);
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An array of user defined compilers.
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
protected static $extensions = array();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Register the Blade view engine with Laravel.
|
* Register the Blade view engine with Laravel.
|
||||||
*
|
*
|
||||||
|
@ -64,6 +72,22 @@ public static function sharpen()
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Register a new blade compiler.
|
||||||
|
*
|
||||||
|
* <code>
|
||||||
|
* Blade::extend(function($view) {
|
||||||
|
* return str_replace('thing', 'another_thing', $view);
|
||||||
|
* });
|
||||||
|
* </code>
|
||||||
|
*
|
||||||
|
* @param closure $compiler
|
||||||
|
*/
|
||||||
|
public static function extend($compiler)
|
||||||
|
{
|
||||||
|
static::$extensions[] = $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.
|
||||||
*
|
*
|
||||||
|
@ -386,6 +410,22 @@ protected static function compile_section_end($value)
|
||||||
return preg_replace('/@endsection/', '<?php \\Laravel\\Section::stop(); ?>', $value);
|
return preg_replace('/@endsection/', '<?php \\Laravel\\Section::stop(); ?>', $value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Execute user defined compilers.
|
||||||
|
*
|
||||||
|
* @param string $value
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
protected static function compile_extensions($value)
|
||||||
|
{
|
||||||
|
foreach (static::$extensions 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.
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in New Issue