diff --git a/bladerunner.php b/bladerunner.php index 59b27c7..afe1719 100644 --- a/bladerunner.php +++ b/bladerunner.php @@ -3,7 +3,7 @@ Plugin Name: Bladerunner Plugin URI: https://github.com/ekandreas/bladerunner Description: Blade template engine for WordPress -Version: 0.5.7 +Version: 0.6 Author: Andreas Ek Author URI: http://www.aekab.se/ @@ -16,6 +16,9 @@ require_once __DIR__ . '/vendor/autoload.php'; } -require_once __DIR__ . '/src/model.php'; -require_once __DIR__ . '/src/controller.php'; +require_once __DIR__ . '/src/init.php'; +require_once __DIR__ . '/src/template.php'; require_once __DIR__ . '/src/blade.php'; + +new Bladerunner\Init(); +new Bladerunner\Template(); diff --git a/composer.json b/composer.json index 4aad5ef..8fab292 100644 --- a/composer.json +++ b/composer.json @@ -1,7 +1,7 @@ { "name": "ekandreas/bladerunner", "type": "wordpress-plugin", - "version": "0.5.7", + "version": "0.6", "description": "WordPress Blade L5 template engine", "keywords": ["laravel", "blade", "wordpress"], "license": "MIT", diff --git a/composer.lock b/composer.lock index 7785cb9..68df08c 100644 --- a/composer.lock +++ b/composer.lock @@ -4,8 +4,8 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "hash": "f3dae1061e201d724a1c041d3e6228aa", - "content-hash": "fd0f7823dac812ae7b5774f670e6e9e3", + "hash": "31503a6f9df76e4388054c846319ee5b", + "content-hash": "27c2df359d8521ef2a4dce5e11fd41c9", "packages": [ { "name": "doctrine/inflector", diff --git a/readme.md b/readme.md index b4bfd69..c3978fa 100644 --- a/readme.md +++ b/readme.md @@ -1,8 +1,6 @@ # Bladerunner WordPress plugin for Blade L5 templating -*** WORK IN PROGRESS *** - To install it to your Composer based WordPress installation: ``` @@ -26,6 +24,9 @@ Hello World Page rendered at {{ date('Y-m-d H:i:s') }} http://laravel.com/docs/master/blade +## Cache +* It's a really good idea to empty the .cache folder inside "uploads" when develop templates. Eg, create a "del" command inside your gulp-file. + ## Directories * Your cached views will always be stored in your wp upload folder, .cache. * Your views must be placed within your theme folder. diff --git a/src/controller.php b/src/controller.php deleted file mode 100644 index 5d6ed1b..0000000 --- a/src/controller.php +++ /dev/null @@ -1,40 +0,0 @@ -

Bladerunner cache error!

.cache -folder is missing in uploads. Please create the folder and make it writable!

"; - } - - static function not_writable() { - echo"

Bladerunner writable error!

.cache -folder not writable. Please make the folder writable for your web process!

"; - } - -} - -new Controller(); diff --git a/src/init.php b/src/init.php new file mode 100644 index 0000000..b5f9437 --- /dev/null +++ b/src/init.php @@ -0,0 +1,60 @@ +cache = Template::cache(); + add_action( 'admin_init', [ $this, 'check_writeable_upload' ] ); + } + + /** + * Check if the cache folder exists and is writable and assigns admin notice if not + * @return void + */ + static function check_writeable_upload() { + + if( !file_exists( $this->cache ) ) { + add_action( 'admin_notices', [ $this, 'notice_create_cache' ] ); + } + else { + + $is_writable = @file_put_contents( $this->cache . '/.folder_writable', "true" ); + if( !$is_writable ) { + add_action( 'admin_notices', [ $this, 'notice_writable_cache' ] ); + } + + } + + } + + /** + * Echo admin notice inside wp-admin if cache folder doesnt exist. + * @return void + */ + static function notice_create_cache() { + echo '
'; + echo '

Cache folder missing

'; + echo '

Bladerunner needs a .cache -folder in uploads. Please create the folder and make it writable!

'; + echo '

Eg, mkdir ' . $this->cache . '

'; + echo '
'; + } + + /** + * Echo admin notice inside wp-admin if cache folder not writable. + * @return void + */ + static function notice_writable_cache() { + echo '
'; + echo '

Cache not writable

'; + echo '

Bladerunner cache folder .cache in uploads not writable. Please make the folder writable for your web server!

'; + echo '

Eg, chmod -R 777 ' . $this->cache . '

'; + echo '
'; + } + +} diff --git a/src/model.php b/src/template.php similarity index 61% rename from src/model.php rename to src/template.php index 2bae557..e4fdb66 100644 --- a/src/model.php +++ b/src/template.php @@ -2,11 +2,35 @@ namespace Bladerunner; use Bladerunner\Blade; -class Model { - +/** + * Handles the template include for blade templates + */ +class Template { + + /** + * Saves the path in case of double object instance + * @var [type] + */ protected $path; - function getPath( $template ) { + /** + * [__construct description] + */ + function __construct() { + + add_action( 'template_include', [ $this, 'path' ], 999 ); + add_filter( 'index_template', function() { return 'index.blade.php'; } ); + //add_filter( 'page_template', [ $model, 'getPath' ] ); + //add_filter( 'bp_template_include', [ $model, 'getPath' ] ); + + } + + /** + * The hook for template_include to override blade templating + * @param [type] $template [description] + * @return [type] [description] + */ + function path( $template ) { if( $this->path ) return $this->path; @@ -18,7 +42,7 @@ function getPath( $template ) { $views = get_stylesheet_directory(); - $cache = Model::get_cache_dir(); + $cache = Template::cache(); if( !file_exists($cache) ) { return $template; } @@ -61,10 +85,14 @@ function getPath( $template ) { } - static function get_cache_dir() { + /** + * Gets the cache folder for Bladerunner + * @return [type] [description] + */ + static function cache() { $result = wp_upload_dir()['basedir']; $result .= '/.cache'; - return $result; + return apply_filters('bladerunner/cache', $result); } }