diff --git a/.editorconfig b/.editorconfig index 8fcbf50..e5c8d6c 100644 --- a/.editorconfig +++ b/.editorconfig @@ -13,5 +13,5 @@ insert_final_newline = true [*.php] indent_size = 4 -[templates/**.php] +[resources/views/**.php] indent_size = 2 diff --git a/CHANGELOG.md b/CHANGELOG.md index 07cf1b5..03d4857 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,5 @@ ### HEAD -* Rename `base.blade.php` to `app.blade.php` ([#1864](https://github.com/roots/sage/pull/1864)) +* Move `templates/` to `resources/views/`, rename `base.blade.php` to `app.blade.php`, ([#1864](https://github.com/roots/sage/pull/1864)) * Add option to configure build settings ([#1822](https://github.com/roots/sage/pull/1822)) * Add support for HTML injection ([#1817](https://github.com/roots/sage/pull/1817)) diff --git a/README.md b/README.md index e3e3c96..b6f8a1b 100644 --- a/README.md +++ b/README.md @@ -53,13 +53,6 @@ During theme installation you will have the options to: ```shell themes/your-theme-name/ # → Root of your Sage based theme -├── assets # → Front-end assets -│ ├── config.json # → Settings for compiled assets -│ ├── build/ # → Webpack and ESLint config -│ ├── fonts/ # → Theme fonts -│ ├── images/ # → Theme images -│ ├── scripts/ # → Theme JS -│ └── styles/ # → Theme stylesheets ├── composer.json # → Autoloading for `src/` files ├── composer.lock # → Composer lock file (never edit) ├── dist/ # → Built theme assets (never edit) @@ -75,9 +68,17 @@ themes/your-theme-name/ # → Root of your Sage based theme │ ├── helpers.php # → Helper functions │ └── setup.php # → Theme setup ├── style.css # → Theme meta information -├── templates/ # → Theme templates -│ ├── layouts/ # → Base templates -│ └── partials/ # → Partial templates +├── resources/ # → Theme assets and templates +├── ├── assets/ # → Front-end assets +│ │ ├── config.json # → Settings for compiled assets +│ │ ├── build/ # → Webpack and ESLint config +│ │ ├── fonts/ # → Theme fonts +│ │ ├── images/ # → Theme images +│ │ ├── scripts/ # → Theme JS +│ │ └── styles/ # → Theme stylesheets +│ └── views/ # → Theme templates +│ ├── layouts/ # → Base templates +│ └── partials/ # → Partial templates └── vendor/ # → Composer packages (never edit) ``` diff --git a/functions.php b/functions.php index 87ac658..07e0b40 100644 --- a/functions.php +++ b/functions.php @@ -60,10 +60,10 @@ array_map(function ($file) use ($sage_error) { /** * Here's what's happening with these hooks: * 1. WordPress initially detects theme in themes/sage - * 2. Upon activation, we tell WordPress that the theme is actually in themes/sage/templates + * 2. Upon activation, we tell WordPress that the theme is actually in themes/sage/resources/views * 3. When we call get_template_directory() or get_template_directory_uri(), we point it back to themes/sage * - * We do this so that the Template Hierarchy will look in themes/sage/templates for core WordPress themes + * We do this so that the Template Hierarchy will look in themes/sage/resources/views for core WordPress themes * But functions.php, style.css, and index.php are all still located in themes/sage * * This is not compatible with the WordPress Customizer theme preview prior to theme activation @@ -72,16 +72,16 @@ array_map(function ($file) use ($sage_error) { * get_stylesheet_directory() -> /srv/www/example.com/current/web/app/themes/sage * locate_template() * ├── STYLESHEETPATH -> /srv/www/example.com/current/web/app/themes/sage - * └── TEMPLATEPATH -> /srv/www/example.com/current/web/app/themes/sage/templates + * └── TEMPLATEPATH -> /srv/www/example.com/current/web/app/themes/sage/resources/views */ if (is_customize_preview() && isset($_GET['theme'])) { $sage_error(__('Theme must be activated prior to using the customizer.', 'sage')); } add_filter('template', function ($stylesheet) { - return dirname($stylesheet); + return dirname(dirname($stylesheet)); }); -if (basename($stylesheet = get_option('template')) !== 'templates') { - update_option('template', "{$stylesheet}/templates"); +if (basename($stylesheet = get_option('template')) !== 'resources/views') { + update_option('template', "{$stylesheet}/resources/views"); wp_redirect($_SERVER['REQUEST_URI']); exit(); } diff --git a/phpcs.xml b/phpcs.xml index 4b4b390..df22395 100644 --- a/phpcs.xml +++ b/phpcs.xml @@ -6,7 +6,7 @@ functions.php index.php src - templates + resources/views @@ -17,55 +17,55 @@ - - + + - templates + resources/views - templates + resources/views - templates + resources/views - templates + resources/views - templates + resources/views - templates + resources/views - templates + resources/views - + - templates + resources/views - templates - + resources/views + - templates + resources/views diff --git a/templates/404.blade.php b/resources/views/404.blade.php similarity index 100% rename from templates/404.blade.php rename to resources/views/404.blade.php diff --git a/templates/index.blade.php b/resources/views/index.blade.php similarity index 100% rename from templates/index.blade.php rename to resources/views/index.blade.php diff --git a/templates/layouts/app.blade.php b/resources/views/layouts/app.blade.php similarity index 100% rename from templates/layouts/app.blade.php rename to resources/views/layouts/app.blade.php diff --git a/templates/page.blade.php b/resources/views/page.blade.php similarity index 100% rename from templates/page.blade.php rename to resources/views/page.blade.php diff --git a/templates/partials/comments.blade.php b/resources/views/partials/comments.blade.php similarity index 100% rename from templates/partials/comments.blade.php rename to resources/views/partials/comments.blade.php diff --git a/templates/partials/content-page.blade.php b/resources/views/partials/content-page.blade.php similarity index 100% rename from templates/partials/content-page.blade.php rename to resources/views/partials/content-page.blade.php diff --git a/templates/partials/content-search.blade.php b/resources/views/partials/content-search.blade.php similarity index 100% rename from templates/partials/content-search.blade.php rename to resources/views/partials/content-search.blade.php diff --git a/templates/partials/content-single.blade.php b/resources/views/partials/content-single.blade.php similarity index 83% rename from templates/partials/content-single.blade.php rename to resources/views/partials/content-single.blade.php index 30a2f9c..653804b 100644 --- a/templates/partials/content-single.blade.php +++ b/resources/views/partials/content-single.blade.php @@ -9,5 +9,5 @@ - @php(comments_template('/templates/partials/comments.blade.php')) + @php(comments_template('/resources/views/partials/comments.blade.php')) diff --git a/templates/partials/content.blade.php b/resources/views/partials/content.blade.php similarity index 100% rename from templates/partials/content.blade.php rename to resources/views/partials/content.blade.php diff --git a/templates/partials/entry-meta.blade.php b/resources/views/partials/entry-meta.blade.php similarity index 100% rename from templates/partials/entry-meta.blade.php rename to resources/views/partials/entry-meta.blade.php diff --git a/templates/partials/footer.blade.php b/resources/views/partials/footer.blade.php similarity index 100% rename from templates/partials/footer.blade.php rename to resources/views/partials/footer.blade.php diff --git a/templates/partials/head.blade.php b/resources/views/partials/head.blade.php similarity index 100% rename from templates/partials/head.blade.php rename to resources/views/partials/head.blade.php diff --git a/templates/partials/header.blade.php b/resources/views/partials/header.blade.php similarity index 100% rename from templates/partials/header.blade.php rename to resources/views/partials/header.blade.php diff --git a/templates/partials/page-header.blade.php b/resources/views/partials/page-header.blade.php similarity index 100% rename from templates/partials/page-header.blade.php rename to resources/views/partials/page-header.blade.php diff --git a/templates/partials/sidebar.blade.php b/resources/views/partials/sidebar.blade.php similarity index 100% rename from templates/partials/sidebar.blade.php rename to resources/views/partials/sidebar.blade.php diff --git a/templates/search.blade.php b/resources/views/search.blade.php similarity index 100% rename from templates/search.blade.php rename to resources/views/search.blade.php diff --git a/templates/single.blade.php b/resources/views/single.blade.php similarity index 100% rename from templates/single.blade.php rename to resources/views/single.blade.php diff --git a/templates/template-custom.blade.php b/resources/views/template-custom.blade.php similarity index 100% rename from templates/template-custom.blade.php rename to resources/views/template-custom.blade.php diff --git a/src/filters.php b/src/filters.php index da4bbe8..3dfc20a 100644 --- a/src/filters.php +++ b/src/filters.php @@ -35,7 +35,7 @@ array_map(function ($type) { add_filter("{$type}_template_hierarchy", function ($templates) { return call_user_func_array('array_merge', array_map(function ($template) { $transforms = [ - '%^/?(templates)?/?%' => config('sage.disable_option_hack') ? 'templates/' : '', + '%^/?(resources/views)?/?%' => config('sage.disable_option_hack') ? 'resources/views/' : '', '%(\.blade)?(\.php)?$%' => '' ]; $normalizedTemplate = preg_replace(array_keys($transforms), array_values($transforms), $template); @@ -44,7 +44,7 @@ array_map(function ($type) { }); }, [ 'index', '404', 'archive', 'author', 'category', 'tag', 'taxonomy', 'date', 'home', - 'frontpage', 'page', 'paged', 'search', 'single', 'singular', 'attachment' + 'front_page', 'page', 'paged', 'search', 'single', 'singular', 'attachment' ]); /** diff --git a/src/setup.php b/src/setup.php index 27a071c..2a93df2 100644 --- a/src/setup.php +++ b/src/setup.php @@ -111,10 +111,12 @@ add_action('after_setup_theme', function () { 'uri.stylesheet' => get_stylesheet_directory_uri(), 'uri.template' => get_template_directory_uri(), ]; - $viewPaths = collect(preg_replace('%[\/]?(templates)?[\/.]*?$%', '', [STYLESHEETPATH, TEMPLATEPATH])) + $viewPaths = collect(preg_replace('%[\/]?(resources/views)?[\/.]*?$%', '', [STYLESHEETPATH, TEMPLATEPATH])) ->flatMap(function ($path) { - return ["{$path}/templates", $path]; + return ["{$path}/resources/views", $path]; })->unique()->toArray(); + + // die(var_dump($viewPaths)); config([ 'assets.manifest' => "{$paths['dir.stylesheet']}/dist/assets.json", 'assets.uri' => "{$paths['uri.stylesheet']}/dist",