Merge pull request #1864 from roots/rename-base-to-app
Move assets/ to resources/assets/, move templates/ to resources/views/
This commit is contained in:
@@ -13,5 +13,5 @@ insert_final_newline = true
|
||||
[*.php]
|
||||
indent_size = 4
|
||||
|
||||
[templates/**.php]
|
||||
[resources/views/**.php]
|
||||
indent_size = 2
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
### HEAD
|
||||
* Move `templates/` to `resources/views/`, move `assets/` to `resources/assets/`, 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))
|
||||
|
||||
|
||||
21
README.md
21
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)
|
||||
```
|
||||
|
||||
|
||||
@@ -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 (($sage_views = basename(__DIR__).'/resources/views') !== get_option('template')) {
|
||||
update_option('template', $sage_views);
|
||||
wp_redirect($_SERVER['REQUEST_URI']);
|
||||
exit();
|
||||
}
|
||||
|
||||
10
package.json
10
package.json
@@ -18,12 +18,12 @@
|
||||
}
|
||||
],
|
||||
"scripts": {
|
||||
"build": "webpack --progress --config assets/build/webpack.config.js",
|
||||
"build:production": "webpack --progress -p --config assets/build/webpack.config.js",
|
||||
"build:profile": "webpack --progress --profile --json --config assets/build/webpack.config.js",
|
||||
"start": "webpack --hide-modules --watch --config assets/build/webpack.config.js",
|
||||
"build": "webpack --progress --config resources/assets/build/webpack.config.js",
|
||||
"build:production": "webpack --progress -p --config resources/assets/build/webpack.config.js",
|
||||
"build:profile": "webpack --progress --profile --json --config resources/assets/build/webpack.config.js",
|
||||
"start": "webpack --hide-modules --watch --config resources/assets/build/webpack.config.js",
|
||||
"rmdist": "rimraf dist",
|
||||
"lint": "eslint assets/scripts assets/build",
|
||||
"lint": "eslint resources/assets/scripts resources/assets/build",
|
||||
"test": "yarn run lint"
|
||||
},
|
||||
"engines": {
|
||||
|
||||
24
phpcs.xml
24
phpcs.xml
@@ -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>
|
||||
<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>
|
||||
|
||||
@@ -15,7 +15,7 @@ const config = merge({
|
||||
cacheBusting: '[name]_[hash]',
|
||||
paths: {
|
||||
root: rootPath,
|
||||
assets: path.join(rootPath, 'assets'),
|
||||
assets: path.join(rootPath, 'resources/assets'),
|
||||
dist: path.join(rootPath, 'dist'),
|
||||
},
|
||||
enabled: {
|
||||
@@ -13,7 +13,7 @@
|
||||
"proxyUrl": "http://localhost:3000",
|
||||
"cacheBusting": "[name]_[hash:8]",
|
||||
"watch": [
|
||||
"{src,templates}/**/*.php"
|
||||
"{src,resources/views}/**/*.php"
|
||||
],
|
||||
"browsers": [
|
||||
"last 2 versions",
|
||||
@@ -1,4 +1,4 @@
|
||||
@extends('layouts.base')
|
||||
@extends('layouts.app')
|
||||
|
||||
@section('content')
|
||||
@include('partials.page-header')
|
||||
@@ -1,4 +1,4 @@
|
||||
@extends('layouts.base')
|
||||
@extends('layouts.app')
|
||||
|
||||
@section('content')
|
||||
@include('partials.page-header')
|
||||
@@ -1,4 +1,4 @@
|
||||
@extends('layouts.base')
|
||||
@extends('layouts.app')
|
||||
|
||||
@section('content')
|
||||
@while(have_posts()) @php(the_post())
|
||||
@@ -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>
|
||||
@@ -1,4 +1,4 @@
|
||||
@extends('layouts.base')
|
||||
@extends('layouts.app')
|
||||
|
||||
@section('content')
|
||||
@include('partials.page-header')
|
||||
@@ -1,8 +1,7 @@
|
||||
@extends('layouts.base')
|
||||
@extends('layouts.app')
|
||||
|
||||
@section('content')
|
||||
@while(have_posts()) @php(the_post())
|
||||
@include('partials/content-single-'.get_post_type())
|
||||
@endwhile
|
||||
@endsection
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
Template Name: Custom Template
|
||||
--}}
|
||||
|
||||
@extends('layouts.base')
|
||||
@extends('layouts.app')
|
||||
|
||||
@section('content')
|
||||
@while(have_posts()) @php(the_post())
|
||||
@@ -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'
|
||||
]);
|
||||
|
||||
/**
|
||||
|
||||
@@ -41,10 +41,10 @@ class PostCreateProject
|
||||
$default_framework_pattern = '"bootstrap": ".*"';
|
||||
|
||||
$files_to_clear = [
|
||||
'assets/styles/components/_comments.scss',
|
||||
'assets/styles/components/_forms.scss',
|
||||
'assets/styles/components/_wp-classes.scss',
|
||||
'assets/styles/layouts/_header.scss',
|
||||
'resources/assets/styles/components/_comments.scss',
|
||||
'resources/assets/styles/components/_forms.scss',
|
||||
'resources/assets/styles/components/_wp-classes.scss',
|
||||
'resources/assets/styles/layouts/_header.scss',
|
||||
];
|
||||
|
||||
|
||||
@@ -61,16 +61,16 @@ class PostCreateProject
|
||||
break;
|
||||
case 1:
|
||||
file_put_contents('package.json', preg_replace("/{$default_framework_pattern}/", '"foundation-sites": "6.3.0"', file_get_contents('package.json')));
|
||||
file_put_contents('assets/styles/main.scss', str_replace('@import "~bootstrap/scss/bootstrap";' . "\n", '@import "~foundation-sites/scss/foundation";' . "\n" . '@include foundation-everything;' . "\n", file_get_contents('assets/styles/main.scss')));
|
||||
file_put_contents('assets/scripts/main.js', str_replace("import 'bootstrap';\n", "import 'foundation-sites/dist/js/foundation';\n", file_get_contents('assets/scripts/main.js')));
|
||||
file_put_contents('resources/assets/styles/main.scss', str_replace('@import "~bootstrap/scss/bootstrap";' . "\n", '@import "~foundation-sites/scss/foundation";' . "\n" . '@include foundation-everything;' . "\n", file_get_contents('resources/assets/styles/main.scss')));
|
||||
file_put_contents('resources/assets/scripts/main.js', str_replace("import 'bootstrap';\n", "import 'foundation-sites/dist/js/foundation';\n", file_get_contents('resources/assets/scripts/main.js')));
|
||||
foreach($files_to_clear as $file) {
|
||||
file_put_contents($file, '');
|
||||
}
|
||||
break;
|
||||
case 2:
|
||||
file_put_contents('package.json', preg_replace("/\s+{$default_framework_pattern},/", '', file_get_contents('package.json')));
|
||||
file_put_contents('assets/styles/main.scss', str_replace('@import "~bootstrap/scss/bootstrap";' . "\n", '', file_get_contents('assets/styles/main.scss')));
|
||||
file_put_contents('assets/scripts/main.js', str_replace("import 'bootstrap';\n", '', file_get_contents('assets/scripts/main.js')));
|
||||
file_put_contents('resources/assets/styles/main.scss', str_replace('@import "~bootstrap/scss/bootstrap";' . "\n", '', file_get_contents('resources/assets/styles/main.scss')));
|
||||
file_put_contents('resources/assets/scripts/main.js', str_replace("import 'bootstrap';\n", '', file_get_contents('resources/assets/scripts/main.js')));
|
||||
foreach($files_to_clear as $file) {
|
||||
file_put_contents($file, '');
|
||||
}
|
||||
@@ -93,8 +93,8 @@ class PostCreateProject
|
||||
file_put_contents('package.json', $package);
|
||||
|
||||
$import_dep_str = '// Import npm dependencies' . "\n";
|
||||
file_put_contents('assets/styles/main.scss', str_replace($import_dep_str, $import_dep_str . '@import "~font-awesome/scss/font-awesome";' . "\n", file_get_contents('assets/styles/main.scss')));
|
||||
file_put_contents('assets/styles/common/_variables.scss', "\n" . '$fa-font-path: \'~font-awesome/fonts\';' . "\n", FILE_APPEND);
|
||||
file_put_contents('resources/assets/styles/main.scss', str_replace($import_dep_str, $import_dep_str . '@import "~font-awesome/scss/font-awesome";' . "\n", file_get_contents('resources/assets/styles/main.scss')));
|
||||
file_put_contents('resources/assets/styles/common/_variables.scss', "\n" . '$fa-font-path: \'~font-awesome/fonts\';' . "\n", FILE_APPEND);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -116,8 +116,8 @@ class PostCreateProject
|
||||
'devUrl' => $io->ask('<info>Local development URL of WP site [<comment>'.$browsersync_settings_default['devUrl'].'</comment>]:</info> ', $browsersync_settings_default['devUrl'])
|
||||
];
|
||||
|
||||
file_put_contents('assets/config.json', str_replace('/app/themes/sage', $browsersync_settings['publicPath'], file_get_contents('assets/config.json')));
|
||||
file_put_contents('assets/config.json', str_replace($browsersync_settings_default['devUrl'], $browsersync_settings['devUrl'], file_get_contents('assets/config.json')));
|
||||
file_put_contents('resources/assets/config.json', str_replace('/app/themes/sage', $browsersync_settings['publicPath'], file_get_contents('resources/assets/config.json')));
|
||||
file_put_contents('resources/assets/config.json', str_replace($browsersync_settings_default['devUrl'], $browsersync_settings['devUrl'], file_get_contents('resources/assets/config.json')));
|
||||
}
|
||||
}
|
||||
// @codingStandardsIgnoreEnd
|
||||
|
||||
@@ -64,7 +64,7 @@ add_action('after_setup_theme', function () {
|
||||
|
||||
/**
|
||||
* Use main stylesheet for visual editor
|
||||
* @see assets/styles/layouts/_tinymce.scss
|
||||
* @see resources/assets/styles/layouts/_tinymce.scss
|
||||
*/
|
||||
add_editor_style(asset_path('styles/main.css'));
|
||||
}, 20);
|
||||
@@ -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",
|
||||
|
||||
Reference in New Issue
Block a user