Skip to content
This repository was archived by the owner on Nov 19, 2024. It is now read-only.

Use composer and Tale Jade #2

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
vendor/*
*.swp
composer.lock
3 changes: 0 additions & 3 deletions .gitmodules

This file was deleted.

19 changes: 14 additions & 5 deletions CJadeViewRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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);
}

/**
Expand All @@ -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);
}
Expand All @@ -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);
}

}
59 changes: 49 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -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(
Expand All @@ -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('<?php extract((array)$data); ?>'),
```

* 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.
9 changes: 9 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
1 change: 0 additions & 1 deletion vendors/jade
Submodule jade deleted from c103a2