├── .gitignore ├── .travis.yml ├── README.md ├── composer.json ├── phpunit.xml ├── src ├── Engine.php └── LaravelPlatesServiceProvider.php └── tests ├── .gitkeep └── EngineTest.php /.gitignore: -------------------------------------------------------------------------------- 1 | /vendor 2 | composer.phar 3 | composer.lock 4 | .DS_Store -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: php 2 | 3 | php: 4 | - 5.3 5 | - 5.4 6 | - 5.5 7 | 8 | before_script: 9 | - curl -s http://getcomposer.org/installer | php 10 | - php composer.phar install --dev 11 | 12 | script: phpunit -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # laravel-plates 2 | 3 | A Laravel driver for the powerful native PHP templating system [Plates](http://platesphp.com). 4 | 5 | ## Installation with Composer 6 | 7 | #### Step 1: Install package through Composer 8 | 9 | Add this line to the `require` section of your `composer.json`: 10 | 11 | "franzl/laravel-plates": "dev-master" 12 | 13 | Alternately, you can use the Composer command-line tool by running this command: 14 | 15 | composer require franzl/laravel-plates 16 | 17 | Next, run `composer install` to actually install the package. 18 | 19 | #### Step 2: Register the service provider 20 | 21 | In your Laravel application, edit the `app/config/app.php` file and add this 22 | line to the `providers` array: 23 | 24 | 'Franzl\LaravelPlates\LaravelPlatesServiceProvider', 25 | 26 | ## Usage 27 | 28 | Once installed, you can use Laravel's view system as you always do. Files ending in `.plates.php` will automatically be treated as Plates templates. As long as you don't try to combine things like Blade layouts and Plates' partial views, everything should go well. 29 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "franzl/laravel-plates", 3 | "description": "The powerful native PHP templating system Plates for Laravel.", 4 | "authors": [ 5 | { 6 | "name": "Franz Liedke", 7 | "email": "franz@develophp.org" 8 | } 9 | ], 10 | "require": { 11 | "php": ">=5.3.0", 12 | "illuminate/support": "~5", 13 | "illuminate/view": "~5", 14 | "league/plates": "~3.1" 15 | }, 16 | "require-dev": { 17 | "squizlabs/php_codesniffer": "~1.5", 18 | "phpunit/phpunit": "~4.2" 19 | }, 20 | "autoload": { 21 | "psr-4": { 22 | "Franzl\\LaravelPlates\\": "src/" 23 | } 24 | }, 25 | "extra": { 26 | "branch-alias": { 27 | "dev-master": "1.0.x-dev" 28 | } 29 | }, 30 | "minimum-stability": "stable" 31 | } 32 | -------------------------------------------------------------------------------- /phpunit.xml: -------------------------------------------------------------------------------- 1 | 2 | 13 | 14 | 15 | ./tests/ 16 | 17 | 18 | -------------------------------------------------------------------------------- /src/Engine.php: -------------------------------------------------------------------------------- 1 | engine = $engine; 15 | } 16 | 17 | /** 18 | * Get the evaluated contents of the view. 19 | * 20 | * @param string $path 21 | * @param array $data 22 | * @return string 23 | */ 24 | public function get($path, array $data = array()) 25 | { 26 | $path = substr($path, strlen($this->engine->getDirectory())); 27 | $path = substr($path, 0, -strlen('.'.$this->engine->getFileExtension())); 28 | 29 | return $this->engine->render($path, $data); 30 | } 31 | } -------------------------------------------------------------------------------- /src/LaravelPlatesServiceProvider.php: -------------------------------------------------------------------------------- 1 | app; 17 | 18 | $app->singleton('League\Plates\Engine', function () use ($app) { 19 | $path = $app['config']['view.paths'][0]; 20 | 21 | return new PlatesEngine($path, 'plates.php'); 22 | }); 23 | 24 | $app->resolving('view', function($view) use ($app) { 25 | $view->addExtension('plates.php', 'plates', function() use ($app) { 26 | return new Engine($app->make('League\Plates\Engine')); 27 | }); 28 | }); 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /tests/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/franzliedke/laravel-plates/8cf885219f947fdd608abb533821880362fece35/tests/.gitkeep -------------------------------------------------------------------------------- /tests/EngineTest.php: -------------------------------------------------------------------------------- 1 | platesEngine = $this->getMock('League\Plates\Engine', [], [], '', false); 20 | $this->engine = new Engine($this->platesEngine); 21 | } 22 | 23 | public function checkInitialization() 24 | { 25 | $this->assertInstanceOf('Illuminate\View\Engines\EngineInterface', $this->engine); 26 | } 27 | 28 | public function testGet() 29 | { 30 | $this->platesEngine->expects($this->once()) 31 | ->method('getDirectory') 32 | ->willReturn('/var/www/app/views'); 33 | 34 | $this->platesEngine->expects($this->once()) 35 | ->method('getFileExtension') 36 | ->willReturn('plates.php'); 37 | 38 | $template = '/var/www/app/views/index.plates.php'; 39 | $data = array('foo' => 'bar'); 40 | $renderedTemplate = '

Hello Wold

'; 41 | 42 | $this->platesEngine->expects($this->once()) 43 | ->method('render') 44 | ->with('index', $data) 45 | ->willReturn($renderedTemplate); 46 | 47 | $this->assertEquals($renderedTemplate, $this->engine->get($template, $data)); 48 | } 49 | } --------------------------------------------------------------------------------