From 2477471ff5f40b0ebf9a3f6e46266a35c06b6bbf Mon Sep 17 00:00:00 2001 From: Andreas Ek Date: Fri, 22 Jan 2016 11:48:48 +0100 Subject: [PATCH] No stop at no template found Filters changed Data to template added as filter --- bladerunner.php | 2 +- composer.json | 2 +- deploy.php | 4 ---- readme.md | 11 ++++++++--- readme.txt | 2 +- src/Template.php | 27 ++++++++++----------------- 6 files changed, 21 insertions(+), 27 deletions(-) delete mode 100644 deploy.php diff --git a/bladerunner.php b/bladerunner.php index ddca1ac..eafad60 100644 --- a/bladerunner.php +++ b/bladerunner.php @@ -3,7 +3,7 @@ Plugin Name: Bladerunner Plugin URI: http://bladerunner.aekab.se Description: Laravel Blade template engine for WordPress -Version: 1.0.4 +Version: 1.0.5 Author: Andreas Ek Author URI: http://www.aekab.se/ License: MIT License diff --git a/composer.json b/composer.json index 65a6ebb..338ff53 100644 --- a/composer.json +++ b/composer.json @@ -1,7 +1,7 @@ { "name": "ekandreas/bladerunner", "type": "wordpress-plugin", - "version": "1.0.4", + "version": "1.0.5", "description": "WordPress Blade L5 template engine", "keywords": ["laravel", "blade", "wordpress"], "license": "MIT", diff --git a/deploy.php b/deploy.php deleted file mode 100644 index aa33557..0000000 --- a/deploy.php +++ /dev/null @@ -1,4 +0,0 @@ - 'that', + 'other' => 'perhaps', +]; +add_filter('bladerunner/templates/data', compact('data')); ``` Inside your view file you will be able to access the passed data like so: ``` -{{ $variableName }} +{{ $data['this'] }} +{{ $data['other'] }} ``` ## Hooks & Filters diff --git a/readme.txt b/readme.txt index ad61b5d..0005177 100644 --- a/readme.txt +++ b/readme.txt @@ -3,7 +3,7 @@ Contributors: ekandreas Tags: Blade,templates,development,laravel Requires at least: 4.4 Tested up to: 4.4 -Stable tag: 1.0.4 +Stable tag: 1.0.5 License: MIT WordPress plugin for Blade L5 templating diff --git a/src/Template.php b/src/Template.php index 5b76b7f..4ed9b94 100644 --- a/src/Template.php +++ b/src/Template.php @@ -15,23 +15,16 @@ class Template * * @var array */ - public static $data = array(); + public $data = []; /** * Constructor. */ public function __construct() { - add_filter('template_include', [$this, 'path'], 999); - add_action('template_redirect', [$this, 'init']); - } - - /** - * Adding {$type}_template to WP - */ - public function init() - { - $this->addTemplateFilters(); + add_filter('template_include', [$this, 'templateFilter'], 999); + add_action('template_redirect', [$this, 'addPageTemplateFilters']); + $this->data = apply_filters('bladerunner/templates/data', [] ); } /** @@ -43,7 +36,7 @@ public function init() * * @return string */ - public function path($template) + public function templateFilter($template) { $path = $template; @@ -51,13 +44,13 @@ public function path($template) return $path; } - $template = apply_filters('bladerunner/get_post_template', $template); + $template = apply_filters('bladerunner/template/post', $template); $views = get_stylesheet_directory(); $cache = self::cache(); if (!file_exists($cache)) { - throw new \Exception('Bladerunner: Cache folder does not exist.'); + trigger_error("Bladerunner: Cache folder {$cache} does not exist.", E_WARNING); return $template; } @@ -72,7 +65,7 @@ public function path($template) } if (!file_exists($template)) { - throw new \Exception("Bladerunner: Missing template file {$template}"); + trigger_error("Bladerunner: Missing template file {$template}", E_WARNING); return $template; } @@ -109,7 +102,7 @@ public static function cache() /** * Add template filters. */ - private function addTemplateFilters() + public function addPageTemplateFilters() { $types = [ 'index' => 'index.blade.php', @@ -131,7 +124,7 @@ private function addTemplateFilters() 'attachment' => 'attachment.blade.php', ]; - $types = apply_filters('bladerunner/template_types', $types); + $types = apply_filters('bladerunner/template/types', $types); if ($types) { foreach ($types as $key => $type) {