├── .gitignore ├── LICENSE ├── composer.json ├── readme.md └── src └── Blade.php /.gitignore: -------------------------------------------------------------------------------- 1 | /vendor 2 | composer.phar 3 | composer.lock 4 | .DS_Store 5 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) Spatie 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "spatie/laravel-blade", 3 | "description": "Use the simple and yet powerful Laravel Blade templating engine as a standalone component.", 4 | "homepage": "https://github.com/spatie/laravel-blade", 5 | "keywords": ["laravel", "blade"], 6 | "license": "MIT", 7 | "authors": [ 8 | { 9 | "name": "Freek Van der Herten", 10 | "email": "freek@spatie.be" 11 | } 12 | ], 13 | "require": { 14 | "illuminate/view": "4.1.*" 15 | }, 16 | "autoload": { 17 | "psr-4": { 18 | "Spatie\\Blade\\": "src" 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | **THIS PACKAGE IS UNMAINTAINED** 2 | 3 | # Use Laravel's blade outside Laravel 4 | 5 | This package is a slightly modified version of [50onred/laravel-blade](https://github.com/50onred/laravel-blade). 6 | 7 | [![Latest Version on Packagist](https://img.shields.io/packagist/v/spatie/laravel-blade.svg?style=flat-square)](https://packagist.org/packages/spatie/laravel-blade) 8 | [![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](LICENSE.md) 9 | 10 | ### Installation 11 | 12 | ```bash 13 | composer require spatie/laravel-blade 14 | ``` 15 | 16 | ## Postcardware 17 | 18 | You're free to use this package (it's [MIT-licensed](LICENSE.md)), but if it makes it to your production environment you are required to send us a postcard from your hometown, mentioning which of our package(s) you are using. 19 | 20 | Our address is: Spatie, Samberstraat 69D, 2060 Antwerp, Belgium. 21 | 22 | The best postcards will get published on the open source page on our website. 23 | 24 | ### Usage 25 | 26 | ```php 27 | view()->make('hello'); 50 | ``` 51 | 52 | You can use all blade features as described in the Laravel 4 documentation: 53 | http://laravel.com/docs/templates#blade-templating 54 | -------------------------------------------------------------------------------- /src/Blade.php: -------------------------------------------------------------------------------- 1 | container = new Container; 47 | 48 | $this->viewPaths = (array) $viewPaths; 49 | 50 | $this->cachePath = $cachePath; 51 | 52 | $this->registerFilesystem(); 53 | 54 | $this->registerEvents(); 55 | 56 | $this->registerEngineResolver(); 57 | 58 | $this->registerViewFinder(); 59 | 60 | $this->instance = $this->registerEnvironment(); 61 | } 62 | 63 | public function view() 64 | { 65 | return $this->instance; 66 | } 67 | 68 | public function registerFilesystem() 69 | { 70 | $this->container->bindShared('files', function(){ 71 | return new Filesystem; 72 | }); 73 | } 74 | public function registerEvents() 75 | { 76 | $this->container->bindShared('events', function(){ 77 | return new Dispatcher; 78 | }); 79 | } 80 | /** 81 | * Register the engine resolver instance. 82 | * 83 | * @return void 84 | */ 85 | public function registerEngineResolver() 86 | { 87 | $me = $this; 88 | 89 | $this->container->bindShared('view.engine.resolver', function($app) use ($me) 90 | { 91 | $resolver = new EngineResolver; 92 | 93 | // Next we will register the various engines with the resolver so that the 94 | // environment can resolve the engines it needs for various views based 95 | // on the extension of view files. We call a method for each engines. 96 | foreach (array('php', 'blade') as $engine) 97 | { 98 | $me->{'register'.ucfirst($engine).'Engine'}($resolver); 99 | } 100 | 101 | return $resolver; 102 | }); 103 | } 104 | 105 | /** 106 | * Register the PHP engine implementation. 107 | * 108 | * @param \Illuminate\View\Engines\EngineResolver $resolver 109 | * @return void 110 | */ 111 | public function registerPhpEngine($resolver) 112 | { 113 | $resolver->register('php', function() { return new PhpEngine; }); 114 | } 115 | 116 | /** 117 | * Register the Blade engine implementation. 118 | * 119 | * @param \Illuminate\View\Engines\EngineResolver $resolver 120 | * @return void 121 | */ 122 | public function registerBladeEngine($resolver) 123 | { 124 | $me = $this; 125 | $app = $this->container; 126 | 127 | // The Compiler engine requires an instance of the CompilerInterface, which in 128 | // this case will be the Blade compiler, so we'll first create the compiler 129 | // instance to pass into the engine so it can compile the views properly. 130 | $this->container->bindShared('blade.compiler', function($app) use ($me) 131 | { 132 | $cache = $me->cachePath; 133 | 134 | return new BladeCompiler($app['files'], $cache); 135 | }); 136 | 137 | $resolver->register('blade', function() use ($app) 138 | { 139 | return new CompilerEngine($app['blade.compiler'], $app['files']); 140 | }); 141 | } 142 | 143 | /** 144 | * Register the view finder implementation. 145 | * 146 | * @return void 147 | */ 148 | public function registerViewFinder() 149 | { 150 | $me = $this; 151 | $this->container->bindShared('view.finder', function($app) use ($me) 152 | { 153 | $paths = $me->viewPaths; 154 | 155 | return new FileViewFinder($app['files'], $paths); 156 | }); 157 | } 158 | 159 | /** 160 | * Register the view environment. 161 | * 162 | * @return void 163 | */ 164 | public function registerEnvironment() 165 | { 166 | // Next we need to grab the engine resolver instance that will be used by the 167 | // environment. The resolver will be used by an environment to get each of 168 | // the various engine implementations such as plain PHP or Blade engine. 169 | $resolver = $this->container['view.engine.resolver']; 170 | 171 | $finder = $this->container['view.finder']; 172 | 173 | $env = new Environment($resolver, $finder, $this->container['events']); 174 | 175 | // We will also set the container instance on this view environment since the 176 | // view composers may be classes registered in the container, which allows 177 | // for great testable, flexible composers for the application developer. 178 | $env->setContainer($this->container); 179 | 180 | return $env; 181 | } 182 | 183 | } 184 | --------------------------------------------------------------------------------