Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ea49729
commit 76c352c
Showing
11 changed files
with
143 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
<?php | ||
Library::import('recess.framework.AbstractHelper'); | ||
|
||
class Layout extends AbstractHelper { | ||
|
||
const DEFAULT_BLOCK = 'body'; | ||
|
||
protected static $extendStack = array(); | ||
|
||
protected static $blockStack = array(); | ||
protected static $blockMap = array(); | ||
|
||
protected static $slotStack = array(); | ||
|
||
protected static $app; | ||
|
||
public static function init($view) { | ||
$response = $view->getResponse(); | ||
self::$app = $response->meta->app; | ||
} | ||
|
||
public static function extend($layout) { | ||
if(!empty(self::$extendStack)) { | ||
die('error: can\'t nest extends'); | ||
} | ||
|
||
array_push(self::$extendStack, $layout); | ||
ob_start(); | ||
} | ||
|
||
public static function block($title) { | ||
if(empty(self::$extendStack)) { | ||
die('error: not extending'); | ||
} | ||
|
||
if(!empty(self::$blockStack)) { | ||
die('error: cant nest blocks'); | ||
} | ||
|
||
array_push(self::$blockStack, $title); | ||
ob_start(); | ||
} | ||
|
||
public static function blockEnd() { | ||
if(empty(self::$blockStack)) { | ||
die('not in a block!'); | ||
} | ||
|
||
$blockName = array_pop(self::$blockStack); | ||
if(!isset(self::$blockMap[$blockName])) { | ||
self::$blockMap[$blockName] = ob_get_clean(); | ||
} else { | ||
ob_end_clean(); | ||
} | ||
} | ||
|
||
public static function slot($title) { | ||
if(!empty(self::$slotStack)) { | ||
die('can\'t nest slots'); | ||
} | ||
|
||
array_push(self::$slotStack, $title); | ||
ob_start(); | ||
} | ||
|
||
public static function slotEnd() { | ||
if(empty(self::$slotStack)) { | ||
die('not in a slot'); | ||
} | ||
|
||
$slotName = array_pop(self::$slotStack); | ||
if(isset(self::$blockMap[$slotName])) { | ||
ob_end_clean(); | ||
echo self::$blockMap[$slotName]; | ||
unset(self::$blockMap[$slotName]); | ||
} else { | ||
ob_end_flush(); | ||
} | ||
} | ||
|
||
public static function extendEnd() { | ||
if(!empty(self::$extendStack)) { | ||
if(!isset(self::$blockMap[Layout::DEFAULT_BLOCK])) { | ||
self::$blockMap[Layout::DEFAULT_BLOCK] = ob_get_clean(); | ||
} else { | ||
ob_end_clean(); | ||
} | ||
|
||
$parent = array_pop(self::$extendStack); | ||
include(self::$app->getViewsDir() . $parent . '.php'); | ||
self::extendEnd(); | ||
} | ||
} | ||
|
||
} | ||
|
||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
Library::import('recess.framework.views.NativeView'); | ||
Library::import('recess.framework.helpers.Layout'); | ||
Library::import('recess.framework.helpers.Url'); | ||
Library::import('recess.framework.helpers.Html'); | ||
|
||
class RecessView extends NativeView { | ||
/** | ||
* Realizes HTTP's body content based on the Response parameter. Responsible | ||
* for returning content in the format desired. The render method likely uses | ||
* inversion of control which delegates to another method within the view to | ||
* realize the Response. | ||
* | ||
* @param Response $response | ||
* @abstract | ||
*/ | ||
protected function render(Response $response) { | ||
$this->loadHelper( | ||
'recess.framework.helpers.Layout', | ||
'recess.framework.helpers.Url', | ||
'recess.framework.helpers.Html'); | ||
parent::render($response); | ||
Layout::extendEnd(); | ||
} | ||
} | ||
?> |