Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
9103f99
Merge branch 'release/1.7-beta'
ekandreas Aug 18, 2017
ba0fc22
Merge branch 'release/1.7-beta.2'
ekandreas Aug 18, 2017
c94a283
Apply fixes from StyleCI
Aug 18, 2017
5cd821d
Merge pull request #55 from ekandreas/analysis-XlwjeQ
Aug 18, 2017
8b1b9de
Merge branch 'release/1.7-beta.3'
ekandreas Aug 18, 2017
accde46
Merge branch 'release/1.7'
ekandreas Aug 22, 2017
a6c9708
Update composer.json
vinkla Aug 30, 2017
d39b5e6
Merge commit 'a6c9708272c4a8e799440d5466c45e8a56ed52c7'
ekandreas Aug 31, 2017
4d07da6
Switching dev to master branch
ekandreas Aug 31, 2017
eb3cc61
Prepp dev 1.7.2
ekandreas Aug 31, 2017
fe2f6c8
Examine extensions and if-statements with L5
ekandreas Aug 31, 2017
3a3290b
Apply fixes from StyleCI
Aug 31, 2017
5e7ad10
Merge pull request #61 from ekandreas/analysis-XW1L9y
Aug 31, 2017
dc0e4de
Paths in controller
ekandreas Oct 17, 2017
1376ba3
Version update
ekandreas Oct 17, 2017
398d6d3
Add version to composer.json to trigger packagist
ekandreas Oct 17, 2017
1cd36bf
No version to composer file, using branch-alias
ekandreas Oct 17, 2017
e1584e0
Dev on branch alias
ekandreas Oct 17, 2017
7acce1c
Blade path adjusted
ekandreas Oct 17, 2017
1ca3311
Update readme with some code tags
frozzare Oct 17, 2017
87b09c8
Template Path optimizations
ekandreas Oct 17, 2017
2f5492c
Merge branch 'master' of github.com:ekandreas/bladerunner
ekandreas Oct 17, 2017
d82cf85
Prepp for the next release in time after 1.7.4
ekandreas Oct 27, 2017
1807740
Make `bladepath` example work in strict php
fiskhandlarn Oct 30, 2017
f5af0e5
Merge pull request #63 from fiskhandlarn/patch-1
ekandreas Oct 30, 2017
d63e0b6
Old filters for cache create and place restored
ekandreas Oct 30, 2017
c1e3fbc
Merge commit 'f5af0e506b1619808aa473290c997c07fb4656cc'
ekandreas Oct 30, 2017
84aec83
Removed history from readme
ekandreas Oct 30, 2017
3721468
Removed old docs from readme, not valid
ekandreas Oct 30, 2017
3bcedb9
Add working example for bladerunner/cache/make
fiskhandlarn Oct 31, 2017
4952198
Merge pull request #66 from fiskhandlarn/patch-1
ekandreas Nov 7, 2017
ebd2c08
composer adjustments for latest illuminate components
ekandreas Dec 20, 2017
06cad13
add filter to disable cache and force view compilation
tomasvanrijsse Jun 19, 2019
ea3aa8e
remove old cache unlink function
tomasvanrijsse Jun 19, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
composer.lock
phpunit.xml
vendor
.idea
2 changes: 1 addition & 1 deletion bladerunner.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Plugin Name: Bladerunner
Plugin URI: http://bladerunner.elseif.se
Description: Laravel Blade template engine for WordPress
Version: 1.7.1-dev
Version: 1.7.5
Author: Andreas Ek
Author URI: https://www.elseif.se/
License: MIT License
Expand Down
31 changes: 17 additions & 14 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
"name": "ekandreas/bladerunner",
"type": "wordpress-plugin",
"version": "1.7.1-dev",
"description": "WordPress Blade L5 template engine",
"keywords": ["laravel", "blade", "wordpress"],
"license": "MIT",
Expand All @@ -12,26 +11,30 @@
}
],
"require": {
"php": ">=5.6",
"illuminate/config": "5.*",
"illuminate/view": "5.*",
"symfony/yaml": "3.*",
"brain/hierarchy":"2.*"
"php": "^5.6 || ^7.0",
"illuminate/config": "^5",
"illuminate/view": "^5",
"symfony/yaml": "^3",
"brain/hierarchy": "^2"
},
"require-dev": {
"frozzare/wp-test-suite": "*"
},
"autoload": {
"psr-4": {
"Bladerunner\\Tests\\": "tests/",
"Bladerunner\\": "src/"
}
},
"prefer-stable": true,
"minimum-stability": "dev",
"require-dev": {
"frozzare/wp-test-suite": "*"
"autoload-dev": {
"psr-4": {
"Bladerunner\\Tests\\": "tests/"
}
},
"extra": {
"branch-alias": {
"dev-develop": "1.7.1-dev"
"dev-master": "1.7.5-dev"
}
}
}
},
"minimum-stability": "dev",
"prefer-stable": true
}
29 changes: 23 additions & 6 deletions globals/filters.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,13 @@
];
$normalizedTemplate = preg_replace(array_keys($transforms), array_values($transforms), $template);

