Skip to content

Commit

Permalink
Merge pull request #1864 from roots/rename-base-to-app
Browse files Browse the repository at this point in the history
Move assets/ to resources/assets/, move templates/ to resources/views/
  • Loading branch information
retlehs authored Apr 4, 2017
2 parents 038de19 + 5ac56aa commit 73b6b78
Show file tree
Hide file tree
Showing 58 changed files with 67 additions and 64 deletions.
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ insert_final_newline = true
[*.php]
indent_size = 4

[templates/**.php]
[resources/views/**.php]
indent_size = 2
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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))

Expand Down
21 changes: 11 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
```

Expand Down
12 changes: 6 additions & 6 deletions functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,10 @@
/**
* 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
Expand All @@ -72,16 +72,16 @@
* 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 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
30 changes: 15 additions & 15 deletions phpcs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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"/>
Expand All @@ -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>
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion assets/config.json → resources/assets/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"proxyUrl": "http://localhost:3000",
"cacheBusting": "[name]_[hash:8]",
"watch": [
"{src,templates}/**/*.php"
"{src,resources/views}/**/*.php"
],
"browsers": [
"last 2 versions",
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion templates/404.blade.php → resources/views/404.blade.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@extends('layouts.base')
@extends('layouts.app')

@section('content')
@include('partials.page-header')
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@extends('layouts.base')
@extends('layouts.app')

@section('content')
@include('partials.page-header')
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@extends('layouts.base')
@extends('layouts.app')

@section('content')
@while(have_posts()) @php(the_post())
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -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>
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@extends('layouts.base')
@extends('layouts.app')

@section('content')
@include('partials.page-header')
Expand Down
Original file line number Diff line number Diff line change
@@ -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

Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Template Name: Custom Template
--}}

@extends('layouts.base')
@extends('layouts.app')

@section('content')
@while(have_posts()) @php(the_post())
Expand Down
4 changes: 2 additions & 2 deletions src/filters.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
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);
Expand All @@ -44,7 +44,7 @@
});
}, [
'index', '404', 'archive', 'author', 'category', 'tag', 'taxonomy', 'date', 'home',
'frontpage', 'page', 'paged', 'search', 'single', 'singular', 'attachment'
'front_page', 'page', 'paged', 'search', 'single', 'singular', 'attachment'
]);

/**
Expand Down
24 changes: 12 additions & 12 deletions src/lib/Sage/PostCreateProject.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ public static function selectFramework(Event $event)
$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',
];


Expand All @@ -61,16 +61,16 @@ public static function selectFramework(Event $event)
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, '');
}
Expand All @@ -93,8 +93,8 @@ public static function addFontAwesome(Event $event)
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);
}
}
}
Expand All @@ -116,8 +116,8 @@ public static function buildOptions(Event $event)
'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
Expand Down
8 changes: 5 additions & 3 deletions src/setup.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@

/**
* 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);
Expand Down Expand Up @@ -111,10 +111,12 @@
'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",
Expand Down

0 comments on commit 73b6b78

Please sign in to comment.