Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
mradlinski committed Nov 8, 2015
1 parent b11c8ab commit cf22942
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 26 deletions.
14 changes: 13 additions & 1 deletion src/Illuminate/View/Compilers/BladeCompiler.php
Original file line number Diff line number Diff line change
Expand Up @@ -704,6 +704,18 @@ public function createMatcher($function)
return '/(?<!\w)(\s*)@'.$function.'(\s*\(.*\))/';
}


/**
* Compile the parent statements into valid PHP.
*
* @param string $expression
* @return string
*/
protected function compileParent($expression)
{
return '<?php $__env->appendParent(); ?>';
}

/**
* Get the regular expression for a generic Blade function.
*
Expand Down Expand Up @@ -743,7 +755,7 @@ public function setRawTags($openTag, $closeTag)
*
* @param string $openTag
* @param string $closeTag
* @param bool $escaped
* @param bool $escaped
* @return void
*/
public function setContentTags($openTag, $closeTag, $escaped = false)
Expand Down
69 changes: 44 additions & 25 deletions src/Illuminate/View/Factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,13 @@ class Factory implements FactoryContract {
*/
protected $renderCount = 0;

/**
* The marks for @parent section embedding.
*
* @var array
*/
protected $parentMarks = [];

/**
* Create a new view factory instance.
*
Expand Down Expand Up @@ -339,7 +346,7 @@ public function share($key, $value = null)
/**
* Register a view creator event.
*
* @param array|string $views
* @param array|string $views
* @param \Closure|string $callback
* @return array
*/
Expand Down Expand Up @@ -421,9 +428,9 @@ protected function addViewEvent($view, $callback, $prefix = 'composing: ', $prio
/**
* Register a class based view composer.
*
* @param string $view
* @param string $class
* @param string $prefix
* @param string $view
* @param string $class
* @param string $prefix
* @param int|null $priority
* @return \Closure
*/
Expand All @@ -444,9 +451,9 @@ protected function addClassEvent($view, $class, $prefix, $priority = null)
/**
* Add a listener to the event dispatcher.
*
* @param string $name
* @param string $name
* @param \Closure $callback
* @param int $priority
* @param int $priority
* @return void
*/
protected function addEventListener($name, $callback, $priority = null)
Expand Down Expand Up @@ -558,6 +565,24 @@ public function inject($section, $content)
return $this->startSection($section, $content);
}

/**
* Create mark for parent section content.
*
* @return void
*/
public function appendParent()
{
$last = array_pop($this->sectionStack);

if (! isset($this->parentMarks[$last])) {
$this->parentMarks[$last] = [];
}

array_push($this->parentMarks[$last], ob_get_length());

$this->sectionStack[] = $last;
}

/**
* Stop injecting content into a section and return its contents.
*
Expand Down Expand Up @@ -620,12 +645,15 @@ public function appendSection()
*/
protected function extendSection($section, $content)
{
if (isset($this->sections[$section]))
{
$content = str_replace('@parent', $content, $this->sections[$section]);
if (isset($this->sections[$section])) {
if (isset($this->parentMarks[$section])) {
while ($mark = array_pop($this->parentMarks[$section])) {
$this->sections[$section] = substr_replace($this->sections[$section], $content, $mark, 0);
}
}
} else {
$this->sections[$section] = $content;
}

$this->sections[$section] = $content;
}

/**
Expand All @@ -637,18 +665,7 @@ protected function extendSection($section, $content)
*/
public function yieldContent($section, $default = '')
{
$sectionContent = $default;

if (isset($this->sections[$section]))
{
$sectionContent = $this->sections[$section];
}

$sectionContent = str_replace('@@parent', '--parent--holder--', $sectionContent);

return str_replace(
'--parent--holder--', '@parent', str_replace('@parent', '', $sectionContent)
);
return isset($this->sections[$section]) ? $this->sections[$section] : $default;
}

/**
Expand All @@ -661,6 +678,8 @@ public function flushSections()
$this->sections = array();

$this->sectionStack = array();

$this->parentMarks = [];
}

/**
Expand Down Expand Up @@ -741,8 +760,8 @@ public function prependNamespace($namespace, $hints)
/**
* Register a valid view extension and its engine.
*
* @param string $extension
* @param string $engine
* @param string $extension
* @param string $engine
* @param \Closure $resolver
* @return void
*/
Expand Down

0 comments on commit cf22942

Please sign in to comment.