From 5cd7961a38d96708468d77a2ea6f4a894eef5241 Mon Sep 17 00:00:00 2001 From: Qiang Xue Date: Sat, 13 Apr 2013 14:44:32 -0400 Subject: [PATCH] renamed clip to block. --- framework/base/View.php | 26 ++++++------- framework/base/ViewContent.php | 86 +++++------------------------------------- framework/widgets/Block.php | 49 ++++++++++++++++++++++++ framework/widgets/Clip.php | 51 ------------------------- 4 files changed, 72 insertions(+), 140 deletions(-) create mode 100644 framework/widgets/Block.php delete mode 100644 framework/widgets/Clip.php diff --git a/framework/base/View.php b/framework/base/View.php index 8b1f4ef..d1a3c5f 100644 --- a/framework/base/View.php +++ b/framework/base/View.php @@ -53,11 +53,12 @@ class View extends Component */ public $theme; /** - * @var array a list of named output clips. You can call [[beginClip()]] and [[endClip()]] + * @var array a list of named output blocks. The keys are the block names and the values + * are the corresponding block content. You can call [[beginBlock()]] and [[endBlock()]] * to capture small fragments of a view. They can be later accessed at somewhere else * through this property. */ - public $clips; + public $blocks; /** * @var Widget[] the widgets that are currently being rendered (not ended). This property * is maintained by [[beginWidget()]] and [[endWidget()]] methods. Do not modify it. @@ -350,26 +351,25 @@ class View extends Component } /** - * Begins recording a clip. - * This method is a shortcut to beginning [[yii\widgets\Clip]] - * @param string $id the clip ID. - * @param boolean $renderInPlace whether to render the clip content in place. - * Defaults to false, meaning the captured clip will not be displayed. - * @return \yii\widgets\Clip the Clip widget instance - * @see \yii\widgets\Clip + * Begins recording a block. + * This method is a shortcut to beginning [[yii\widgets\Block]] + * @param string $id the block ID. + * @param boolean $renderInPlace whether to render the block content in place. + * Defaults to false, meaning the captured block will not be displayed. + * @return \yii\widgets\Block the Block widget instance */ - public function beginClip($id, $renderInPlace = false) + public function beginBlock($id, $renderInPlace = false) { - return $this->beginWidget('yii\widgets\Clip', array( + return $this->beginWidget('yii\widgets\Block', array( 'id' => $id, 'renderInPlace' => $renderInPlace, )); } /** - * Ends recording a clip. + * Ends recording a block. */ - public function endClip() + public function endBlock() { $this->endWidget(); } diff --git a/framework/base/ViewContent.php b/framework/base/ViewContent.php index cf7684b..cea3c7c 100644 --- a/framework/base/ViewContent.php +++ b/framework/base/ViewContent.php @@ -49,9 +49,13 @@ class ViewContent extends Component public $metaTags; public $linkTags; public $css; - public $js; public $cssFiles; + public $js; public $jsFiles; + public $jsInHead; + public $jsFilesInHead; + public $jsInBody; + public $jsFilesInBody; public function populate($content) { @@ -64,86 +68,16 @@ class ViewContent extends Component $this->metaTags = null; $this->linkTags = null; $this->css = null; - $this->js = null; $this->cssFiles = null; + $this->js = null; $this->jsFiles = null; + $this->jsInHead = null; + $this->jsFilesInHead = null; + $this->jsInBody = null; + $this->jsFilesInBody = null; } public function renderScripts($pos) { } - - public function registerBundle($name) - { - if (!isset($this->bundles[$name])) { - $am = Yii::$app->assets; - $bundle = $am->getBundle($name); - if ($bundle !== null) { - $this->bundles[$name] = $bundle; - } else { - throw new InvalidConfigException("Asset bundle does not exist: $name"); - } - } - } - - public function getMetaTag($key) - { - return isset($this->metaTags[$key]) ? $this->metaTags[$key] : null; - } - - public function setMetaTag($key, $tag) - { - $this->metaTags[$key] = $tag; - } - - public function getLinkTag($key) - { - return isset($this->linkTags[$key]) ? $this->linkTags[$key] : null; - } - - public function setLinkTag($key, $tag) - { - $this->linkTags[$key] = $tag; - } - - public function getCss($key) - { - return isset($this->css[$key]) ? $this->css[$key]: null; - } - - public function setCss($key, $css) - { - $this->css[$key] = $css; - } - - public function getCssFile($key) - { - return isset($this->cssFiles[$key]) ? $this->cssFiles[$key]: null; - } - - public function setCssFile($key, $file) - { - $this->cssFiles[$key] = $file; - } - - public function getJs($key, $position = self::POS_END) - { - return isset($this->js[$position][$key]) ? $this->js[$position][$key] : null; - } - - public function setJs($key, $js, $position = self::POS_END) - { - $this->js[$position][$key] = $js; - } - - public function getJsFile($key, $position = self::POS_END) - { - return isset($this->jsFiles[$position][$key]) ? $this->jsFiles[$position][$key] : null; - } - - public function setJsFile($key, $file, $position = self::POS_END) - { - $this->jsFiles[$position][$key] = $file; - } - } \ No newline at end of file diff --git a/framework/widgets/Block.php b/framework/widgets/Block.php new file mode 100644 index 0000000..d6f7317 --- /dev/null +++ b/framework/widgets/Block.php @@ -0,0 +1,49 @@ + + * @since 2.0 + */ +class Block extends Widget +{ + /** + * @var string the ID of this block. + */ + public $id; + /** + * @var boolean whether to render the block content in place. Defaults to false, + * meaning the captured block content will not be displayed. + */ + public $renderInPlace = false; + + /** + * Starts recording a block. + */ + public function init() + { + ob_start(); + ob_implicit_flush(false); + } + + /** + * Ends recording a block. + * This method stops output buffering and saves the rendering result as a named block in the controller. + */ + public function run() + { + $block = ob_get_clean(); + if ($this->renderInPlace) { + echo $block; + } + $this->view->blocks[$this->id] = $block; + } +} \ No newline at end of file diff --git a/framework/widgets/Clip.php b/framework/widgets/Clip.php deleted file mode 100644 index f321209..0000000 --- a/framework/widgets/Clip.php +++ /dev/null @@ -1,51 +0,0 @@ - - * @since 2.0 - */ -class Clip extends Widget -{ - /** - * @var string the ID of this clip. - */ - public $id; - /** - * @var boolean whether to render the clip content in place. Defaults to false, - * meaning the captured clip will not be displayed. - */ - public $renderInPlace = false; - - /** - * Starts recording a clip. - */ - public function init() - { - ob_start(); - ob_implicit_flush(false); - } - - /** - * Ends recording a clip. - * This method stops output buffering and saves the rendering result as a named clip in the controller. - */ - public function run() - { - $clip = ob_get_clean(); - if ($this->renderClip) { - echo $clip; - } - $this->view->clips[$this->id] = $clip; - } -} \ No newline at end of file