removed blade from core and extracted it into bundle. added view engine event to hook in any view engine to the core.

This commit is contained in:
Taylor Otwell 2012-02-23 22:34:42 -06:00
parent 441a9e206f
commit 49d3c5251b
3 changed files with 13 additions and 157 deletions

View File

@ -1,151 +0,0 @@
<?php namespace Laravel; defined('DS') or die('No direct script access.');
class Blade {
/**
* All of the compiler functions used by Blade.
*
* @var array
*/
protected static $compilers = array(
'echos',
'structure_openings',
'structure_closings',
'else',
'yields',
'section_start',
'section_end',
);
/**
* Compiles the specified file containing Blade pseudo-code into valid PHP.
*
* @param string $path
* @return string
*/
public static function compile($path)
{
return static::compile_string(file_get_contents($path));
}
/**
* Compiles the given string containing Blade pseudo-code into valid PHP.
*
* @param string $value
* @return string
*/
public static function compile_string($value)
{
foreach (static::$compilers as $compiler)
{
$method = "compile_{$compiler}";
$value = static::$method($value);
}
return $value;
}
/**
* Rewrites Blade echo statements into PHP echo statements.
*
* @param string $value
* @return string
*/
protected static function compile_echos($value)
{
return preg_replace('/\{\{(.+?)\}\}/', '<?php echo $1; ?>', $value);
}
/**
* Rewrites Blade structure openings into PHP structure openings.
*
* @param string $value
* @return string
*/
protected static function compile_structure_openings($value)
{
$pattern = '/(\s*)@(if|elseif|foreach|for|while)(\s*\(.*\))/';
return preg_replace($pattern, '$1<?php $2$3: ?>', $value);
}
/**
* Rewrites Blade structure closings into PHP structure closings.
*
* @param string $value
* @return string
*/
protected static function compile_structure_closings($value)
{
$pattern = '/(\s*)@(endif|endforeach|endfor|endwhile)(\s*)/';
return preg_replace($pattern, '$1<?php $2; ?>$3', $value);
}
/**
* Rewrites Blade else statements into PHP else statements.
*
* @param string $value
* @return string
*/
protected static function compile_else($value)
{
return preg_replace('/(\s*)@(else)(\s*)/', '$1<?php $2: ?>$3', $value);
}
/**
* Rewrites Blade @yield statements into Section statements.
*
* The Blade @yield statement is a shortcut to the Section::yield method.
*
* @param string $value
* @return string
*/
protected static function compile_yields($value)
{
$pattern = static::matcher('yield');
return preg_replace($pattern, '$1<?php echo \\Laravel\\Section::yield$2; ?>', $value);
}
/**
* Rewrites Blade @section statements into Section statements.
*
* The Blade @section statement is a shortcut to the Section::start method.
*
* @param string $value
* @return string
*/
protected static function compile_section_start($value)
{
$pattern = static::matcher('section');
return preg_replace($pattern, '$1<?php \\Laravel\\Section::start$2; ?>', $value);
}
/**
* Rewrites Blade @endsection statements into Section statements.
*
* The Blade @endsection statement is a shortcut to the Section::stop method.
*
* @param string $value
* @return string
*/
protected static function compile_section_end($value)
{
return preg_replace('/@endsection/', '<?php \\Laravel\\Section::stop(); ?>', $value);
}
/**
* Get the regular expression for a generic Blade function.
*
* @param string $function
* @return string
*/
protected static function matcher($function)
{
return '/(\s*)@'.$function.'(\s*\(.*\))/';
}
}

View File

@ -37,6 +37,13 @@ class View implements ArrayAccess {
*/
public static $names = array();
/**
* The Laravel view engine event name.
*
* @var string
*/
const engine = 'laravel.view.engine';
/**
* Create a new view instance.
*
@ -194,15 +201,17 @@ class View implements ArrayAccess {
{
// To allow bundles or other pieces of the application to modify the
// view before it is rendered, we'll fire an event, passing in the
// view instance so it can modified.
Event::fire("laravel.composing: {$this->view}", array($this));
// view instance so it can modified by the composer.
$composer = "laravel.composing: {$this->view}";
Event::fire($composer, array($this));
// If there are listeners to the view engine event, we'll pass them
// the view so they can render it according to their needs, which
// allows easy attachment of other view parsers.
if (Event::listeners('laravel.viewer'))
if (Event::listeners(static::engine))
{
return Event::first('laravel.viewer', array($this));
return Event::first(static::engine, array($this));
}
else
{

View File

@ -1,2 +0,0 @@
*
!.gitignore