$controllerPaths = collect([
apply_filters('bladerunner/controller/paths', []),
get_stylesheet_directory() . '/controllers',
])->unique()->toArray();
$paths = apply_filters('bladerunner/controller/paths', []);
if (!is_array($paths)) {
$paths = [$paths];
}
$paths[] = get_stylesheet_directory() . '/controllers';

$controllerPaths = collect($paths)->unique()->toArray();

foreach ($controllerPaths as $path) {
if (!is_string($path)) {
Expand All @@ -39,8 +42,22 @@
return $result;
});
}, [
'index', '404', 'archive', 'author', 'category', 'tag', 'taxonomy', 'date', 'home',
'frontpage', 'page', 'paged', 'search', 'single', 'singular', 'attachment'
'index',
'404',
'archive',
'author',
'category',
'tag',
'taxonomy',
'date',
'home',
'frontpage',
'page',
'paged',
'search',
'single',
'singular',
'attachment'
]);

add_filter('template_include', function ($template) {
Expand Down
26 changes: 6 additions & 20 deletions globals/setup.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,29 +17,22 @@
'uri.template' => get_template_directory_uri(),
];

$viewPaths = collect(preg_replace('%[\/]?(templates)?[\/.]*?$%', '', [
apply_filters('bladerunner/template/bladepath', $paths['dir.stylesheet']),
$paths['dir.stylesheet'] . DIRECTORY_SEPARATOR . 'views',
STYLESHEETPATH,
TEMPLATEPATH,
]))
->flatMap(function ($path) {
return ["{$path}/templates", $path];
})->unique()->toArray();

\Bladerunner\Config::repo([
'view.compiled' => "{$paths['dir.upload']}/.cache",
'view.paths' => $viewPaths,
'view.compiled' => apply_filters('bladerunner/cache/path', "{$paths['dir.upload']}/.cache"),
'view.paths' => \Bladerunner\Config::viewPaths(),
] + $paths);

/**
* Add Blade to Bladerunner container
*/
Bladerunner\Container::current()->singleton('bladerunner.blade', function (ContainerContract $app) {
$cachePath = Bladerunner\Config::repo('view.compiled');
if (!file_exists($cachePath)) {

$makePath = apply_filters('bladerunner/cache/make', true);
if ($makePath && !file_exists($cachePath)) {
wp_mkdir_p($cachePath);
}

(new \Bladerunner\BladeProvider($app))->register();
return new \Bladerunner\Blade($app['view'], $app);
});
Expand All @@ -48,14 +41,7 @@
return '<?php (new \Bladerunner\ControllerDebug(get_defined_vars())); ?>';
});

if (defined('WP_DEBUG') && WP_DEBUG) {
array_map('unlink',
glob(\Bladerunner\Config::repo('view.compiled') . '/*'));
}


