Refactor Blade implementation (again), closes #1769 (#1777)

* Squash bugs, reorganize, etc.
* Use `get_body_class()` to apply filters on template data
* Use `PHP_INT_MAX` as priority for `template_include` filter
This commit is contained in:
QWp6t
2016-12-18 15:50:08 -08:00
committed by GitHub
parent 258d454bec
commit a3141c569e
8 changed files with 267 additions and 182 deletions

View File

@@ -34,7 +34,7 @@ add_filter('excerpt_more', function () {
array_map(function ($type) {
add_filter("{$type}_template_hierarchy", function ($templates) {
return call_user_func_array('array_merge', array_map(function ($template) {
$normalizedTemplate = str_replace('.', '/', sage('blade')->normalizeViewPath($template));
$normalizedTemplate = preg_replace('%(\.blade)?(\.php)?$%', '', $template);
return ["{$normalizedTemplate}.blade.php", "{$normalizedTemplate}.php"];
}, $templates));
});
@@ -47,11 +47,14 @@ array_map(function ($type) {
* Render page using Blade
*/
add_filter('template_include', function ($template) {
echo template($template, apply_filters('sage/template_data', []));
$data = array_reduce(get_body_class(), function ($data, $class) {
return apply_filters("sage/template/{$class}/data", $data);
}, []);
echo template($template, $data);
// Return a blank file to make WordPress happy
return get_template_directory() . '/index.php';
}, 1000);
}, PHP_INT_MAX);
/**
* Tell WordPress how to find the compiled path of comments.blade.php