Commit 41ca8169 authored by Taylor Otwell's avatar Taylor Otwell

refactoring the blade class.

parent f9ec36d7
...@@ -73,9 +73,9 @@ class Blade { ...@@ -73,9 +73,9 @@ class Blade {
*/ */
protected static function compile_structure_openings($value) protected static function compile_structure_openings($value)
{ {
$pattern = '/@(if|elseif|foreach|for|while)(\s*\(.*?\))/'; $pattern = '/(\s*)@(if|elseif|foreach|for|while)(\s*\(.*?\))/';
return preg_replace($pattern, '<?php $1$2: ?>', $value); return preg_replace($pattern, '$1<?php $2$3: ?>', $value);
} }
/** /**
...@@ -86,9 +86,9 @@ class Blade { ...@@ -86,9 +86,9 @@ class Blade {
*/ */
protected static function compile_structure_closings($value) protected static function compile_structure_closings($value)
{ {
$pattern = '/@(endif|endforeach|endfor|endwhile)(\s*)/'; $pattern = '/(\s*)@(endif|endforeach|endfor|endwhile)(\s*)/';
return preg_replace($pattern, '<?php $1; ?>$2', $value); return preg_replace($pattern, '$1<?php $2; ?>$3', $value);
} }
/** /**
...@@ -112,7 +112,7 @@ class Blade { ...@@ -112,7 +112,7 @@ class Blade {
*/ */
protected static function compile_yields($value) protected static function compile_yields($value)
{ {
$pattern = '/(\s*)@yield(\s*\(.*?\))/'; $pattern = static::matcher('yield');
return preg_replace($pattern, '$1<?php echo \\Laravel\\Section::yield$2; ?>', $value); return preg_replace($pattern, '$1<?php echo \\Laravel\\Section::yield$2; ?>', $value);
} }
...@@ -127,7 +127,7 @@ class Blade { ...@@ -127,7 +127,7 @@ class Blade {
*/ */
protected static function compile_section_start($value) protected static function compile_section_start($value)
{ {
$pattern = '/(\s*)@section(\s*\(.*?\))/'; $pattern = static::matcher('section');
return preg_replace($pattern, '$1<?php \\Laravel\\Section::start$2; ?>', $value); return preg_replace($pattern, '$1<?php \\Laravel\\Section::start$2; ?>', $value);
} }
...@@ -145,4 +145,15 @@ class Blade { ...@@ -145,4 +145,15 @@ class Blade {
return preg_replace('/@endsection/', '<?php \\Laravel\\Section::stop(); ?>', $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*\(.*?\))/';
}
} }
\ No newline at end of file
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