Skip to content

Commit

Permalink
Merge branch 'staging'
Browse files Browse the repository at this point in the history
  • Loading branch information
taylorotwell committed Aug 29, 2012
2 parents dd01308 + 9b90242 commit 928ce7c
Show file tree
Hide file tree
Showing 11 changed files with 307 additions and 119 deletions.
13 changes: 13 additions & 0 deletions application/config/application.php
Expand Up @@ -94,6 +94,19 @@

'language' => 'en',

/*
|--------------------------------------------------------------------------
| Supported Languages
|--------------------------------------------------------------------------
|
| These languages may also be supported by your application. If a request
| enters your application with a URI beginning with one of these values
| the default language will automatically be set to that language.
|
*/

'languages' => array(),

/*
|--------------------------------------------------------------------------
| SSL Link Generation
Expand Down
2 changes: 1 addition & 1 deletion artisan
Expand Up @@ -4,7 +4,7 @@
* Laravel - A PHP Framework For Web Artisans
*
* @package Laravel
* @version 3.2.5
* @version 3.2.6
* @author Taylor Otwell <taylorotwell@gmail.com>
* @link http://laravel.com
*/
Expand Down
132 changes: 52 additions & 80 deletions laravel/blade.php
Expand Up @@ -105,7 +105,7 @@ public static function expired($view, $path)
/**
* Compiles the specified file containing Blade pseudo-code into valid PHP.
*
* @param string $view
* @param string $path
* @return string
*/
public static function compile($view)
Expand Down Expand Up @@ -149,33 +149,31 @@ protected static function compile_layouts($value)
}

// First we'll split out the lines of the template so we can get the
// layout from the top of the template. By convention, it must be
// layout from the top of the template. By convention it must be
// located on the first line of the template contents.
preg_replace_callback(
'/^@layout(\s*?\(.+?\))(\r?\n)?/',
function($matches) use (&$value)
{
$value = substr( $value, strlen( $matches[0] ) ).CRLF.'@include'.$matches[1];
},
$value
);
$lines = preg_split("/(\r?\n)/", $value);

return $value;
$pattern = static::matcher('layout');

$lines[] = preg_replace($pattern, '$1@include$2', $lines[0]);

// We will add a "render" statement to the end of the templates and
// then slice off the "@layout" shortcut from the start so the
// sections register before the parent template renders.
return implode(CRLF, array_slice($lines, 1));
}

/**
* Extract a variable value out of a Blade expression.
*
* @param string $value
* @param string $expression
* @return string
*/
protected static function extract($value, $expression)
{
if ( preg_match("/@layout\s*?\(\s*?'(.+?)'\s*?\)/", $value, $matches))
{
return trim( $matches[1] );
}
preg_match('/@layout(\s*\(.*\))(\s*)/', $value, $matches);

return str_replace(array("('", "')"), '', $matches[1]);
}

/**
Expand All @@ -186,9 +184,9 @@ protected static function extract($value, $expression)
*/
protected static function compile_comments($value)
{
$value = preg_replace('/\{\{--(.*?)--\}\}/', "<?php // $1 ?>", $value);
return preg_replace('/\{\{--(.*?)--\}\}/s', "<?php /* ?>$1<?php */ ?>", $value);
$value = preg_replace('/\{\{--(.+?)(--\}\})?\n/', "<?php // $1 ?>", $value);

return preg_replace('/\{\{--((.|\s)*?)--\}\}/', "<?php /* $1 */ ?>\n", $value);
}

/**
Expand All @@ -199,7 +197,7 @@ protected static function compile_comments($value)
*/
protected static function compile_echos($value)
{
return preg_replace('/\{\{(.+?)\}\}/s', '<?php echo $1; ?>', $value);
return preg_replace('/\{\{(.+?)\}\}/', '<?php echo $1; ?>', $value);
}

