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 deleted file mode 100644 index 272e1ba..0000000 --- a/.gitmodules +++ /dev/null @@ -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..d5206b1 100644 --- a/CJadeViewRenderer.php +++ b/CJadeViewRenderer.php @@ -22,7 +22,7 @@ * @license http://www.yiiframework.com/license/ */ -Yii::setPathOfAlias('Jade', dirname(__FILE__).'/vendors/jade/src/Jade'); +use Tale\Jade; class CJadeViewRenderer extends CViewRenderer { @@ -57,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\Jade(); + $this->jade = new Jade\Compiler($this->taleJadeConfig); } /** @@ -76,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); } @@ -102,12 +108,15 @@ public function renderFile($context,$sourceFile,$data,$return) $viewFile = $this->getViewFile($sourceFile); $viewFile = str_replace($this->fileExtension.($this->useRuntimePath?'':'c'), $this->viewFileExtension, $viewFile); - if(@filemtime($sourceFile) > @filemtime($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) || $forceRefresh) { $this->generateViewFile($sourceFile,$viewFile); @chmod($viewFile,$this->filePermission); } return $context->renderInternal($viewFile,$data,$return); } - } diff --git a/README.md b/README.md index 7d90409..10a67fe 100644 --- a/README.md +++ b/README.md @@ -1,18 +1,38 @@ +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](https://github.com/greenhost/yii-pug) instead.__ + + + 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 +42,29 @@ 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. 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. 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