Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
New appends Blade directive.
- Loading branch information
|
@@ -33,6 +33,7 @@ class BladeCompiler extends Compiler implements CompilerInterface { |
|
|
'Language', |
|
|
'SectionStart', |
|
|
'SectionStop', |
|
|
'SectionAppend', |
|
|
'SectionOverwrite', |
|
|
); |
|
|
|
|
@@ -398,6 +399,19 @@ protected function compileSectionStop($value) |
|
|
return preg_replace($pattern, '$1<?php $__env->stopSection(); ?>$2', $value); |
|
|
} |
|
|
|
|
|
/** |
|
|
* Compile Blade section append statements into valid PHP. |
|
|
* |
|
|
* @param string $value |
|
|
* @return string |
|
|
*/ |
|
|
protected function compileSectionAppend($value) |
|
|
{ |
|
|
$pattern = $this->createPlainMatcher('append'); |
|
|
|
|
|
return preg_replace($pattern, '$1<?php $__env->appendSection(); ?>$2', $value); |
|
|
} |
|
|
|
|
|
/** |
|
|
* Compile Blade section stop statements into valid PHP. |
|
|
* |
|
|
|
@@ -497,6 +497,27 @@ public function stopSection($overwrite = false) |
|
|
return $last; |
|
|
} |
|
|
|
|
|
/** |
|
|
* Stop injecting content into a section and append it. |
|
|
* |
|
|
* @return string |
|
|
*/ |
|
|
public function appendSection() |
|
|
{ |
|
|
$last = array_pop($this->sectionStack); |
|
|
|
|
|
if (isset($this->sections[$last])) |
|
|
{ |
|
|
$this->sections[$last] .= ob_get_clean(); |
|
|
} |
|
|
else |
|
|
{ |
|
|
$this->sections[$last] = ob_get_clean(); |
|
|
} |
|
|
|
|
|
return $last; |
|
|
} |
|
|
|
|
|
/** |
|
|
* Append content to a given section. |
|
|
* |
|
|
|
@@ -296,6 +296,13 @@ public function testStopSectionsAreCompiled() |
|
|
} |
|
|
|
|
|
|
|
|
public function testAppendSectionsAreCompiled() |
|
|
{ |
|
|
$compiler = new BladeCompiler($this->getFiles(), __DIR__); |
|
|
$this->assertEquals('<?php $__env->appendSection(); ?>', $compiler->compileString('@append')); |
|
|
} |
|
|
|
|
|
|
|
|
public function testCustomExtensionsAreCompiled() |
|
|
{ |
|
|
$compiler = new BladeCompiler($this->getFiles(), __DIR__); |
|
|
|
@@ -237,6 +237,19 @@ public function testSectionExtending() |
|
|
} |
|
|
|
|
|
|
|
|
public function testSessionAppending() |
|
|
{ |
|
|
$environment = $this->getEnvironment(); |
|
|
$environment->startSection('foo'); |
|
|
echo 'hi'; |
|
|
$environment->appendSection(); |
|
|
$environment->startSection('foo'); |
|
|
echo 'there'; |
|
|
$environment->appendSection(); |
|
|
$this->assertEquals('hithere', $environment->yieldContent('foo')); |
|
|
} |
|
|
|
|
|
|
|
|
public function testYieldSectionStopsAndYields() |
|
|
{ |
|
|
$environment = $this->getEnvironment(); |
|
|