Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move required theme files to sage/resources #1877

Merged
merged 2 commits into from
Apr 16, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
### HEAD
* Move required theme files to `sage/resources` ([#1877](https://github.com/roots/sage/pull/1877))
* Move `src/` to `app/` ([#1868](https://github.com/roots/sage/pull/1868))
* 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))
Expand Down
36 changes: 18 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,31 +53,31 @@ During theme installation you will have the options to:
```shell
themes/your-theme-name/ # → Root of your Sage based theme
├── app/ # → Theme PHP
   ├── lib/Sage/ # → Blade implementation, asset manifest
   ├── admin.php # → Theme customizer setup
   ├── filters.php # → Theme filters
   ├── helpers.php # → Helper functions
   └── setup.php # → Theme setup
├── lib/Sage/ # → Blade implementation, asset manifest
├── admin.php # → Theme customizer setup
├── filters.php # → Theme filters
├── helpers.php # → Helper functions
└── setup.php # → Theme setup
├── composer.json # → Autoloading for `app/` files
├── composer.lock # → Composer lock file (never edit)
├── dist/ # → Built theme assets (never edit)
├── functions.php # → Composer autoloader, theme includes
├── index.php # → Never manually edit
├── node_modules/ # → Node.js packages (never edit)
├── package.json # → Node.js dependencies and scripts
├── screenshot.png # → Theme screenshot for WP admin
├── style.css # → Theme meta information
├── 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
│ │ ├── config.json # → Settings for compiled assets
│ │ ├── build/ # → Webpack and ESLint config
│ │ ├── fonts/ # → Theme fonts
│ │ ├── images/ # → Theme images
│ │ ├── scripts/ # → Theme JS
│ │ └── styles/ # → Theme stylesheets
│ ├── functions.php # → Composer autoloader, theme includes
│ ├── index.php # → Never manually edit
│ ├── screenshot.png # → Theme screenshot for WP admin
│ ├── style.css # → Theme meta information
│ └── views/ # → Theme templates
│ ├── layouts/ # → Base templates
│ └── partials/ # → Partial templates
└── vendor/ # → Composer packages (never edit)
```

Expand Down
30 changes: 17 additions & 13 deletions app/filters.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,24 @@
* Add <body> classes
*/
add_filter('body_class', function (array $classes) {
// Add page slug if it doesn't exist
/** Add page slug if it doesn't exist */
if (is_single() || is_page() && !is_front_page()) {
if (!in_array(basename(get_permalink()), $classes)) {
$classes[] = basename(get_permalink());
}
}

// Add class if sidebar is active
/** Add class if sidebar is active */
if (display_sidebar()) {
$classes[] = 'sidebar-primary';
}

return $classes;
/** Clean up class names for custom templates */
$classes = array_map(function ($class) {
return preg_replace(['/-blade(-php)?$/', '/^page-template-views/'], '', $class);
}, $classes);

return array_filter($classes);
});

/**
Expand All @@ -31,31 +36,30 @@
/**
* Template Hierarchy should search for .blade.php files
*/
array_map(function ($type) {
collect([
'index', '404', 'archive', 'author', 'category', 'tag', 'taxonomy', 'date', 'home',
'frontpage', 'page', 'paged', 'search', 'single', 'singular', 'attachment'
])->map(function ($type) {
add_filter("{$type}_template_hierarchy", function ($templates) {
return call_user_func_array('array_merge', array_map(function ($template) {
return collect($templates)->flatMap(function ($template) {
$transforms = [
'%^/?(resources/views)?/?%' => config('sage.disable_option_hack') ? 'resources/views/' : '',
'%^/?(resources[\\/]views)?[\\/]?%' => '',
'%(\.blade)?(\.php)?$%' => ''
];
$normalizedTemplate = preg_replace(array_keys($transforms), array_values($transforms), $template);
return ["{$normalizedTemplate}.blade.php", "{$normalizedTemplate}.php"];
}, $templates));
})->toArray();
});
}, [
'index', '404', 'archive', 'author', 'category', 'tag', 'taxonomy', 'date', 'home',
'frontpage', 'page', 'paged', 'search', 'single', 'singular', 'attachment'
]);
});

/**
* Render page using Blade
*/
add_filter('template_include', function ($template) {
$data = array_reduce(get_body_class(), function ($data, $class) use ($template) {
$data = collect(get_body_class())->reduce(function ($data, $class) use ($template) {
return apply_filters("sage/template/{$class}/data", $data, $template);
}, []);
echo template($template, $data);

// Return a blank file to make WordPress happy
return get_theme_file_path('index.php');
}, PHP_INT_MAX);
Expand Down
2 changes: 1 addition & 1 deletion app/lib/Sage/PostCreateProject.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public static function updateHeaders(Event $event)
'author_uri' => $io->ask('<info>Theme Author URI [<comment>'.$theme_headers_default['author_uri'].'</comment>]:</info> ', $theme_headers_default['author_uri'])
];

file_put_contents('style.css', str_replace($theme_headers_default, $theme_headers, file_get_contents('style.css')));
file_put_contents('resources/style.css', str_replace($theme_headers_default, $theme_headers, file_get_contents('resources/style.css')));
}
}

Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"illuminate/config": "~5.4.0"
},
"require-dev": {
"squizlabs/php_codesniffer": "^2.5.1"
"squizlabs/php_codesniffer": "^2.8.0"
},
"scripts": {
"test": [
Expand Down
Loading