From 51923c82715a05fce028a17394909662f7daecd7 Mon Sep 17 00:00:00 2001 From: Qiang Xue Date: Mon, 9 Dec 2013 23:34:44 -0500 Subject: [PATCH] moved smarty to yii. --- extensions/smarty/LICENSE.md | 32 ----------- extensions/smarty/README.md | 41 -------------- extensions/smarty/ViewRenderer.php | 98 ---------------------------------- extensions/smarty/composer.json | 28 ---------- extensions/yii/smarty/LICENSE.md | 32 +++++++++++ extensions/yii/smarty/README.md | 41 ++++++++++++++ extensions/yii/smarty/ViewRenderer.php | 98 ++++++++++++++++++++++++++++++++++ extensions/yii/smarty/composer.json | 28 ++++++++++ 8 files changed, 199 insertions(+), 199 deletions(-) delete mode 100644 extensions/smarty/LICENSE.md delete mode 100644 extensions/smarty/README.md delete mode 100644 extensions/smarty/ViewRenderer.php delete mode 100644 extensions/smarty/composer.json create mode 100644 extensions/yii/smarty/LICENSE.md create mode 100644 extensions/yii/smarty/README.md create mode 100644 extensions/yii/smarty/ViewRenderer.php create mode 100644 extensions/yii/smarty/composer.json diff --git a/extensions/smarty/LICENSE.md b/extensions/smarty/LICENSE.md deleted file mode 100644 index e98f03d..0000000 --- a/extensions/smarty/LICENSE.md +++ /dev/null @@ -1,32 +0,0 @@ -The Yii framework is free software. It is released under the terms of -the following BSD License. - -Copyright © 2008 by Yii Software LLC (http://www.yiisoft.com) -All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions -are met: - - * Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in - the documentation and/or other materials provided with the - distribution. - * Neither the name of Yii Software LLC nor the names of its - contributors may be used to endorse or promote products derived - from this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS -FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE -COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, -INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, -BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; -LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN -ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -POSSIBILITY OF SUCH DAMAGE. diff --git a/extensions/smarty/README.md b/extensions/smarty/README.md deleted file mode 100644 index 06617f0..0000000 --- a/extensions/smarty/README.md +++ /dev/null @@ -1,41 +0,0 @@ -Smarty Extension for Yii 2 -========================== - -This extension provides a `ViewRender` that would allow you to use Smarty view template engine. - -To use this extension, simply add the following code in your application configuration: - -```php -return [ - //.... - 'components' => [ - 'view' => [ - 'renderers' => [ - 'tpl' => [ - 'class' => 'yii\smarty\ViewRenderer', - //'cachePath' => '@runtime/Smarty/cache', - ], - ], - ], - ], -]; -``` - -Installation ------------- - -The preferred way to install this extension is through [composer](http://getcomposer.org/download/). - -Either run - -``` -php composer.phar require yiisoft/yii2-smarty "*" -``` - -or add - -```json -"yiisoft/yii2-smarty": "*" -``` - -to the require section of your composer.json. diff --git a/extensions/smarty/ViewRenderer.php b/extensions/smarty/ViewRenderer.php deleted file mode 100644 index 2cfb216..0000000 --- a/extensions/smarty/ViewRenderer.php +++ /dev/null @@ -1,98 +0,0 @@ - - * @since 2.0 - */ -class ViewRenderer extends BaseViewRenderer -{ - /** - * @var string the directory or path alias pointing to where Smarty cache will be stored. - */ - public $cachePath = '@runtime/Smarty/cache'; - - /** - * @var string the directory or path alias pointing to where Smarty compiled templates will be stored. - */ - public $compilePath = '@runtime/Smarty/compile'; - - /** - * @var Smarty - */ - public $smarty; - - public function init() - { - $this->smarty = new Smarty(); - $this->smarty->setCompileDir(Yii::getAlias($this->compilePath)); - $this->smarty->setCacheDir(Yii::getAlias($this->cachePath)); - - $this->smarty->registerPlugin('function', 'path', [$this, 'smarty_function_path']); - } - - /** - * Smarty template function to get a path for using in links - * - * Usage is the following: - * - * {path route='blog/view' alias=$post.alias user=$user.id} - * - * where route is Yii route and the rest of parameters are passed as is. - * - * @param $params - * @param \Smarty_Internal_Template $template - * - * @return string - */ - public function smarty_function_path($params, \Smarty_Internal_Template $template) - { - if (!isset($params['route'])) { - trigger_error("path: missing 'route' parameter"); - } - - array_unshift($params, $params['route']) ; - unset($params['route']); - - return Html::url($params); - } - - /** - * Renders a view file. - * - * This method is invoked by [[View]] whenever it tries to render a view. - * Child classes must implement this method to render the given view file. - * - * @param View $view the view object used for rendering the file. - * @param string $file the view file. - * @param array $params the parameters to be passed to the view file. - * - * @return string the rendering result - */ - public function render($view, $file, $params) - { - /** @var \Smarty_Internal_Template $template */ - $template = $this->smarty->createTemplate($file, null, null, $params, true); - - $template->assign('app', \Yii::$app); - $template->assign('this', $view); - - return $template->fetch(); - } -} diff --git a/extensions/smarty/composer.json b/extensions/smarty/composer.json deleted file mode 100644 index a3a8254..0000000 --- a/extensions/smarty/composer.json +++ /dev/null @@ -1,28 +0,0 @@ -{ - "name": "yiisoft/yii2-smarty", - "description": "The Smarty integration for the Yii framework", - "keywords": ["yii", "smarty", "renderer"], - "type": "yii2-extension", - "license": "BSD-3-Clause", - "support": { - "issues": "https://github.com/yiisoft/yii2/issues?labels=ext%3Asmarty", - "forum": "http://www.yiiframework.com/forum/", - "wiki": "http://www.yiiframework.com/wiki/", - "irc": "irc://irc.freenode.net/yii", - "source": "https://github.com/yiisoft/yii2" - }, - "authors": [ - { - "name": "Alexander Makarov", - "email": "sam@rmcreative.ru" - } - ], - "require": { - "yiisoft/yii2": "*", - "smarty/smarty": "*" - }, - "autoload": { - "psr-0": { "yii\\smarty\\": "" } - }, - "target-dir": "yii/smarty" -} diff --git a/extensions/yii/smarty/LICENSE.md b/extensions/yii/smarty/LICENSE.md new file mode 100644 index 0000000..e98f03d --- /dev/null +++ b/extensions/yii/smarty/LICENSE.md @@ -0,0 +1,32 @@ +The Yii framework is free software. It is released under the terms of +the following BSD License. + +Copyright © 2008 by Yii Software LLC (http://www.yiisoft.com) +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions +are met: + + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in + the documentation and/or other materials provided with the + distribution. + * Neither the name of Yii Software LLC nor the names of its + contributors may be used to endorse or promote products derived + from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +POSSIBILITY OF SUCH DAMAGE. diff --git a/extensions/yii/smarty/README.md b/extensions/yii/smarty/README.md new file mode 100644 index 0000000..06617f0 --- /dev/null +++ b/extensions/yii/smarty/README.md @@ -0,0 +1,41 @@ +Smarty Extension for Yii 2 +========================== + +This extension provides a `ViewRender` that would allow you to use Smarty view template engine. + +To use this extension, simply add the following code in your application configuration: + +```php +return [ + //.... + 'components' => [ + 'view' => [ + 'renderers' => [ + 'tpl' => [ + 'class' => 'yii\smarty\ViewRenderer', + //'cachePath' => '@runtime/Smarty/cache', + ], + ], + ], + ], +]; +``` + +Installation +------------ + +The preferred way to install this extension is through [composer](http://getcomposer.org/download/). + +Either run + +``` +php composer.phar require yiisoft/yii2-smarty "*" +``` + +or add + +```json +"yiisoft/yii2-smarty": "*" +``` + +to the require section of your composer.json. diff --git a/extensions/yii/smarty/ViewRenderer.php b/extensions/yii/smarty/ViewRenderer.php new file mode 100644 index 0000000..2cfb216 --- /dev/null +++ b/extensions/yii/smarty/ViewRenderer.php @@ -0,0 +1,98 @@ + + * @since 2.0 + */ +class ViewRenderer extends BaseViewRenderer +{ + /** + * @var string the directory or path alias pointing to where Smarty cache will be stored. + */ + public $cachePath = '@runtime/Smarty/cache'; + + /** + * @var string the directory or path alias pointing to where Smarty compiled templates will be stored. + */ + public $compilePath = '@runtime/Smarty/compile'; + + /** + * @var Smarty + */ + public $smarty; + + public function init() + { + $this->smarty = new Smarty(); + $this->smarty->setCompileDir(Yii::getAlias($this->compilePath)); + $this->smarty->setCacheDir(Yii::getAlias($this->cachePath)); + + $this->smarty->registerPlugin('function', 'path', [$this, 'smarty_function_path']); + } + + /** + * Smarty template function to get a path for using in links + * + * Usage is the following: + * + * {path route='blog/view' alias=$post.alias user=$user.id} + * + * where route is Yii route and the rest of parameters are passed as is. + * + * @param $params + * @param \Smarty_Internal_Template $template + * + * @return string + */ + public function smarty_function_path($params, \Smarty_Internal_Template $template) + { + if (!isset($params['route'])) { + trigger_error("path: missing 'route' parameter"); + } + + array_unshift($params, $params['route']) ; + unset($params['route']); + + return Html::url($params); + } + + /** + * Renders a view file. + * + * This method is invoked by [[View]] whenever it tries to render a view. + * Child classes must implement this method to render the given view file. + * + * @param View $view the view object used for rendering the file. + * @param string $file the view file. + * @param array $params the parameters to be passed to the view file. + * + * @return string the rendering result + */ + public function render($view, $file, $params) + { + /** @var \Smarty_Internal_Template $template */ + $template = $this->smarty->createTemplate($file, null, null, $params, true); + + $template->assign('app', \Yii::$app); + $template->assign('this', $view); + + return $template->fetch(); + } +} diff --git a/extensions/yii/smarty/composer.json b/extensions/yii/smarty/composer.json new file mode 100644 index 0000000..a3a8254 --- /dev/null +++ b/extensions/yii/smarty/composer.json @@ -0,0 +1,28 @@ +{ + "name": "yiisoft/yii2-smarty", + "description": "The Smarty integration for the Yii framework", + "keywords": ["yii", "smarty", "renderer"], + "type": "yii2-extension", + "license": "BSD-3-Clause", + "support": { + "issues": "https://github.com/yiisoft/yii2/issues?labels=ext%3Asmarty", + "forum": "http://www.yiiframework.com/forum/", + "wiki": "http://www.yiiframework.com/wiki/", + "irc": "irc://irc.freenode.net/yii", + "source": "https://github.com/yiisoft/yii2" + }, + "authors": [ + { + "name": "Alexander Makarov", + "email": "sam@rmcreative.ru" + } + ], + "require": { + "yiisoft/yii2": "*", + "smarty/smarty": "*" + }, + "autoload": { + "psr-0": { "yii\\smarty\\": "" } + }, + "target-dir": "yii/smarty" +}