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

@@ -3,36 +3,9 @@
namespace App;
use Roots\Sage\Assets\JsonManifest;
use Roots\Sage\Template\Blade;
use Roots\Sage\Template\BladeProvider;
/**
* Add JsonManifest to Sage container
*/
sage()->singleton('sage.assets', function () {
return new JsonManifest(
get_stylesheet_directory().'/dist/assets.json',
get_stylesheet_directory_uri().'/dist'
);
});
/**
* Add Blade to Sage container
*/
sage()->singleton('sage.blade', function () {
$cachePath = wp_upload_dir()['basedir'].'/cache/compiled';
if (!file_exists($cachePath)) {
wp_mkdir_p($cachePath);
}
return new BladeProvider(TEMPLATEPATH, $cachePath, sage());
});
/**
* Create @asset() Blade directive
*/
sage('blade')->compiler()->directive('asset', function ($asset) {
return '<?= App\\asset_path(\''.trim($asset, '\'"').'\'); ?>';
});
/**
* Theme assets
*/
@@ -86,7 +59,7 @@ add_action('after_setup_theme', function () {
* @see assets/styles/layouts/_tinymce.scss
*/
add_editor_style(asset_path('styles/main.css'));
});
}, 20);
/**
* Register sidebars
@@ -107,3 +80,49 @@ add_action('widgets_init', function () {
'id' => 'sidebar-footer'
] + $config);
});
/**
* Setup Sage options
*/
add_action('after_setup_theme', function () {
/**
* Sage config
*/
sage()->bindIf('config', function () {
return [
'view.paths' => [TEMPLATEPATH, STYLESHEETPATH],
'view.compiled' => wp_upload_dir()['basedir'].'/cache/compiled',
'view.namespaces' => ['App' => WP_CONTENT_DIR],
'assets.manifest' => get_stylesheet_directory().'/dist/assets.json',
'assets.uri' => get_stylesheet_directory_uri().'/dist'
];
});
/**
* Add JsonManifest to Sage container
*/
sage()->singleton('sage.assets', function ($app) {
$config = $app['config'];
return new JsonManifest($config['assets.manifest'], $config['assets.uri']);
});
/**
* Add Blade to Sage container
*/
sage()->singleton('sage.blade', function ($app) {
$config = $app['config'];
$cachePath = $config['view.compiled'];
if (!file_exists($cachePath)) {
wp_mkdir_p($cachePath);
}
(new BladeProvider($app))->register();
return new Blade($app['view'], $app);
});
/**
* Create @asset() Blade directive
*/
sage('blade')->compiler()->directive('asset', function ($asset) {
return '<?= App\\asset_path(\''.trim($asset, '\'"').'\'); ?>';
});
});