/**
Expand All @@ -210,21 +208,27 @@ protected static function compile_echos($value)
*/
protected static function compile_forelse($value)
{
preg_match_all('/@forelse\s*?\(\s*?\$(.+?)\s*?as\s*?\$(.+?)\s*?\)/', $value, $matches, PREG_SET_ORDER );

if ( count($matches) < 1 ) return $value;
preg_match_all('/(\s*)@forelse(\s*\(.*\))(\s*)/', $value, $matches);

foreach ($matches as $forelse)
foreach ($matches[0] as $forelse)
{
preg_match('/\s*\(\s*(\S*)\s/', $forelse, $variable);

// Once we have extracted the variable being looped against, we can add
// an if statement to the start of the loop that checks if the count
// of the variable being looped against is greater than zero.
$replace = '<?php if (count($'.$forelse[1].') > 0): foreach ($'.$forelse[1].' as $'.$forelse[2].'): ?>';
$if = "<?php if (count({$variable[1]}) > 0): ?>";

$search = '/(\s*)@forelse(\s*\(.*\))/';

$replace = '$1'.$if.'<?php foreach$2: ?>';

$blade = preg_replace($search, $replace, $forelse);

// Finally, once we have the check prepended to the loop we'll replace
// all instances of this forelse syntax in the view content of the
// view being compiled to Blade syntax with real PHP syntax.
$value = str_replace($forelse[0], $replace, $value);
$value = str_replace($forelse, $blade, $value);
}

return $value;
Expand All @@ -238,7 +242,7 @@ protected static function compile_forelse($value)
*/
protected static function compile_empty($value)
{
return str_replace('@empty', '<?php endforeach; else: ?>', $value);
return str_replace('@empty', '<?php endforeach; ?><?php else: ?>', $value);
}

/**
Expand All @@ -260,42 +264,9 @@ protected static function compile_endforelse($value)
*/
protected static function compile_structure_openings($value)
{
preg_replace_callback(
'/@(if|elseif|foreach|for|while)(\s*?)(\([^\n\r\t]+\))/',
function($matches) use (&$value)
{
if(count( $matches ) === 4)
{
$open = 0;
$close = 0;
$cut = 0;
$len = strlen($matches[3]);
for($i = 0; $i < $len; $i++)
{
if($matches[3][$i] === '(' )
{
$open++;
}
if($matches[3][$i] === ')' )
{
$close++;
}
if($open !== 0 && ($open === $close))
{
break;
}
}
$condition = substr($matches[3], 0, ($i + 1));
$value = str_replace(
'@'.$matches[1].$matches[2].$condition,
'<?php '.$matches[1].$condition.': ?>',
$value
);
}
},
$value
);
return $value;
$pattern = '/(\s*)@(if|elseif|foreach|for|while)(\s*\(.*\))/';

return preg_replace($pattern, '$1<?php $2$3: ?>', $value);
}

/**
Expand All @@ -306,9 +277,9 @@ function($matches) use (&$value)
*/
protected static function compile_structure_closings($value)
{
$pattern = '/@(endif|endforeach|endfor|endwhile|break|continue)/';
$pattern = '/(\s*)@(endif|endforeach|endfor|endwhile)(\s*)/';

return preg_replace($pattern, '<?php $1; ?>', $value);
return preg_replace($pattern, '$1<?php $2; ?>$3', $value);
}

/**
Expand All @@ -319,7 +290,7 @@ protected static function compile_structure_closings($value)
*/
protected static function compile_else($value)
{
return str_replace( '@else', '<?php else: ?>', $value);
return preg_replace('/(\s*)@(else)(\s*)/', '$1<?php $2: ?>$3', $value);
}

/**
Expand All @@ -330,9 +301,9 @@ protected static function compile_else($value)
*/
protected static function compile_unless($value)
{
$pattern = static::matcher('unless');
$pattern = '/(\s*)@unless(\s*\(.*\))/';

return preg_replace($pattern, '<?php if( ! ($1)): ?>', $value);
return preg_replace($pattern, '$1<?php if( ! ($2)): ?>', $value);
}

/**
Expand All @@ -356,7 +327,7 @@ protected static function compile_includes($value)
{
$pattern = static::matcher('include');

return preg_replace($pattern, '<?php echo view$1->with(get_defined_vars())->render(); ?>', $value);
return preg_replace($pattern, '$1<?php echo view$2->with(get_defined_vars())->render(); ?>', $value);
}

/**
Expand All @@ -369,7 +340,7 @@ protected static function compile_render($value)
{
$pattern = static::matcher('render');

return preg_replace($pattern, '<?php echo render$1; ?>', $value);
return preg_replace($pattern, '$1<?php echo render$2; ?>', $value);
}

/**
Expand All @@ -382,7 +353,7 @@ protected static function compile_render_each($value)
{
$pattern = static::matcher('render_each');

return preg_replace($pattern, '<?php echo render_each$1; ?>', $value);
return preg_replace($pattern, '$1<?php echo render_each$2; ?>', $value);
}

/**
Expand All @@ -397,18 +368,19 @@ protected static function compile_yields($value)
{
$pattern = static::matcher('yield');

return preg_replace($pattern, '<?php echo \\Laravel\\Section::yield$1; ?>', $value);
return preg_replace($pattern, '$1<?php echo \\Laravel\\Section::yield$2; ?>', $value);
}

/**
* Rewrites Blade yield section statements into valid PHP.
*
* @param string $value
* @return string
*/
protected static function compile_yield_sections($value)
{
return str_replace('@yield_section', '<?php echo \\Laravel\\Section::yield_section(); ?>', $value);
$replace = '<?php echo \\Laravel\\Section::yield_section(); ?>';

return str_replace('@yield_section', $replace, $value);
}

/**
Expand All @@ -423,7 +395,7 @@ protected static function compile_section_start($value)
{
$pattern = static::matcher('section');

return preg_replace($pattern, '<?php \\Laravel\\Section::start$1; ?>', $value);
return preg_replace($pattern, '$1<?php \\Laravel\\Section::start$2; ?>', $value);
}

/**
Expand All @@ -436,7 +408,7 @@ protected static function compile_section_start($value)
*/
protected static function compile_section_end($value)
{
return str_replace('@endsection', '<?php \\Laravel\\Section::stop(); ?>', $value);
return preg_replace('/@endsection/', '<?php \\Laravel\\Section::stop(); ?>', $value);
}

/**
Expand All @@ -453,7 +425,7 @@ protected static function compile_extensions($value)
}

return $value;
}
}

/**
* Get the regular expression for a generic Blade function.
Expand All @@ -463,18 +435,18 @@ protected static function compile_extensions($value)
*/
public static function matcher($function)
{
return '/@'.$function.'\s*?(\(.+?\))/';
return '/(\s*)@'.$function.'(\s*\(.*\))/';
}

/**
* Get the fully qualified path for a compiled view.
*
* @param string $path
* @param string $view
* @return string
*/
public static function compiled($path)
{
return path('storage').'views/'.md5($path);
}

}
}

0 comments on commit 928ce7c

Please sign in to comment.