From 02a2a50b5a755ee215838d8673ff5a91902abf4f Mon Sep 17 00:00:00 2001 From: Qiang Xue Date: Mon, 9 Dec 2013 23:16:17 -0500 Subject: [PATCH] moved twig to yii subdirectory. --- extensions/twig/LICENSE.md | 32 ---------------- extensions/twig/README.md | 43 --------------------- extensions/twig/ViewRenderer.php | 73 ------------------------------------ extensions/twig/composer.json | 28 -------------- extensions/yii/twig/LICENSE.md | 32 ++++++++++++++++ extensions/yii/twig/README.md | 43 +++++++++++++++++++++ extensions/yii/twig/ViewRenderer.php | 73 ++++++++++++++++++++++++++++++++++++ extensions/yii/twig/composer.json | 28 ++++++++++++++ 8 files changed, 176 insertions(+), 176 deletions(-) delete mode 100644 extensions/twig/LICENSE.md delete mode 100644 extensions/twig/README.md delete mode 100644 extensions/twig/ViewRenderer.php delete mode 100644 extensions/twig/composer.json create mode 100644 extensions/yii/twig/LICENSE.md create mode 100644 extensions/yii/twig/README.md create mode 100644 extensions/yii/twig/ViewRenderer.php create mode 100644 extensions/yii/twig/composer.json diff --git a/extensions/twig/LICENSE.md b/extensions/twig/LICENSE.md deleted file mode 100644 index e98f03d..0000000 --- a/extensions/twig/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/twig/README.md b/extensions/twig/README.md deleted file mode 100644 index 8099e1c..0000000 --- a/extensions/twig/README.md +++ /dev/null @@ -1,43 +0,0 @@ -Twig Extension for Yii 2 -======================== - -This extension provides a `ViewRender` that would allow you to use Twig view template engine. - -To use this extension, simply add the following code in your application configuration: - -```php -return [ - //.... - 'components' => [ - 'view' => [ - 'renderers' => [ - 'twig' => [ - 'class' => 'yii\twig\ViewRenderer', - //'cachePath' => '@runtime/Twig/cache', - //'options' => [], /* Array of twig options */ - ], - ], - ], - ], -]; -``` - - -Installation ------------- - -The preferred way to install this extension is through [composer](http://getcomposer.org/download/). - -Either run - -``` -php composer.phar require yiisoft/yii2-twig "*" -``` - -or add - -``` -"yiisoft/yii2-twig": "*" -``` - -to the require section of your composer.json. diff --git a/extensions/twig/ViewRenderer.php b/extensions/twig/ViewRenderer.php deleted file mode 100644 index b1598cf..0000000 --- a/extensions/twig/ViewRenderer.php +++ /dev/null @@ -1,73 +0,0 @@ - - * @since 2.0 - */ -class ViewRenderer extends BaseViewRenderer -{ - /** - * @var string the directory or path alias pointing to where Twig cache will be stored. - */ - public $cachePath = '@runtime/Twig/cache'; - - /** - * @var array Twig options - * @see http://twig.sensiolabs.org/doc/api.html#environment-options - */ - public $options = []; - - /** - * @var \Twig_Environment - */ - public $twig; - - public function init() - { - $loader = new \Twig_Loader_String(); - - $this->twig = new \Twig_Environment($loader, array_merge([ - 'cache' => Yii::getAlias($this->cachePath), - ], $this->options)); - - $this->twig->addFunction('path', new \Twig_Function_Function(function ($path, $args = []) { - return Html::url(array_merge([$path], $args)); - })); - - $this->twig->addGlobal('app', \Yii::$app); - } - - /** - * 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) - { - $this->twig->addGlobal('this', $view); - return $this->twig->render(file_get_contents($file), $params); - } -} diff --git a/extensions/twig/composer.json b/extensions/twig/composer.json deleted file mode 100644 index 1e7f49e..0000000 --- a/extensions/twig/composer.json +++ /dev/null @@ -1,28 +0,0 @@ -{ - "name": "yiisoft/yii2-twig", - "description": "The Twig integration for the Yii framework", - "keywords": ["yii", "twig", "renderer"], - "type": "yii2-extension", - "license": "BSD-3-Clause", - "support": { - "issues": "https://github.com/yiisoft/yii2/issues?labels=ext%3Atwig", - "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": "*", - "twig/twig": "*" - }, - "autoload": { - "psr-0": { "yii\\twig\\": "" } - }, - "target-dir": "yii/twig" -} diff --git a/extensions/yii/twig/LICENSE.md b/extensions/yii/twig/LICENSE.md new file mode 100644 index 0000000..e98f03d --- /dev/null +++ b/extensions/yii/twig/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/twig/README.md b/extensions/yii/twig/README.md new file mode 100644 index 0000000..8099e1c --- /dev/null +++ b/extensions/yii/twig/README.md @@ -0,0 +1,43 @@ +Twig Extension for Yii 2 +======================== + +This extension provides a `ViewRender` that would allow you to use Twig view template engine. + +To use this extension, simply add the following code in your application configuration: + +```php +return [ + //.... + 'components' => [ + 'view' => [ + 'renderers' => [ + 'twig' => [ + 'class' => 'yii\twig\ViewRenderer', + //'cachePath' => '@runtime/Twig/cache', + //'options' => [], /* Array of twig options */ + ], + ], + ], + ], +]; +``` + + +Installation +------------ + +The preferred way to install this extension is through [composer](http://getcomposer.org/download/). + +Either run + +``` +php composer.phar require yiisoft/yii2-twig "*" +``` + +or add + +``` +"yiisoft/yii2-twig": "*" +``` + +to the require section of your composer.json. diff --git a/extensions/yii/twig/ViewRenderer.php b/extensions/yii/twig/ViewRenderer.php new file mode 100644 index 0000000..b1598cf --- /dev/null +++ b/extensions/yii/twig/ViewRenderer.php @@ -0,0 +1,73 @@ + + * @since 2.0 + */ +class ViewRenderer extends BaseViewRenderer +{ + /** + * @var string the directory or path alias pointing to where Twig cache will be stored. + */ + public $cachePath = '@runtime/Twig/cache'; + + /** + * @var array Twig options + * @see http://twig.sensiolabs.org/doc/api.html#environment-options + */ + public $options = []; + + /** + * @var \Twig_Environment + */ + public $twig; + + public function init() + { + $loader = new \Twig_Loader_String(); + + $this->twig = new \Twig_Environment($loader, array_merge([ + 'cache' => Yii::getAlias($this->cachePath), + ], $this->options)); + + $this->twig->addFunction('path', new \Twig_Function_Function(function ($path, $args = []) { + return Html::url(array_merge([$path], $args)); + })); + + $this->twig->addGlobal('app', \Yii::$app); + } + + /** + * 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) + { + $this->twig->addGlobal('this', $view); + return $this->twig->render(file_get_contents($file), $params); + } +} diff --git a/extensions/yii/twig/composer.json b/extensions/yii/twig/composer.json new file mode 100644 index 0000000..1e7f49e --- /dev/null +++ b/extensions/yii/twig/composer.json @@ -0,0 +1,28 @@ +{ + "name": "yiisoft/yii2-twig", + "description": "The Twig integration for the Yii framework", + "keywords": ["yii", "twig", "renderer"], + "type": "yii2-extension", + "license": "BSD-3-Clause", + "support": { + "issues": "https://github.com/yiisoft/yii2/issues?labels=ext%3Atwig", + "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": "*", + "twig/twig": "*" + }, + "autoload": { + "psr-0": { "yii\\twig\\": "" } + }, + "target-dir": "yii/twig" +}