Added View::render_each and Blade shortcut.
This commit is contained in:
parent
9df88c461b
commit
727b064bf7
|
@ -18,6 +18,7 @@ class Blade {
|
||||||
'yields',
|
'yields',
|
||||||
'section_start',
|
'section_start',
|
||||||
'section_end',
|
'section_end',
|
||||||
|
'render_each',
|
||||||
);
|
);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -238,6 +239,19 @@ 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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Rewrites Blade @render_each statements into View statements.
|
||||||
|
*
|
||||||
|
* @param string $value
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
protected static function compile_render_each($value)
|
||||||
|
{
|
||||||
|
$pattern = static::matcher('render_each');
|
||||||
|
|
||||||
|
return preg_replace($pattern, '$1<?php \\Laravel\\View::render_each$2; ?>', $value);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the regular expression for a generic Blade function.
|
* Get the regular expression for a generic Blade function.
|
||||||
*
|
*
|
||||||
|
|
|
@ -37,20 +37,6 @@ class View implements ArrayAccess {
|
||||||
*/
|
*/
|
||||||
public static $names = array();
|
public static $names = array();
|
||||||
|
|
||||||
/**
|
|
||||||
* The extensions a view file can have.
|
|
||||||
*
|
|
||||||
* @var array
|
|
||||||
*/
|
|
||||||
public static $extensions = array(EXT);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The path in which a view can live.
|
|
||||||
*
|
|
||||||
* @var array
|
|
||||||
*/
|
|
||||||
public static $paths = array(DEFAULT_BUNDLE => array(''));
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The Laravel view loader event name.
|
* The Laravel view loader event name.
|
||||||
*
|
*
|
||||||
|
@ -238,28 +224,47 @@ public static function composer($view, $composer)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Register a new root path for a bundle.
|
* Get the rendered contents of a partial from a loop.
|
||||||
*
|
*
|
||||||
* @param string $bundle
|
* @param string $view
|
||||||
* @param string $path
|
* @param array $data
|
||||||
* @return void
|
* @param string $iterator
|
||||||
|
* @param string $empty
|
||||||
|
* @return string
|
||||||
*/
|
*/
|
||||||
public static function search($bundle, $path)
|
public static function render_each($view, array $data, $iterator, $empty = null)
|
||||||
{
|
{
|
||||||
static::$paths[$bundle][] = $path;
|
$result = '';
|
||||||
|
|
||||||
|
// If is actually data in the array, we will loop through the data and
|
||||||
|
// append an instance of the partial view to the final result HTML,
|
||||||
|
// passing in the iterated value of the data array.
|
||||||
|
if (count($data) > 0)
|
||||||
|
{
|
||||||
|
foreach ($data as $key => $value)
|
||||||
|
{
|
||||||
|
$with = array('key' => $key, $iterator => $value);
|
||||||
|
|
||||||
|
$result .= render($view, $with);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
// If there is no data in the array, we will render the contents of
|
||||||
* Register a new valid view extension.
|
// the "empty" view. Alternative, the "empty view" can be a raw
|
||||||
*
|
// string that is prefixed with "raw|" for convenience.
|
||||||
* @param string $extension
|
else
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public static function extension($extension)
|
|
||||||
{
|
{
|
||||||
static::$extensions[] = $extension;
|
if (starts_with($empty, 'raw|'))
|
||||||
|
{
|
||||||
|
$result = substr($empty, 4);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$result = render($empty ?: $view.'_empty');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static::$extensions = array_unique(static::$extensions);
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue