templates/ -> resources/views/

This commit is contained in:
Ben Word
2017-04-03 18:26:26 -06:00
parent 0fab46fe14
commit 700a556c02
25 changed files with 41 additions and 38 deletions

View File

@@ -13,5 +13,5 @@ insert_final_newline = true
[*.php]
indent_size = 4
[templates/**.php]
[resources/views/**.php]
indent_size = 2

View File

@@ -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))

View File

@@ -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)
```

View File

@@ -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();
}

View File

@@ -6,7 +6,7 @@
<file>functions.php</file>
<file>index.php</file>
<file>src</file>
<file>templates</file>
<file>resources/views</file>
<!-- Show colors in console -->
<arg value="-colors"/>
@@ -17,55 +17,55 @@
<!-- Use PSR-2 as a base -->
<rule ref="PSR2"/>
<!-- Exclusions below are for templates/ folder -->
<!-- Exclusions below are for resources/views/ folder -->
<!-- Allow php files without any PHP in them -->
<rule ref="Internal.NoCodeFound">
<exclude-pattern>templates</exclude-pattern>
<exclude-pattern>resources/views</exclude-pattern>
</rule>
<!-- Allow braces on same line for named functions -->
<rule ref="Squiz.Functions.MultiLineFunctionDeclaration.BraceOnSameLine">
<exclude-pattern>templates</exclude-pattern>
<exclude-pattern>resources/views</exclude-pattern>
</rule>
<!-- Allow closing braces to be on the same line -->
<rule ref="Squiz.WhiteSpace.ScopeClosingBrace">
<exclude-pattern>templates</exclude-pattern>
<exclude-pattern>resources/views</exclude-pattern>
</rule>
<!-- Disable newline after opening brace -->
<rule ref="Squiz.ControlStructures.ControlSignature.NewlineAfterOpenBrace">
<exclude-pattern>templates</exclude-pattern>
<exclude-pattern>resources/views</exclude-pattern>
</rule>
<!-- Allow multiple PHP statements in the same line -->
<rule ref="Generic.Formatting.DisallowMultipleStatements.SameLine">
<exclude-pattern>templates</exclude-pattern>
<exclude-pattern>resources/views</exclude-pattern>
</rule>
<!-- Disable PSR-2 indentation rules that are buggy with 2 spaces -->
<rule ref="PSR2.ControlStructures.SwitchDeclaration.BreakIndent">
<exclude-pattern>templates</exclude-pattern>
<exclude-pattern>resources/views</exclude-pattern>
</rule>
<!-- Don't require a blank line after the last `use` -->
<rule ref="PSR2.Namespaces.UseDeclaration.SpaceAfterLastUse">
<exclude-pattern>templates</exclude-pattern>
<exclude-pattern>resources/views</exclude-pattern>
</rule>
<!-- Allow long lines -->
<rule ref="Generic.Files.LineLength.TooLong">
<exclude-pattern>templates</exclude-pattern>
<exclude-pattern>resources/views</exclude-pattern>
</rule>
<!-- Ignore indentation rules -->
<rule ref="Generic.WhiteSpace.ScopeIndent">
<exclude-pattern>templates</exclude-pattern>
</rule>
<exclude-pattern>resources/views</exclude-pattern>
</rule>
<!-- Allow PHP closing tags -->
<rule ref="PSR2.Files.ClosingTag.NotAllowed">
<exclude-pattern>templates</exclude-pattern>
<exclude-pattern>resources/views</exclude-pattern>
</rule>
</ruleset>

View File

@@ -9,5 +9,5 @@
<footer>
{!! wp_link_pages(['echo' => 0, 'before' => '<nav class="page-nav"><p>' . __('Pages:', 'sage'), 'after' => '</p></nav>']) !!}
</footer>
@php(comments_template('/templates/partials/comments.blade.php'))
@php(comments_template('/resources/views/partials/comments.blade.php'))
</article>

View File

@@ -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'
]);
/**

View File

@@ -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",