From 9f87e0e1da14666032e808d51367d9fa18f70f89 Mon Sep 17 00:00:00 2001 From: Maarten de Waard Date: Thu, 4 Aug 2016 17:23:40 +0200 Subject: [PATCH 1/8] move to using composer, move to Talesofts Jade implementation --- .gitignore | 3 +++ .gitmodules | 3 --- CJadeViewRenderer.php | 5 +++-- composer.json | 9 +++++++++ vendors/jade | 1 - 5 files changed, 15 insertions(+), 6 deletions(-) create mode 100644 .gitignore create mode 100644 composer.json delete mode 160000 vendors/jade diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..114228e --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +vendor/* +*.swp +composer.lock diff --git a/.gitmodules b/.gitmodules index 272e1ba..e69de29 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +0,0 @@ -[submodule "vendors/jade"] - path = vendors/jade - url = git@github.com:sisoftrg/jade.php.git diff --git a/CJadeViewRenderer.php b/CJadeViewRenderer.php index da4c9a6..99301ca 100644 --- a/CJadeViewRenderer.php +++ b/CJadeViewRenderer.php @@ -22,7 +22,8 @@ * @license http://www.yiiframework.com/license/ */ -Yii::setPathOfAlias('Jade', dirname(__FILE__).'/vendors/jade/src/Jade'); +use Tale\Jade; +include(dirname(__FILE__) . '/vendor/autoload'); class CJadeViewRenderer extends CViewRenderer { @@ -62,7 +63,7 @@ class CJadeViewRenderer extends CViewRenderer */ public function init() { parent::init(); - $this->jade = new Jade\Jade(); + $this->jade = new Jade\Renderer(); } /** diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..ec56310 --- /dev/null +++ b/composer.json @@ -0,0 +1,9 @@ +{ + "name": "greenhost/yii-jade", + "description": "Fork of Yii's extension for Jade template system", + "license" : "New BSD License", + "homepage": "https://github.com/greenhost/yii-jade", + "require": { + "talesoft/tale-jade": "^1.4" + } +} diff --git a/vendors/jade b/vendors/jade deleted file mode 160000 index c103a21..0000000 --- a/vendors/jade +++ /dev/null @@ -1 +0,0 @@ -Subproject commit c103a219a472dda71d3d1ccb01d50407a9106f98 From 7e976f9f7204941b8c21ac4dcc101434038bafcb Mon Sep 17 00:00:00 2001 From: Maarten de Waard Date: Fri, 5 Aug 2016 16:43:06 +0200 Subject: [PATCH 2/8] use tale compiler instead of renderer, do not load autoload --- CJadeViewRenderer.php | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/CJadeViewRenderer.php b/CJadeViewRenderer.php index 99301ca..57b6520 100644 --- a/CJadeViewRenderer.php +++ b/CJadeViewRenderer.php @@ -23,7 +23,6 @@ */ use Tale\Jade; -include(dirname(__FILE__) . '/vendor/autoload'); class CJadeViewRenderer extends CViewRenderer { @@ -58,12 +57,18 @@ class CJadeViewRenderer extends CViewRenderer */ public $prepend; + /** + * @var array the jade configuration for tale-jade, supplied to the + * constructor of Renderer + */ + public $taleJadeConfig = []; + /** * Init a Jade parser instance */ public function init() { parent::init(); - $this->jade = new Jade\Renderer(); + $this->jade = new Jade\Compiler($this->taleJadeConfig); } /** @@ -77,7 +82,7 @@ protected function generateViewFile($sourceFile,$viewFile) if ($this->jade == null) $this->init(); - $data = $this->jade->render($sourceFile); + $data = $this->jade->compileFile($sourceFile); } else { $data = file_get_contents($sourceFile); } From 9ada8690b857b79dd94191de284d9e9133e36b24 Mon Sep 17 00:00:00 2001 From: Maarten de Waard Date: Wed, 7 Sep 2016 15:15:13 +0200 Subject: [PATCH 3/8] expand readme --- README.md | 50 ++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 40 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 7d90409..7813ef4 100644 --- a/README.md +++ b/README.md @@ -3,16 +3,30 @@ Yii-jade Yii's extension for Jade template system ## Instructions -* Code must be in this folder 'protected/extensions/yii-jade/' -* Since I'm using git submodules, you need to init them: - ```bash - cd protected/extensions/yii-jade - git submodule init - git submodule update +### Installation + +Install yii-jade with composer. Because it is not in the standard composer +repositories, you will need to add the repository to your composer.json file as +well: + ``` - -* Add this to your 'config/main.php' file: + "repositories": [ + { + "url": "https://github.com/greenhost/yii-jade", + "type": "vcs" + } + ] + "require": { + "greenhost/yii-jade": "dev-dev@dev", + }, + + ``` + +### Configuration + + +To enable yii-jade, add this to your 'config/main.php' file: ```php 'components'=>array( @@ -22,10 +36,26 @@ Yii's extension for Jade template system ), ... ``` -* You may want to add the following line, so the compiled templates will have passed data to a template in the main var list + +You may want to add the following line, so the compiled templates will have passed data to a template in the main var list + ```php 'prepend' => array(''), ``` -* Jade templates must have '.jade' extension +It is possible to configure other variables: check the class variables in +`CJadeViewRenderer.php`. Each public variable can be configured in your main.php +yii configuration file, e.g.: + + ```php + 'components'=>array( + ... + 'viewRenderer'=>array( + 'class' => 'ext.yii-jade.CJadeViewRenderer', + 'filePermission' => '775', + ), + ... + ``` + +sets the file permissions of all the files yii-jade creates to 775. From b1bbb0937188b048d8fa8166db5735aa6ee0dfb7 Mon Sep 17 00:00:00 2001 From: Maarten de Waard Date: Thu, 22 Sep 2016 17:38:38 +0200 Subject: [PATCH 4/8] comment out renderFile function which adds nothing really... --- CJadeViewRenderer.php | 46 +++++++++++++++++++++---------------------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/CJadeViewRenderer.php b/CJadeViewRenderer.php index 57b6520..2a77f7b 100644 --- a/CJadeViewRenderer.php +++ b/CJadeViewRenderer.php @@ -89,31 +89,31 @@ protected function generateViewFile($sourceFile,$viewFile) file_put_contents($viewFile, $this->prepend[0] . $data); } - /** - * Renders a view file. - * This method is required by {@link IViewRenderer}. - * @param CBaseController $context the controller or widget who is rendering the view file. - * @param string $sourceFile the view file path - * @param mixed $data the data to be passed to the view - * @param boolean $return whether the rendering result should be returned - * @return mixed the rendering result, or null if the rendering result is not needed. - */ - public function renderFile($context,$sourceFile,$data,$return) - { - $jadeSourceFile = substr($sourceFile, 0, strrpos($sourceFile, '.')).$this->fileExtension; + ///** + // * Renders a view file. + // * This method is required by {@link IViewRenderer}. + // * @param CBaseController $context the controller or widget who is rendering the view file. + // * @param string $sourceFile the view file path + // * @param mixed $data the data to be passed to the view + // * @param boolean $return whether the rendering result should be returned + // * @return mixed the rendering result, or null if the rendering result is not needed. + // */ + //public function renderFile($context,$sourceFile,$data,$return) + //{ + // $jadeSourceFile = substr($sourceFile, 0, strrpos($sourceFile, '.')).$this->fileExtension; - if(!is_file($jadeSourceFile) || ($file=realpath($jadeSourceFile))===false) - return parent::renderFile($context, $sourceFile, $data, $return); + // if(!is_file($jadeSourceFile) || ($file=realpath($jadeSourceFile))===false) + // return parent::renderFile($context, $sourceFile, $data, $return); - $viewFile = $this->getViewFile($sourceFile); - $viewFile = str_replace($this->fileExtension.($this->useRuntimePath?'':'c'), $this->viewFileExtension, $viewFile); + // $viewFile = $this->getViewFile($sourceFile); + // $viewFile = str_replace($this->fileExtension.($this->useRuntimePath?'':'c'), $this->viewFileExtension, $viewFile); - if(@filemtime($sourceFile) > @filemtime($viewFile)) - { - $this->generateViewFile($sourceFile,$viewFile); - @chmod($viewFile,$this->filePermission); - } - return $context->renderInternal($viewFile,$data,$return); - } + // if(@filemtime($sourceFile) > @filemtime($viewFile)) + // { + // $this->generateViewFile($sourceFile,$viewFile); + // @chmod($viewFile,$this->filePermission); + // } + // return $context->renderInternal($viewFile,$data,$return); + //} } From 2e139be413e3a93f639d2af437bf0e8ae0ef979d Mon Sep 17 00:00:00 2001 From: Chris Snijder Date: Mon, 3 Oct 2016 14:08:37 +0200 Subject: [PATCH 5/8] Make rendered templates have .php extentions instead of .jade extensions. Also add _flush capability. --- CJadeViewRenderer.php | 34 +++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/CJadeViewRenderer.php b/CJadeViewRenderer.php index 2a77f7b..a5b2df3 100644 --- a/CJadeViewRenderer.php +++ b/CJadeViewRenderer.php @@ -58,7 +58,7 @@ class CJadeViewRenderer extends CViewRenderer public $prepend; /** - * @var array the jade configuration for tale-jade, supplied to the + * @var array the jade configuration for tale-jade, supplied to the * constructor of Renderer */ public $taleJadeConfig = []; @@ -98,22 +98,26 @@ protected function generateViewFile($sourceFile,$viewFile) // * @param boolean $return whether the rendering result should be returned // * @return mixed the rendering result, or null if the rendering result is not needed. // */ - //public function renderFile($context,$sourceFile,$data,$return) - //{ - // $jadeSourceFile = substr($sourceFile, 0, strrpos($sourceFile, '.')).$this->fileExtension; + public function renderFile($context,$sourceFile,$data,$return) + { + $jadeSourceFile = substr($sourceFile, 0, strrpos($sourceFile, '.')).$this->fileExtension; + + if(!is_file($jadeSourceFile) || ($file=realpath($jadeSourceFile))===false) + return parent::renderFile($context, $sourceFile, $data, $return); - // if(!is_file($jadeSourceFile) || ($file=realpath($jadeSourceFile))===false) - // return parent::renderFile($context, $sourceFile, $data, $return); + $viewFile = $this->getViewFile($sourceFile); + $viewFile = str_replace($this->fileExtension.($this->useRuntimePath?'':'c'), $this->viewFileExtension, $viewFile); - // $viewFile = $this->getViewFile($sourceFile); - // $viewFile = str_replace($this->fileExtension.($this->useRuntimePath?'':'c'), $this->viewFileExtension, $viewFile); + // Included Jade files do not cause the cache to be invalidated. + // By forcing a flush you can make Jade regenerate all views. + $forceRefresh = array_key_exists('_flush', $_GET); - // if(@filemtime($sourceFile) > @filemtime($viewFile)) - // { - // $this->generateViewFile($sourceFile,$viewFile); - // @chmod($viewFile,$this->filePermission); - // } - // return $context->renderInternal($viewFile,$data,$return); - //} + if(@filemtime($sourceFile) > @filemtime($viewFile) || $forceRefresh) + { + $this->generateViewFile($sourceFile,$viewFile); + @chmod($viewFile,$this->filePermission); + } + return $context->renderInternal($viewFile,$data,$return); + } } From e2a0f22e2d8d43df1b1f9e6a58f7d32872c71fe8 Mon Sep 17 00:00:00 2001 From: Maarten de Waard Date: Mon, 12 Dec 2016 11:17:43 +0100 Subject: [PATCH 6/8] cleanup --- .gitmodules | 0 CJadeViewRenderer.php | 19 +++++++++---------- README.md | 5 ++++- 3 files changed, 13 insertions(+), 11 deletions(-) delete mode 100644 .gitmodules diff --git a/.gitmodules b/.gitmodules deleted file mode 100644 index e69de29..0000000 diff --git a/CJadeViewRenderer.php b/CJadeViewRenderer.php index a5b2df3..d5206b1 100644 --- a/CJadeViewRenderer.php +++ b/CJadeViewRenderer.php @@ -89,15 +89,15 @@ protected function generateViewFile($sourceFile,$viewFile) file_put_contents($viewFile, $this->prepend[0] . $data); } - ///** - // * Renders a view file. - // * This method is required by {@link IViewRenderer}. - // * @param CBaseController $context the controller or widget who is rendering the view file. - // * @param string $sourceFile the view file path - // * @param mixed $data the data to be passed to the view - // * @param boolean $return whether the rendering result should be returned - // * @return mixed the rendering result, or null if the rendering result is not needed. - // */ + /** + * Renders a view file. + * This method is required by {@link IViewRenderer}. + * @param CBaseController $context the controller or widget who is rendering the view file. + * @param string $sourceFile the view file path + * @param mixed $data the data to be passed to the view + * @param boolean $return whether the rendering result should be returned + * @return mixed the rendering result, or null if the rendering result is not needed. + */ public function renderFile($context,$sourceFile,$data,$return) { $jadeSourceFile = substr($sourceFile, 0, strrpos($sourceFile, '.')).$this->fileExtension; @@ -119,5 +119,4 @@ public function renderFile($context,$sourceFile,$data,$return) } return $context->renderInternal($viewFile,$data,$return); } - } diff --git a/README.md b/README.md index 7813ef4..7dc8f0d 100644 --- a/README.md +++ b/README.md @@ -58,4 +58,7 @@ yii configuration file, e.g.: ... ``` -sets the file permissions of all the files yii-jade creates to 775. +sets the file permissions of all the files yii-jade creates to 775. Note that +this is applied to the compiled templates with `chmod`, so this overrides the +umask you set in PHP. Also note that this does *not* override any permissions of +directories that are automatically created. From c7ebfedc955fc5b79f9d7da1c73d018f25aba944 Mon Sep 17 00:00:00 2001 From: Chris Date: Tue, 4 Apr 2017 12:01:17 +0200 Subject: [PATCH 7/8] Update README.md --- README.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/README.md b/README.md index 7dc8f0d..7c330d9 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,9 @@ +Note: +----- +__The original Jade was renamed to Pug some time ago, Talesoft has since renamed their port of Jade: TaleJade to TalePug. This wrapper still uses TaleJade, it's still here in case someone is pulling this in with composer. But you should really use [github.com/greenhost/yii-pug](github.com/greenhost/yii-pug) instead.__ + + + Yii-jade ======== Yii's extension for Jade template system From 78113ad09243095987843596de60294bf6bede00 Mon Sep 17 00:00:00 2001 From: Chris Date: Tue, 4 Apr 2017 12:03:12 +0200 Subject: [PATCH 8/8] Fix URL in readme --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 7c330d9..10a67fe 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ Note: ----- -__The original Jade was renamed to Pug some time ago, Talesoft has since renamed their port of Jade: TaleJade to TalePug. This wrapper still uses TaleJade, it's still here in case someone is pulling this in with composer. But you should really use [github.com/greenhost/yii-pug](github.com/greenhost/yii-pug) instead.__ +__The original Jade was renamed to Pug some time ago, Talesoft has since renamed their port of Jade: TaleJade to TalePug. This wrapper still uses TaleJade, it's still here in case someone is pulling this in with composer. But you should really use [github.com/greenhost/yii-pug](https://github.com/greenhost/yii-pug) instead.__