$extensions = apply_filters('bladerunner/extend', []);
var_dump($extensions);
if ($extensions && is_array($extensions)) {
foreach ($extensions as $extension) {
if (is_callable($extension)) {
Expand Down
123 changes: 28 additions & 95 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ WordPress plugin for Laravel Blade templating.
To install it to your Composer based WordPress installation:

```
composer require ekandreas/bladerunner:*
composer require ekandreas/bladerunner
```
Activate the plugin inside WordPress and templates with *.blade.php are inspected and active.
Your theme still needs an index.php due to WordPress basic functionality. When removed the theme is known as broken.
Expand All @@ -23,14 +23,14 @@ Releases to this plugin is listed last in this readme.

## Hello World
1. Install the library with composer
2. Make sure the cache-folder is writeable in uploads, eg ../wp-content/uploads/.cache
2. Make sure the cache-folder is writeable in uploads, eg `../wp-content/uploads/.cache`
3. Activate the plugin
4. Create a view, eg:
```twig
<!-- view file: views/pages/index.blade.php -->
Hello World Page rendered at {{ date('Y-m-d H:i:s') }}
```
5. In your index.php, add a global call for the view created, eg:
5. In your `index.php`, add a global call for the view created, eg:
```php
<?php
bladerunner('views.pages.index')
Expand All @@ -39,30 +39,30 @@ Hello World Page rendered at {{ date('Y-m-d H:i:s') }}
[https://laravel.com/docs/5.2/blade](https://laravel.com/docs/5.2/blade)

## Cache
* If WP_DEBUG is set and true then templates always will be rendered and updated.
* View files (cache) is invalidated at save_post.
* (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.)
* If `WP_DEBUG` is set and true then templates always will be rendered and updated.
* View files (cache) is invalidated at `save_post`
* (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 cached views will always be stored in your wp upload folder, `.cache`
* Your views must be placed within your theme folder.
* Your views must have .blade.php extension.
* Your views must have `.blade.php` extension.

## Template helper
There is a template helper function named "bladerunner", defined globally to use in standard WordPress templates.
There is a template helper function named `bladerunner`, defined globally to use in standard WordPress templates.

Example:
You want to create a 404-template and don't want to use the .blade.php extension to the template file.
You want to create a 404-template and don't want to use the `.blade.php` extension to the template file.

* Create a 404.php in the theme root.
* Add the following code to the template:
```php
<?php
bladerunner('views.pages.404');
```
* In the folder "views/pages", create a blade template "404.blade.php".
* In the folder `views/pages`, create a blade template `404.blade.php`

You can pass any data with the global "bladerunner" function like so,
You can pass any data with the global `bladerunner` function like so,
```php
<?php
bladerunner('views.pages.404', ['module'=>$module]);
Expand All @@ -88,7 +88,7 @@ Extend the Controller Class, it is recommended that the class name matches the f
Create methods within the Controller Class:
* Use public function to expose the returned values to the Blade views/s.
* Use public static function to use the function within your Blade view/s.
* Use protected function for internal controller methods as only public methods are exposed to the view. You can run them within __construct.
* Use protected function for internal controller methods as only public methods are exposed to the view. You can run them within `__construct`

### Controller example:

Expand Down Expand Up @@ -143,21 +143,28 @@ add_filter('bladerunner/cache/path', function() {
});
```

Permission settings to cache folder, default 777
If you don't want Bladerunner to create the cache folder:
```php
add_filter('bladerunner/cache/permission', function() {
return 644;
add_filter('bladerunner/cache/make', function() {
return false;
});
```
If you don't want Bladerunner to check for permissions form cache folder then set the return to null, eg:

If you don't want Blade to use cached view files:
```php
add_filter('bladerunner/cache/permission', '__return_null');
add_filter('bladerunner/cache/disable', function() {
return true;
});
```

If you wan't to customize the base paths where you have your views stored, use:
```php
add_filter('bladerunner/template/bladepath', function ($paths) {
$paths[] = PLUGIN_DIR . '/my-fancy-plugin/views';
return $path;
add_filter('bladerunner/template/bladepath', function ($paths) {
if (!is_array($paths)) {
$paths = [$paths];
}
$paths[] = ABSPATH . '../../resources/views';
return $paths;
});
```
If you wan't to customize the controller paths where you have your controllers stored, use:
Expand All @@ -168,59 +175,8 @@ add_filter('bladerunner/controller/paths', function ($paths) {
});
```

#### Custom extensions
If you are comfortable with regular expressions and want to add your own extensions to your templates use the filter ``bladerunner/extend``.
Note! It takes one *array* as parameter and requires two keys; "pattern" and "replace".

```php
$extensions[] = [
'pattern' => '...',
'replace' => '...',
];
```

Use the filter as possible way to add your own custom extensions.

In this example we want to add ``@mysyntax`` as a custom extension.
```php
/*
* Add custom extension @mysyntax to Bladerunner
*/
add_filter('bladerunner/extend', function($extensions) {
$extensions[] = [
'pattern' => '/(\s*)@mysyntax(\s*)/',
'replace' => '$1<?php echo "MYSYNTAX COMPILED!"; ?>$2',
];
return $extensions;
});
```
Then use your new syntax inside a WordPress blade template like so:
```php
@mysyntax
```

We will soon add more WordPress extenstions to the Bladerunner engine. Please give us your great examples to implement!

#### Template Data Filter
A simple way to pass data to a given view before it's loaded.

Set the filter ``bladerunner/templates/data/{view}`` before running a template to pass custom data to the template, eg:
```php
$data = [
'this' => 'that',
'other' => 'perhaps',
];
add_filter('bladerunner/templates/data/single', $data);
```

Inside your "single.blade.php" / view file you will be able to access the passed data like so:
```php
{{ $data['this'] }}
{{ $data['other'] }}
```

Default value for data is an empty array.

## Links
* [Bladerunner site with documentation and distro](http://bladerunner.aekab.se)
* [Docs Laravel Blade v5.2](https://laravel.com/docs/5.2/blade)
Expand All @@ -245,26 +201,3 @@ Using *Testrunner* (required-dev package) and Docker the test should be exexuted
```bash
vendor/bin/dep testrunner
```

## Releases

### 1.7
Controller concept included, read more about it at [https://bladerunner.elseif.se/controllers](https://bladerunner.elseif.se/controllers)

### Release 1.6.1 and 1.6.2
Just to update Laravel Blade engine upgrades

### Release 1.6
Laravel 5.4 with Components and Slots!
This is a completely rewrite, perhaps v2? Extracted from Roots Sage.
Some breaking changes:
* Laravel Config and View v5.4, these are in dev mode right now.
* Global function view over old global bladerunner for no echo as default.
* No template filters. You need to use "view" or "bladerunner" global functions in your ordinary WordPress templates.
* No WP admin pages, this is a dev tool :-)

### Release 1.5
Now only supports PHP5.6 and greater.
Laravel 5.3 is used as blade base.


2 changes: 1 addition & 1 deletion readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Contributors: ekandreas
Tags: Blade,templates,development,laravel
Requires at least: 4.4
Tested up to: 4.8.1
Stable tag: 1.7.1-dev
Stable tag: 1.7.5
License: MIT

WordPress plugin for Blade L5 templating
Expand Down
17 changes: 17 additions & 0 deletions src/BladeCompiler.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

namespace Bladerunner;

class BladeCompiler extends \Illuminate\View\Compilers\BladeCompiler
{
public function isExpired($path)
{
$forceCompile = apply_filters('bladerunner\cache\disable', WP_DEBUG, $path);

if ($forceCompile) {
return true;
}

return parent::isExpired($path);
}
}
Loading