-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 78eba82
Showing
9 changed files
with
273 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
/vendor | ||
composer.lock | ||
composer.phar |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
language: php | ||
|
||
php: | ||
- 5.4 | ||
- 5.5 | ||
- 5.6 | ||
- hhvm | ||
|
||
before_script: | ||
- composer self-update | ||
- composer install --prefer-source --no-interaction --dev | ||
|
||
script: phpunit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
The MIT License (MIT) | ||
|
||
Copyright (c) 2015 René van Asperen | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
## LaravelJade | ||
[![Build Status](https://travis-ci.org/rvanasperen/laravel-jade.svg)](https://travis-ci.org/rvanasperen/laravel-jade) | ||
[![License](https://poser.pugx.org/rvanasperen/laravel-jade/license.svg)](https://packagist.org/packages/rvanasperen/laravel-jade) | ||
|
||
LaravelJade is a library that adds [JadePHP templating](https://github.com/maht0rz/jade.php) support to Laravel 5.0 through [maht0rz's](https://github.com/maht0rz) [JadePHP package](https://github.com/maht0rz/jade.php). | ||
|
||
## Installation | ||
|
||
Require this package with composer: | ||
|
||
``` | ||
composer require rvanasperen/laravel-jade | ||
``` | ||
|
||
Add the ServiceProvider to the providers array in config/app.php: | ||
|
||
``` | ||
'LaravelJade\ServiceProvider', | ||
``` | ||
|
||
## Usage | ||
|
||
Create views as you would normally, prefixed with .jade.php. The view rendering engine should resolve and compile them as Jade templates automatically. | ||
|
||
## License | ||
|
||
LaravelJade is licensed under the [MIT license](http://opensource.org/licenses/MIT). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
{ | ||
"name": "rvanasperen/laravel-jade", | ||
"description": "Adds support for JadePHP templates to Laravel", | ||
"tags": [ | ||
"jade", | ||
"laravel", | ||
"template", | ||
"templating" | ||
], | ||
"license": "MIT", | ||
"authors": [ | ||
{ | ||
"name": "René van Asperen", | ||
"email": "rvanasperen@gmail.com" | ||
} | ||
], | ||
"require": { | ||
"php": ">=5.4.0", | ||
"illuminate/view": "5.0.*", | ||
"maht0rz/jade": "dev-master" | ||
}, | ||
"require-dev": { | ||
"mockery/mockery": "~0.9", | ||
"phpunit/phpunit": "~4.0" | ||
}, | ||
"autoload": { | ||
"psr-4": { | ||
"LaravelJade\\": "src/LaravelJade/" | ||
} | ||
}, | ||
"minimum-stability": "dev" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<phpunit backupGlobals="false" | ||
backupStaticAttributes="false" | ||
bootstrap="vendor/autoload.php" | ||
colors="true" | ||
convertErrorsToExceptions="true" | ||
convertNoticesToExceptions="true" | ||
convertWarningsToExceptions="true" | ||
processIsolation="false" | ||
stopOnFailure="false" | ||
syntaxCheck="false" | ||
> | ||
<testsuites> | ||
<testsuite name="Package Test Suite"> | ||
<directory suffix=".php">./tests/</directory> | ||
</testsuite> | ||
</testsuites> | ||
</phpunit> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
<?php namespace LaravelJade; | ||
|
||
use Everzet\Jade\Dumper\PHPDumper; | ||
use Everzet\Jade\Filter\CDATAFilter; | ||
use Everzet\Jade\Filter\CSSFilter; | ||
use Everzet\Jade\Filter\JavaScriptFilter; | ||
use Everzet\Jade\Filter\PHPFilter; | ||
use Everzet\Jade\Jade; | ||
use Everzet\Jade\Lexer\Lexer; | ||
use Everzet\Jade\Parser; | ||
use Everzet\Jade\Visitor\AutotagsVisitor; | ||
use Illuminate\Filesystem\Filesystem; | ||
use Illuminate\View\Compilers\Compiler; | ||
use Illuminate\View\Compilers\CompilerInterface; | ||
|
||
class JadeCompiler extends Compiler implements CompilerInterface | ||
{ | ||
/** | ||
* @var \Everzet\Jade\Jade | ||
*/ | ||
private $jade; | ||
|
||
/** | ||
* @var \Everzet\Jade\Parser | ||
*/ | ||
private $parser; | ||
|
||
/** | ||
* @var \Everzet\Jade\Lexer\Lexer | ||
*/ | ||
private $lexer; | ||
|
||
/** | ||
* @var \Everzet\Jade\Dumper\PHPDumper | ||
*/ | ||
private $dumper; | ||
|
||
/** | ||
* Create a new JadeCompiler instance. | ||
* | ||
* @param \Illuminate\Filesystem\Filesystem $files | ||
* @param string $cachePath | ||
*/ | ||
public function __construct(Filesystem $files, $cachePath) | ||
{ | ||
parent::__construct($files, $cachePath); | ||
|
||
$this->dumper = new PHPDumper; | ||
$this->dumper->registerVisitor('tag', new AutotagsVisitor); | ||
$this->dumper->registerFilter('javascript', new JavaScriptFilter); | ||
$this->dumper->registerFilter('cdata', new CDATAFilter); | ||
$this->dumper->registerFilter('php', new PHPFilter); | ||
$this->dumper->registerFilter('style', new CSSFilter); | ||
|
||
$this->lexer = new Lexer; | ||
$this->parser = new Parser($this->lexer); | ||
|
||
$this->jade = new Jade($this->parser, $this->dumper); | ||
} | ||
|
||
/** | ||
* Compile the view at the given path. | ||
* | ||
* @param string $path | ||
* @return void | ||
*/ | ||
public function compile($path) | ||
{ | ||
$contents = $this->compileString($this->files->get($path)); | ||
|
||
if (!is_null($this->cachePath)) { | ||
$this->files->put($this->getCompiledPath($path), $contents); | ||
} | ||
} | ||
|
||
/** | ||
* Compile the given Jade template contents. | ||
* | ||
* @param string $value | ||
* @return string | ||
*/ | ||
public function compileString($value) | ||
{ | ||
return $this->jade->render($value); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?php namespace LaravelJade; | ||
|
||
use Illuminate\Support\ServiceProvider as BaseServiceProvider; | ||
use Illuminate\View\Engines\CompilerEngine; | ||
use Illuminate\View\Engines\EngineResolver; | ||
|
||
class ServiceProvider extends BaseServiceProvider | ||
{ | ||
/** | ||
* Register the service provider. | ||
*/ | ||
public function register() | ||
{ | ||
$this->registerEngineResolver(); | ||
} | ||
|
||
/** | ||
* Register the engine resolver instance. | ||
*/ | ||
public function registerEngineResolver() | ||
{ | ||
$resolver = $this->app['view.engine.resolver']; | ||
|
||
$this->registerJadeEngine($resolver); | ||
} | ||
|
||
/** | ||
* Register the Jade engine implementation. | ||
* | ||
* @param \Illuminate\View\Engines\EngineResolver $resolver | ||
*/ | ||
public function registerJadeEngine(EngineResolver $resolver) | ||
{ | ||
$app = $this->app; | ||
|
||
$app->singleton('jade.compiler', function ($app) { | ||
$cache = $app['config']['view.compiled']; | ||
|
||
return new JadeCompiler($app['files'], $cache); | ||
}); | ||
|
||
$resolver->register('jade', function () use ($app) { | ||
return new CompilerEngine($app['jade.compiler'], $app['files']); | ||
}); | ||
|
||
$app['view']->addExtension('jade.php', 'jade'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php | ||
|
||
use LaravelJade\JadeCompiler; | ||
use Mockery as m; | ||
|
||
class JadeCompilerTest extends PHPUnit_Framework_TestCase | ||
{ | ||
public function tearDown() | ||
{ | ||
m::close(); | ||
} | ||
|
||
public function testBasicCompile() | ||
{ | ||
$compiler = new JadeCompiler($files = $this->getFiles(), __DIR__); | ||
|
||
$this->assertEquals('<html></html>', $compiler->compileString('html')); | ||
|
||
} | ||
|
||
protected function getFiles() | ||
{ | ||
return m::mock('Illuminate\Filesystem\Filesystem'); | ||
} | ||
} |