From 9eaffa3a2d4df462dd8020a10551334208bd32a3 Mon Sep 17 00:00:00 2001 From: QWp6t Date: Fri, 18 Dec 2015 16:41:37 -0800 Subject: [PATCH 01/82] Restructure theme, use autoloader --- .travis.yml | 5 +- app/admin.php | 15 ++ app/filters.php | 55 +++++++ app/helpers.php | 77 ++++++++++ app/lib/Sage/Asset.php | 35 +++++ app/lib/Sage/Assets/IManifest.php | 26 ++++ app/lib/Sage/Assets/JsonManifest.php | 29 ++++ app/lib/Sage/Template.php | 151 ++++++++++++++++++++ app/lib/Sage/Template/IWrapper.php | 27 ++++ app/lib/Sage/Template/Wrapper.php | 48 +++++++ app/setup.php | 96 +++++++++++++ composer.json | 15 +- composer.lock | 119 +++++++++++++++ functions.php | 44 +++--- gulpfile.js | 2 +- index.php | 18 +-- lib/assets.php | 58 -------- lib/customizer.php | 21 --- lib/extras.php | 33 ----- lib/setup.php | 106 -------------- lib/titles.php | 24 ---- lib/wrapper.php | 64 --------- package.json | 2 +- page.php | 4 - ruleset.xml | 5 - single.php | 1 - style.css | 2 +- template-custom.php | 10 -- 404.php => templates/404.php | 2 +- templates/index.php | 14 ++ base.php => templates/layouts/base.php | 19 +-- templates/page-header.php | 5 - templates/page.php | 4 + templates/{ => partials}/comments.php | 0 templates/{ => partials}/content-page.php | 0 templates/{ => partials}/content-search.php | 2 +- templates/{ => partials}/content-single.php | 4 +- templates/{ => partials}/content.php | 2 +- templates/{ => partials}/entry-meta.php | 0 templates/{ => partials}/footer.php | 0 templates/{ => partials}/head.php | 0 templates/{ => partials}/header.php | 0 templates/partials/page-header.php | 3 + templates/{ => partials}/sidebar.php | 0 search.php => templates/search.php | 4 +- templates/single.php | 1 + templates/template-custom.php | 10 ++ 47 files changed, 770 insertions(+), 392 deletions(-) create mode 100644 app/admin.php create mode 100644 app/filters.php create mode 100644 app/helpers.php create mode 100644 app/lib/Sage/Asset.php create mode 100644 app/lib/Sage/Assets/IManifest.php create mode 100644 app/lib/Sage/Assets/JsonManifest.php create mode 100644 app/lib/Sage/Template.php create mode 100644 app/lib/Sage/Template/IWrapper.php create mode 100644 app/lib/Sage/Template/Wrapper.php create mode 100644 app/setup.php create mode 100644 composer.lock delete mode 100644 lib/assets.php delete mode 100644 lib/customizer.php delete mode 100644 lib/extras.php delete mode 100644 lib/setup.php delete mode 100644 lib/titles.php delete mode 100644 lib/wrapper.php delete mode 100644 page.php delete mode 100644 single.php delete mode 100644 template-custom.php rename 404.php => templates/404.php (73%) create mode 100644 templates/index.php rename base.php => templates/layouts/base.php (69%) delete mode 100644 templates/page-header.php create mode 100644 templates/page.php rename templates/{ => partials}/comments.php (100%) rename templates/{ => partials}/content-page.php (100%) rename templates/{ => partials}/content-search.php (71%) rename templates/{ => partials}/content-single.php (76%) rename templates/{ => partials}/content.php (80%) rename templates/{ => partials}/entry-meta.php (100%) rename templates/{ => partials}/footer.php (100%) rename templates/{ => partials}/head.php (100%) rename templates/{ => partials}/header.php (100%) create mode 100644 templates/partials/page-header.php rename templates/{ => partials}/sidebar.php (100%) rename search.php => templates/search.php (70%) create mode 100644 templates/single.php create mode 100644 templates/template-custom.php diff --git a/.travis.yml b/.travis.yml index fa38f3635f..ac066b908c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -23,9 +23,12 @@ install: - composer self-update && composer --version - export PATH="$HOME/.composer/vendor/bin:$PATH" - composer global require squizlabs/php_codesniffer + - composer global require phpmd/phpmd + - composer install -o script: - npm run build - npm run jshint - npm run jscs - - phpcs --standard=ruleset.xml --extensions=php -n -s . + - phpcs --standard=ruleset.xml --extensions=php --ignore=node_modules,bower_components,vendor -n -s . + - phpmd app text cleancode,codesize,controversial,design,naming,unusedcode diff --git a/app/admin.php b/app/admin.php new file mode 100644 index 0000000000..74fa2c480f --- /dev/null +++ b/app/admin.php @@ -0,0 +1,15 @@ +get_setting('blogname')->transport = 'postMessage'; +}); + +/** + * Customizer JS + */ +add_action('customize_preview_init', function () { + wp_enqueue_script('sage/customizer', asset_path('scripts/customizer.js'), ['customize-preview'], null, true); +}); diff --git a/app/filters.php b/app/filters.php new file mode 100644 index 0000000000..a631da64db --- /dev/null +++ b/app/filters.php @@ -0,0 +1,55 @@ + classes + */ +add_filter('body_class', function (array $classes) { + // 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 + if (display_sidebar()) { + $classes[] = 'sidebar-primary'; + } + + return $classes; +}); + +/** + * Clean up the_excerpt() + */ +add_filter('excerpt_more', function () { + return ' … ' . __('Continued', 'sage') . ''; +}); + + +/** + * Use Wrapper by default + */ +add_filter('template_include', function ($main) { + if (!is_string($main) || !(string) $main) { + return $main; + } + $main = basename($main, '.php'); + return Template::wrap(new Wrapper($main, 'layouts/base.php'))->locate(); +}, 109); diff --git a/app/helpers.php b/app/helpers.php new file mode 100644 index 0000000000..395744a9b6 --- /dev/null +++ b/app/helpers.php @@ -0,0 +1,77 @@ +locate()) { + /** @noinspection PhpIncludeInspection */ + include $file; + } +} + +/** + * @param array $context + */ +function template_sidebar($context = []) { + template_part('sidebar', $context); +} + +/** + * @param $template + * @param array $context + */ +function template_part($template, $context = []) { + if ($file = (new Template($template, $context))->locate()) { + /** @noinspection PhpIncludeInspection */ + include $file; + } +} + +/** + * @param $filename + * @return string + */ +function asset_path($filename) { + static $manifest; + isset($manifest) || $manifest = new JsonManifest(get_template_directory() . '/' . Asset::$dist . '/assets.json'); + return (string) new Asset($filename, $manifest); +} + +/** + * Determine whether to show the sidebar + * @return bool + */ +function display_sidebar() { + static $display; + isset($display) || $display = apply_filters('sage/display_sidebar', true); + return $display; +} + +/** + * Page titles + * @return string + */ +function title() { + if (is_home()) { + if ($home = get_option('page_for_posts', true)) { + return get_the_title($home); + } + return __('Latest Posts', 'sage'); + } + if (is_archive()) { + return get_the_archive_title(); + } + if (is_search()) { + return sprintf(__('Search Results for %s', 'sage'), get_search_query()); + } + if (is_404()) { + return __('Not Found', 'sage'); + } + return get_the_title(); +} diff --git a/app/lib/Sage/Asset.php b/app/lib/Sage/Asset.php new file mode 100644 index 0000000000..fd47a7bfa1 --- /dev/null +++ b/app/lib/Sage/Asset.php @@ -0,0 +1,35 @@ +manifest = $manifest; + $this->asset = basename($file); + $this->dir = dirname($file) != '.' ? dirname($file) : ''; + } + + public function __toString() { + return $this->getUri(); + } + + public function getUri() { + $file = self::$dist . '/' . $this->dir . '/' . ($this->manifest ? $this->manifest->get($this->asset) : $this->asset); + return get_template_directory_uri() . $file; + } +} diff --git a/app/lib/Sage/Assets/IManifest.php b/app/lib/Sage/Assets/IManifest.php new file mode 100644 index 0000000000..62b5134261 --- /dev/null +++ b/app/lib/Sage/Assets/IManifest.php @@ -0,0 +1,26 @@ +manifest = file_exists($manifestPath) ? json_decode(file_get_contents($manifestPath), true) : []; + } + + /** @inheritdoc */ + public function get($file) { + return isset($this->manifest[$file]) ? $this->manifest[$file] : $file; + } + + /** @inheritdoc */ + public function getAll() { + return $this->manifest; + } +} diff --git a/app/lib/Sage/Template.php b/app/lib/Sage/Template.php new file mode 100644 index 0000000000..3655e76e44 --- /dev/null +++ b/app/lib/Sage/Template.php @@ -0,0 +1,151 @@ +getSlug()] = $wrapper; + return new static($wrapper->getWrappers(), $context); + } + + /** + * @param string $slug + * @param array $context + * @return static + */ + public static function unwrap($slug = '', $context = []) { + if (!$slug) { + // If no slug is specified, we grab the most recently wrapped item + end(self::$wrappers); + $slug = key(self::$wrappers); + } + return new static(self::$wrappers[$slug]->getTemplate(), $context); + } + + /** + * Converts a delimeted template file into an array of parts + * + * Example: + * Template::getConvertedTemplateParts('content-single-audio.php'); + * => ['content-single-audio.php', 'content-single.php', 'content.php'] + * + * The returned value can then be passed to WordPress's locate_template. + * + * @param string $template + * @param string $delimeter + * @return array + */ + public static function convertParts($template, $delimeter = '-') { + $templateParts = explode($delimeter, str_replace('.php', '', (string) $template)); + $templates[] = array_shift($templateParts); + foreach ($templateParts as $i => $templatePart) { + $templates[] = $templates[$i] . $delimeter . $templatePart; + } + return array_reverse($templates); + } + + /** + * Template constructor + * @param string|string[] $template + * @param array $context + */ + public function __construct($template, array $context = []) { + $this->set($template); + $this->context = $context; + } + + /** + * @return string HTML + * @see get + */ + public function __toString() { + return $this->get(); + } + + /** + * Echoes the output HTML + * @see get + */ + public function render() { + echo $this->get(); + } + + /** + * @return string HTML + * @SuppressWarnings(PHPMD.UnusedLocalVariable) + */ + public function get() { + /** @noinspection PhpUnusedLocalVariableInspection $context is passed to the included template */ + $context = $this->context; + extract($this->context); + ob_start(); + if ($template = $this->locate()) { + /** @noinspection PhpIncludeInspection */ + include $template; + } + $this->html = ob_get_clean() ?: ''; + return $this->html; + } + + /** + * @param string[]|string $template + */ + public function set($template) { + if (is_array($template)) { + $this->templates = self::format($template); + return; + } + if (!is_string($template) || !(string) $template) { + return; + } + // At this point, we assume it's something like `content-single.php` or `content-single-audio.php` + $this->templates = self::format(self::convertParts($template)); + } + + /** + * Ensures that each template in $this->templates is appended with `.php` + * @param $templates + * @return array + */ + protected static function format($templates) { + return array_map(function ($template) { + if (substr($template, -4, 4) === '.php') { + return $template; + } + return $template . '.php'; + }, $templates); + } + + /** + * @param string $templateDir Specify a template directory relative to your theme directory; e.g., `templates/`, `templates/partials/`, `woocommerce/` + * @return string Filename + */ + public function locate($templateDir = '') { + $templates = array_map(function ($template) use ($templateDir) { + return ($templateDir ?: self::$root) . $template; + }, $this->templates); + $template = locate_template($templates); + return apply_filters('sage/locate_template', $template, $templates) ?: $template; + } +} diff --git a/app/lib/Sage/Template/IWrapper.php b/app/lib/Sage/Template/IWrapper.php new file mode 100644 index 0000000000..d785988788 --- /dev/null +++ b/app/lib/Sage/Template/IWrapper.php @@ -0,0 +1,27 @@ +slug = sanitize_title(basename($base, '.php')); + $this->wrappers = [$base]; + $this->template = $templateSlug; + $str = substr($base, 0, -4); + array_unshift($this->wrappers, sprintf($str . '-%s.php', $templateSlug)); + } + + /** {@inheritdoc} */ + public function getWrappers() { + $this->wrappers = apply_filters('sage/wrap_' . $this->slug, $this->wrappers) ?: $this->wrappers; + return $this->wrappers; + } + + /** {@inheritdoc} */ + public function getSlug() { + return $this->slug; + } + + /** {@inheritdoc} */ + public function getTemplate() + { + return $this->template; + } +} diff --git a/app/setup.php b/app/setup.php new file mode 100644 index 0000000000..1127939e41 --- /dev/null +++ b/app/setup.php @@ -0,0 +1,96 @@ + __('Primary Navigation', 'sage') + ]); + + /** + * Enable post thumbnails + * @link http://codex.wordpress.org/Post_Thumbnails + * @link http://codex.wordpress.org/Function_Reference/set_post_thumbnail_size + * @link http://codex.wordpress.org/Function_Reference/add_image_size + */ + add_theme_support('post-thumbnails'); + + /** + * Enable post formats + * @link http://codex.wordpress.org/Post_Formats + */ + add_theme_support('post-formats', ['aside', 'gallery', 'link', 'image', 'quote', 'video', 'audio']); + + /** + * Enable HTML5 markup support + * @link http://codex.wordpress.org/Function_Reference/add_theme_support#HTML5 + */ + add_theme_support('html5', ['caption', 'comment-form', 'comment-list', 'gallery', 'search-form']); + + /** + * Use main stylesheet for visual editor + * @see /assets/styles/layouts/_tinymce.scss + */ + add_editor_style(asset_path('styles/main.css')); +}); + +/** + * Register sidebars + */ +add_action('widgets_init', function () { + $config = function ($name, $id = '') { + return [ + 'name' => __($name, 'sage'), + 'id' => 'sidebar-' . $id ?: sanitize_title($name), + 'before_widget' => '
', + 'after_widget' => '
', + 'before_title' => '

', + 'after_title' => '

' + ]; + }; + + register_sidebar($config('Primary')); + register_sidebar($config('Footer')); +}); + +/** + * Theme assets + */ +add_action('wp_enqueue_scripts', function () { + wp_enqueue_style('sage/css', asset_path('styles/main.css'), false, null); + + if (is_single() && comments_open() && get_option('thread_comments')) { + wp_enqueue_script('comment-reply'); + } + + wp_enqueue_script('sage/js', asset_path('scripts/main.js'), ['jquery'], null, true); +}, 100); diff --git a/composer.json b/composer.json index d9e6d58c7b..8afb68b185 100644 --- a/composer.json +++ b/composer.json @@ -23,8 +23,19 @@ "issues": "https://github.com/roots/sage/issues", "forum": "https://discourse.roots.io/" }, + "autoload": { + "psr-4": { + "Roots\\Sage\\": "app/lib/Sage/" + }, + "files": [ + "app/helpers.php", + "app/setup.php", + "app/filters.php", + "app/admin.php" + ] + }, "require": { - "php": ">=5.4.0", + "php": ">=5.5.0", "composer/installers": "~1.0" } -} \ No newline at end of file +} diff --git a/composer.lock b/composer.lock new file mode 100644 index 0000000000..6f0dea204d --- /dev/null +++ b/composer.lock @@ -0,0 +1,119 @@ +{ + "_readme": [ + "This file locks the dependencies of your project to a known state", + "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", + "This file is @generated automatically" + ], + "hash": "85f4aee59d18d093f8e3a52b8a70f766", + "content-hash": "75ad99c892e1d82404c58fe3bd989585", + "packages": [ + { + "name": "composer/installers", + "version": "v1.0.22", + "source": { + "type": "git", + "url": "https://github.com/composer/installers.git", + "reference": "bd9b14f094c89c8b5804a4e41edeb7853bb85046" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/composer/installers/zipball/bd9b14f094c89c8b5804a4e41edeb7853bb85046", + "reference": "bd9b14f094c89c8b5804a4e41edeb7853bb85046", + "shasum": "" + }, + "require": { + "composer-plugin-api": "1.0.0" + }, + "replace": { + "roundcube/plugin-installer": "*", + "shama/baton": "*" + }, + "require-dev": { + "composer/composer": "1.0.*@dev", + "phpunit/phpunit": "4.1.*" + }, + "type": "composer-plugin", + "extra": { + "class": "Composer\\Installers\\Plugin", + "branch-alias": { + "dev-master": "1.0-dev" + } + }, + "autoload": { + "psr-0": { + "Composer\\Installers\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Kyle Robinson Young", + "email": "kyle@dontkry.com", + "homepage": "https://github.com/shama" + } + ], + "description": "A multi-framework Composer library installer", + "homepage": "http://composer.github.com/installers/", + "keywords": [ + "Craft", + "Dolibarr", + "Hurad", + "MODX Evo", + "OXID", + "SMF", + "Thelia", + "WolfCMS", + "agl", + "aimeos", + "annotatecms", + "bitrix", + "cakephp", + "chef", + "codeigniter", + "concrete5", + "croogo", + "dokuwiki", + "drupal", + "elgg", + "fuelphp", + "grav", + "installer", + "joomla", + "kohana", + "laravel", + "lithium", + "magento", + "mako", + "mediawiki", + "modulework", + "moodle", + "phpbb", + "piwik", + "ppi", + "puppet", + "roundcube", + "shopware", + "silverstripe", + "symfony", + "typo3", + "wordpress", + "zend", + "zikula" + ], + "time": "2015-10-29 23:28:48" + } + ], + "packages-dev": [], + "aliases": [], + "minimum-stability": "stable", + "stability-flags": [], + "prefer-stable": false, + "prefer-lowest": false, + "platform": { + "php": ">=5.5.0" + }, + "platform-dev": [] +} diff --git a/functions.php b/functions.php index 35df8db212..11c9a5e2a4 100644 --- a/functions.php +++ b/functions.php @@ -1,28 +1,28 @@ + -
- -
- - - - - - - - +if (defined('ABSPATH')) { + update_option('template', get_option('template') . '/templates'); +} +die("Kind Regards,\nRoots"); diff --git a/lib/assets.php b/lib/assets.php deleted file mode 100644 index fba751cc3a..0000000000 --- a/lib/assets.php +++ /dev/null @@ -1,58 +0,0 @@ -manifest = json_decode(file_get_contents($manifest_path), true); - } else { - $this->manifest = []; - } - } - - public function get() { - return $this->manifest; - } - - public function getPath($key = '', $default = null) { - $collection = $this->manifest; - if (is_null($key)) { - return $collection; - } - if (isset($collection[$key])) { - return $collection[$key]; - } - foreach (explode('.', $key) as $segment) { - if (!isset($collection[$segment])) { - return $default; - } else { - $collection = $collection[$segment]; - } - } - return $collection; - } -} - -function asset_path($filename) { - $dist_path = get_template_directory_uri() . '/dist/'; - $directory = dirname($filename) . '/'; - $file = basename($filename); - static $manifest; - - if (empty($manifest)) { - $manifest_path = get_template_directory() . '/dist/' . 'assets.json'; - $manifest = new JsonManifest($manifest_path); - } - - if (array_key_exists($file, $manifest->get())) { - return $dist_path . $directory . $manifest->get()[$file]; - } else { - return $dist_path . $directory . $file; - } -} diff --git a/lib/customizer.php b/lib/customizer.php deleted file mode 100644 index d0253f9409..0000000000 --- a/lib/customizer.php +++ /dev/null @@ -1,21 +0,0 @@ -get_setting('blogname')->transport = 'postMessage'; -} -add_action('customize_register', __NAMESPACE__ . '\\customize_register'); - -/** - * Customizer JS - */ -function customize_preview_js() { - wp_enqueue_script('sage/customizer', Assets\asset_path('scripts/customizer.js'), ['customize-preview'], null, true); -} -add_action('customize_preview_init', __NAMESPACE__ . '\\customize_preview_js'); diff --git a/lib/extras.php b/lib/extras.php deleted file mode 100644 index dc551563ef..0000000000 --- a/lib/extras.php +++ /dev/null @@ -1,33 +0,0 @@ - classes - */ -function body_class($classes) { - // 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 - if (Setup\display_sidebar()) { - $classes[] = 'sidebar-primary'; - } - - return $classes; -} -add_filter('body_class', __NAMESPACE__ . '\\body_class'); - -/** - * Clean up the_excerpt() - */ -function excerpt_more() { - return ' … ' . __('Continued', 'sage') . ''; -} -add_filter('excerpt_more', __NAMESPACE__ . '\\excerpt_more'); diff --git a/lib/setup.php b/lib/setup.php deleted file mode 100644 index b9f962d18b..0000000000 --- a/lib/setup.php +++ /dev/null @@ -1,106 +0,0 @@ - __('Primary Navigation', 'sage') - ]); - - // Enable post thumbnails - // http://codex.wordpress.org/Post_Thumbnails - // http://codex.wordpress.org/Function_Reference/set_post_thumbnail_size - // http://codex.wordpress.org/Function_Reference/add_image_size - add_theme_support('post-thumbnails'); - - // Enable post formats - // http://codex.wordpress.org/Post_Formats - add_theme_support('post-formats', ['aside', 'gallery', 'link', 'image', 'quote', 'video', 'audio']); - - // Enable HTML5 markup support - // http://codex.wordpress.org/Function_Reference/add_theme_support#HTML5 - add_theme_support('html5', ['caption', 'comment-form', 'comment-list', 'gallery', 'search-form']); - - // Use main stylesheet for visual editor - // To add custom styles edit /assets/styles/layouts/_tinymce.scss - add_editor_style(Assets\asset_path('styles/main.css')); -} -add_action('after_setup_theme', __NAMESPACE__ . '\\setup'); - -/** - * Register sidebars - */ -function widgets_init() { - register_sidebar([ - 'name' => __('Primary', 'sage'), - 'id' => 'sidebar-primary', - 'before_widget' => '
', - 'after_widget' => '
', - 'before_title' => '

', - 'after_title' => '

' - ]); - - register_sidebar([ - 'name' => __('Footer', 'sage'), - 'id' => 'sidebar-footer', - 'before_widget' => '
', - 'after_widget' => '
', - 'before_title' => '

', - 'after_title' => '

' - ]); -} -add_action('widgets_init', __NAMESPACE__ . '\\widgets_init'); - -/** - * Determine which pages should NOT display the sidebar - */ -function display_sidebar() { - static $display; - - isset($display) || $display = !in_array(true, [ - // The sidebar will NOT be displayed if ANY of the following return true. - // @link https://codex.wordpress.org/Conditional_Tags - is_404(), - is_front_page(), - is_page_template('template-custom.php'), - ]); - - return apply_filters('sage/display_sidebar', $display); -} - -/** - * Theme assets - */ -function assets() { - wp_enqueue_style('sage/css', Assets\asset_path('styles/main.css'), false, null); - - if (is_single() && comments_open() && get_option('thread_comments')) { - wp_enqueue_script('comment-reply'); - } - - wp_enqueue_script('sage/js', Assets\asset_path('scripts/main.js'), ['jquery'], null, true); -} -add_action('wp_enqueue_scripts', __NAMESPACE__ . '\\assets', 100); diff --git a/lib/titles.php b/lib/titles.php deleted file mode 100644 index cdabacd65c..0000000000 --- a/lib/titles.php +++ /dev/null @@ -1,24 +0,0 @@ -slug = basename($template, '.php'); - $this->templates = [$template]; - - if (self::$base) { - $str = substr($template, 0, -4); - array_unshift($this->templates, sprintf($str . '-%s.php', self::$base)); - } - } - - public function __toString() { - $this->templates = apply_filters('sage/wrap_' . $this->slug, $this->templates); - return locate_template($this->templates); - } - - public static function wrap($main) { - // Check for other filters returning null - if (!is_string($main)) { - return $main; - } - - self::$main_template = $main; - self::$base = basename(self::$main_template, '.php'); - - if (self::$base === 'index') { - self::$base = false; - } - - return new SageWrapping(); - } -} -add_filter('template_include', [__NAMESPACE__ . '\\SageWrapping', 'wrap'], 109); diff --git a/package.json b/package.json index 3e76e8472d..40b1c12eb5 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "sage", - "version": "8.4.2", + "version": "9.0.0", "author": "Ben Word ", "homepage": "https://roots.io/sage/", "private": true, diff --git a/page.php b/page.php deleted file mode 100644 index 6e55a0d8ee..0000000000 --- a/page.php +++ /dev/null @@ -1,4 +0,0 @@ - - - - diff --git a/ruleset.xml b/ruleset.xml index f0b7c0af41..8fb7a9cafb 100644 --- a/ruleset.xml +++ b/ruleset.xml @@ -28,11 +28,6 @@ templates/* - 404.php - index.php - page.php - single.php - template-custom.php diff --git a/single.php b/single.php deleted file mode 100644 index 71b1840fa4..0000000000 --- a/single.php +++ /dev/null @@ -1 +0,0 @@ - diff --git a/style.css b/style.css index 3b2edc874d..c03c6f347a 100644 --- a/style.css +++ b/style.css @@ -2,7 +2,7 @@ Theme Name: Sage Starter Theme Theme URI: https://roots.io/sage/ Description: Sage is a WordPress starter theme. Contribute on GitHub -Version: 8.4.2 +Version: 9.0.0 Author: Roots Author URI: https://roots.io/ Text Domain: sage diff --git a/template-custom.php b/template-custom.php deleted file mode 100644 index 3becaba1a6..0000000000 --- a/template-custom.php +++ /dev/null @@ -1,10 +0,0 @@ - - - - - - diff --git a/404.php b/templates/404.php similarity index 73% rename from 404.php rename to templates/404.php index 8d228d527b..23af1ece56 100644 --- a/404.php +++ b/templates/404.php @@ -1,4 +1,4 @@ - +
diff --git a/templates/index.php b/templates/index.php new file mode 100644 index 0000000000..16694b8fda --- /dev/null +++ b/templates/index.php @@ -0,0 +1,14 @@ + + + +
+ +
+ + + + + + + + diff --git a/base.php b/templates/layouts/base.php similarity index 69% rename from base.php rename to templates/layouts/base.php index f5a0cfd04d..54b0de6fbc 100644 --- a/base.php +++ b/templates/layouts/base.php @@ -1,13 +1,6 @@ - - > - + >
- +
- +
diff --git a/templates/page-header.php b/templates/page-header.php deleted file mode 100644 index 55a27ca466..0000000000 --- a/templates/page-header.php +++ /dev/null @@ -1,5 +0,0 @@ - - - diff --git a/templates/page.php b/templates/page.php new file mode 100644 index 0000000000..7a1d16710d --- /dev/null +++ b/templates/page.php @@ -0,0 +1,4 @@ + + + + diff --git a/templates/comments.php b/templates/partials/comments.php similarity index 100% rename from templates/comments.php rename to templates/partials/comments.php diff --git a/templates/content-page.php b/templates/partials/content-page.php similarity index 100% rename from templates/content-page.php rename to templates/partials/content-page.php diff --git a/templates/content-search.php b/templates/partials/content-search.php similarity index 71% rename from templates/content-search.php rename to templates/partials/content-search.php index 79339c83c1..749f11acd7 100644 --- a/templates/content-search.php +++ b/templates/partials/content-search.php @@ -1,7 +1,7 @@
>

- +
diff --git a/templates/content-single.php b/templates/partials/content-single.php similarity index 76% rename from templates/content-single.php rename to templates/partials/content-single.php index 2750794391..60392e9e48 100644 --- a/templates/content-single.php +++ b/templates/partials/content-single.php @@ -2,7 +2,7 @@
>

- +
@@ -10,6 +10,6 @@
'']); ?>
- +
diff --git a/templates/content.php b/templates/partials/content.php similarity index 80% rename from templates/content.php rename to templates/partials/content.php index 0904a5ed88..3ae0e4abba 100644 --- a/templates/content.php +++ b/templates/partials/content.php @@ -1,7 +1,7 @@
>

- +
diff --git a/templates/entry-meta.php b/templates/partials/entry-meta.php similarity index 100% rename from templates/entry-meta.php rename to templates/partials/entry-meta.php diff --git a/templates/footer.php b/templates/partials/footer.php similarity index 100% rename from templates/footer.php rename to templates/partials/footer.php diff --git a/templates/head.php b/templates/partials/head.php similarity index 100% rename from templates/head.php rename to templates/partials/head.php diff --git a/templates/header.php b/templates/partials/header.php similarity index 100% rename from templates/header.php rename to templates/partials/header.php diff --git a/templates/partials/page-header.php b/templates/partials/page-header.php new file mode 100644 index 0000000000..0f1a21cdfc --- /dev/null +++ b/templates/partials/page-header.php @@ -0,0 +1,3 @@ + diff --git a/templates/sidebar.php b/templates/partials/sidebar.php similarity index 100% rename from templates/sidebar.php rename to templates/partials/sidebar.php diff --git a/search.php b/templates/search.php similarity index 70% rename from search.php rename to templates/search.php index 63d867c579..e150715b22 100644 --- a/search.php +++ b/templates/search.php @@ -1,4 +1,4 @@ - +
@@ -8,7 +8,7 @@ - + diff --git a/templates/single.php b/templates/single.php new file mode 100644 index 0000000000..345b962fb3 --- /dev/null +++ b/templates/single.php @@ -0,0 +1 @@ + diff --git a/templates/template-custom.php b/templates/template-custom.php new file mode 100644 index 0000000000..82ef512943 --- /dev/null +++ b/templates/template-custom.php @@ -0,0 +1,10 @@ + + + + + + From 97906e97e9055390c19cedda87bb81ed33354350 Mon Sep 17 00:00:00 2001 From: QWp6t Date: Fri, 18 Dec 2015 18:55:19 -0800 Subject: [PATCH 02/82] Rename interfaces, unset after unwrapping --- app/lib/Sage/Asset.php | 6 +++--- app/lib/Sage/Assets/JsonManifest.php | 2 +- .../Assets/{IManifest.php => ManifestInterface.php} | 4 ++-- app/lib/Sage/Template.php | 12 +++++++----- app/lib/Sage/Template/Wrapper.php | 4 ++-- .../Template/{IWrapper.php => WrapperInterface.php} | 6 +++--- composer.json | 2 +- 7 files changed, 19 insertions(+), 17 deletions(-) rename app/lib/Sage/Assets/{IManifest.php => ManifestInterface.php} (87%) rename app/lib/Sage/Template/{IWrapper.php => WrapperInterface.php} (80%) diff --git a/app/lib/Sage/Asset.php b/app/lib/Sage/Asset.php index fd47a7bfa1..3508ff8729 100644 --- a/app/lib/Sage/Asset.php +++ b/app/lib/Sage/Asset.php @@ -1,6 +1,6 @@ manifest = $manifest; $this->asset = basename($file); $this->dir = dirname($file) != '.' ? dirname($file) : ''; diff --git a/app/lib/Sage/Assets/JsonManifest.php b/app/lib/Sage/Assets/JsonManifest.php index 9b776d0452..ff9936430e 100644 --- a/app/lib/Sage/Assets/JsonManifest.php +++ b/app/lib/Sage/Assets/JsonManifest.php @@ -5,7 +5,7 @@ * @package Roots\Sage * @author QWp6t */ -class JsonManifest implements IManifest { +class JsonManifest implements ManifestInterface { /** @var array */ protected $manifest = []; diff --git a/app/lib/Sage/Assets/IManifest.php b/app/lib/Sage/Assets/ManifestInterface.php similarity index 87% rename from app/lib/Sage/Assets/IManifest.php rename to app/lib/Sage/Assets/ManifestInterface.php index 62b5134261..749185b0e4 100644 --- a/app/lib/Sage/Assets/IManifest.php +++ b/app/lib/Sage/Assets/ManifestInterface.php @@ -1,11 +1,11 @@ getSlug()] = $wrapper; return new static($wrapper->getWrappers(), $context); } @@ -40,7 +40,9 @@ public static function unwrap($slug = '', $context = []) { end(self::$wrappers); $slug = key(self::$wrappers); } - return new static(self::$wrappers[$slug]->getTemplate(), $context); + $template = new static(self::$wrappers[$slug]->getTemplate(), $context); + unset(self::$wrappers[$slug]); + return $template; } /** diff --git a/app/lib/Sage/Template/Wrapper.php b/app/lib/Sage/Template/Wrapper.php index 5ae23d8a51..009b56b07c 100644 --- a/app/lib/Sage/Template/Wrapper.php +++ b/app/lib/Sage/Template/Wrapper.php @@ -1,11 +1,11 @@ =5.5.0", + "php": ">=5.4.0", "composer/installers": "~1.0" } } From 2911c3e0154ec1bc8d1c6329a76079f6d832229b Mon Sep 17 00:00:00 2001 From: QWp6t Date: Fri, 18 Dec 2015 19:06:59 -0800 Subject: [PATCH 03/82] Update Composer.lock --- composer.lock | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/composer.lock b/composer.lock index 6f0dea204d..70ca3eca39 100644 --- a/composer.lock +++ b/composer.lock @@ -4,8 +4,8 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "hash": "85f4aee59d18d093f8e3a52b8a70f766", - "content-hash": "75ad99c892e1d82404c58fe3bd989585", + "hash": "750e0d8e05f32cf6bb431d9406037c7a", + "content-hash": "d0ce163b056002fe67c8e8036573e276", "packages": [ { "name": "composer/installers", @@ -113,7 +113,7 @@ "prefer-stable": false, "prefer-lowest": false, "platform": { - "php": ">=5.5.0" + "php": ">=5.4.0" }, "platform-dev": [] } From 9283bbbfb3c9555145ccf191723874aa95707864 Mon Sep 17 00:00:00 2001 From: QWp6t Date: Fri, 18 Dec 2015 19:26:54 -0800 Subject: [PATCH 04/82] Fix: page title not displaying --- templates/partials/page-header.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/partials/page-header.php b/templates/partials/page-header.php index 0f1a21cdfc..b48856048d 100644 --- a/templates/partials/page-header.php +++ b/templates/partials/page-header.php @@ -1,3 +1,3 @@ From f752470b337ef6e063055cc99add496f5953e416 Mon Sep 17 00:00:00 2001 From: QWp6t Date: Sat, 19 Dec 2015 16:52:05 -0800 Subject: [PATCH 05/82] Rename app to src --- .travis.yml | 2 +- composer.json | 10 +++++----- composer.lock | 2 +- gulpfile.js | 2 +- {app => src}/admin.php | 0 {app => src}/filters.php | 0 {app => src}/helpers.php | 0 {app => src}/lib/Sage/Asset.php | 0 {app => src}/lib/Sage/Assets/JsonManifest.php | 0 {app => src}/lib/Sage/Assets/ManifestInterface.php | 0 {app => src}/lib/Sage/Template.php | 0 {app => src}/lib/Sage/Template/Wrapper.php | 0 {app => src}/lib/Sage/Template/WrapperInterface.php | 0 {app => src}/setup.php | 0 14 files changed, 8 insertions(+), 8 deletions(-) rename {app => src}/admin.php (100%) rename {app => src}/filters.php (100%) rename {app => src}/helpers.php (100%) rename {app => src}/lib/Sage/Asset.php (100%) rename {app => src}/lib/Sage/Assets/JsonManifest.php (100%) rename {app => src}/lib/Sage/Assets/ManifestInterface.php (100%) rename {app => src}/lib/Sage/Template.php (100%) rename {app => src}/lib/Sage/Template/Wrapper.php (100%) rename {app => src}/lib/Sage/Template/WrapperInterface.php (100%) rename {app => src}/setup.php (100%) diff --git a/.travis.yml b/.travis.yml index ac066b908c..22157178c6 100644 --- a/.travis.yml +++ b/.travis.yml @@ -31,4 +31,4 @@ script: - npm run jshint - npm run jscs - phpcs --standard=ruleset.xml --extensions=php --ignore=node_modules,bower_components,vendor -n -s . - - phpmd app text cleancode,codesize,controversial,design,naming,unusedcode + - phpmd src text cleancode,codesize,controversial,design,naming,unusedcode diff --git a/composer.json b/composer.json index 5ce018f5a7..1028a69943 100644 --- a/composer.json +++ b/composer.json @@ -25,13 +25,13 @@ }, "autoload": { "psr-4": { - "Roots\\Sage\\": "app/lib/Sage/" + "Roots\\Sage\\": "src/lib/Sage/" }, "files": [ - "app/helpers.php", - "app/setup.php", - "app/filters.php", - "app/admin.php" + "src/helpers.php", + "src/setup.php", + "src/filters.php", + "src/admin.php" ] }, "require": { diff --git a/composer.lock b/composer.lock index 70ca3eca39..17854c8c39 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "hash": "750e0d8e05f32cf6bb431d9406037c7a", + "hash": "7bb0b8d676ed7c711aca81f0c9e65355", "content-hash": "d0ce163b056002fe67c8e8036573e276", "packages": [ { diff --git a/gulpfile.js b/gulpfile.js index c7df729dc9..d14c36ffb3 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -244,7 +244,7 @@ gulp.task('clean', require('del').bind(null, [path.dist])); // See: http://www.browsersync.io gulp.task('watch', function() { browserSync.init({ - files: ['{app,templates}/**/*.php'], + files: ['{src,templates}/**/*.php'], proxy: config.devUrl, snippetOptions: { whitelist: ['/wp-admin/admin-ajax.php'], diff --git a/app/admin.php b/src/admin.php similarity index 100% rename from app/admin.php rename to src/admin.php diff --git a/app/filters.php b/src/filters.php similarity index 100% rename from app/filters.php rename to src/filters.php diff --git a/app/helpers.php b/src/helpers.php similarity index 100% rename from app/helpers.php rename to src/helpers.php diff --git a/app/lib/Sage/Asset.php b/src/lib/Sage/Asset.php similarity index 100% rename from app/lib/Sage/Asset.php rename to src/lib/Sage/Asset.php diff --git a/app/lib/Sage/Assets/JsonManifest.php b/src/lib/Sage/Assets/JsonManifest.php similarity index 100% rename from app/lib/Sage/Assets/JsonManifest.php rename to src/lib/Sage/Assets/JsonManifest.php diff --git a/app/lib/Sage/Assets/ManifestInterface.php b/src/lib/Sage/Assets/ManifestInterface.php similarity index 100% rename from app/lib/Sage/Assets/ManifestInterface.php rename to src/lib/Sage/Assets/ManifestInterface.php diff --git a/app/lib/Sage/Template.php b/src/lib/Sage/Template.php similarity index 100% rename from app/lib/Sage/Template.php rename to src/lib/Sage/Template.php diff --git a/app/lib/Sage/Template/Wrapper.php b/src/lib/Sage/Template/Wrapper.php similarity index 100% rename from app/lib/Sage/Template/Wrapper.php rename to src/lib/Sage/Template/Wrapper.php diff --git a/app/lib/Sage/Template/WrapperInterface.php b/src/lib/Sage/Template/WrapperInterface.php similarity index 100% rename from app/lib/Sage/Template/WrapperInterface.php rename to src/lib/Sage/Template/WrapperInterface.php diff --git a/app/setup.php b/src/setup.php similarity index 100% rename from app/setup.php rename to src/setup.php From c9ef232ec1ff33e89bf64d53e53eb1b2fa6a2eb7 Mon Sep 17 00:00:00 2001 From: QWp6t Date: Sat, 19 Dec 2015 22:31:32 -0800 Subject: [PATCH 06/82] bootstrap 4 --- assets/styles/common/_variables.scss | 4 +--- assets/styles/components/_comments.scss | 2 +- assets/styles/components/_grid.scss | 16 ++++++++++---- assets/styles/components/_wp-classes.scss | 12 +++++----- assets/styles/layouts/_header.scss | 6 +++++ assets/styles/main.scss | 2 +- bower.json | 27 ++--------------------- 7 files changed, 29 insertions(+), 40 deletions(-) diff --git a/assets/styles/common/_variables.scss b/assets/styles/common/_variables.scss index 7a0eb40847..3a1ae7a760 100644 --- a/assets/styles/common/_variables.scss +++ b/assets/styles/common/_variables.scss @@ -1,7 +1,5 @@ -// Glyphicons font path -$icon-font-path: "../fonts/"; - // Grid settings +$enable-flex: true; $main-sm-columns: 12; $sidebar-sm-columns: 4; diff --git a/assets/styles/components/_comments.scss b/assets/styles/components/_comments.scss index 29ec32c8ce..4184591cad 100644 --- a/assets/styles/components/_comments.scss +++ b/assets/styles/components/_comments.scss @@ -1,5 +1,5 @@ .comment-list { - @include list-unstyled; + @extend .list-unstyled; } .comment-list ol { list-style: none; diff --git a/assets/styles/components/_grid.scss b/assets/styles/components/_grid.scss index b6e5199cdd..fb3e829a3c 100644 --- a/assets/styles/components/_grid.scss +++ b/assets/styles/components/_grid.scss @@ -1,10 +1,18 @@ // Grid system .main { - @include make-sm-column($main-sm-columns); - .sidebar-primary & { - @include make-sm-column($main-sm-columns - $sidebar-sm-columns); + @include make-col(); + + @include media-breakpoint-up(sm) { + @include make-col-span($main-sm-columns); + .sidebar-primary & { + @include make-col-span($main-sm-columns - $sidebar-sm-columns); + } } } .sidebar { - @include make-sm-column($sidebar-sm-columns); + @include make-col(); + + @include media-breakpoint-up(sm) { + @include make-col-span($sidebar-sm-columns); + } } diff --git a/assets/styles/components/_wp-classes.scss b/assets/styles/components/_wp-classes.scss index edbb835a84..106aa76f48 100644 --- a/assets/styles/components/_wp-classes.scss +++ b/assets/styles/components/_wp-classes.scss @@ -10,23 +10,23 @@ } .aligncenter { display: block; - margin: ($line-height-computed / 2) auto; + margin: ($spacer / 2) auto; height: auto; } .alignleft, .alignright { - margin-bottom: ($line-height-computed / 2); + margin-bottom: ($spacer / 2); height: auto; } -@media (min-width: $screen-sm-min) { +@include media-breakpoint-up(sm) { // Only float if not on an extra small device .alignleft { float: left; - margin-right: ($line-height-computed / 2); + margin-right: ($spacer / 2); } .alignright { float: right; - margin-left: ($line-height-computed / 2); + margin-left: ($spacer / 2); } } @@ -35,7 +35,7 @@ @extend .thumbnail; } .wp-caption-text { - padding: $thumbnail-caption-padding; + padding: $thumbnail-padding; } // Text meant only for screen readers diff --git a/assets/styles/layouts/_header.scss b/assets/styles/layouts/_header.scss index e69de29bb2..2ad19563ea 100644 --- a/assets/styles/layouts/_header.scss +++ b/assets/styles/layouts/_header.scss @@ -0,0 +1,6 @@ +.banner .nav li { + @extend .nav-item; +} +.banner .nav a { + @extend .nav-link; +} diff --git a/assets/styles/main.scss b/assets/styles/main.scss index cecbd4b1cd..7ae1198a85 100644 --- a/assets/styles/main.scss +++ b/assets/styles/main.scss @@ -2,7 +2,7 @@ // Automatically injected Bower dependencies via wiredep (never manually edit this block) // bower:scss -@import "../../bower_components/bootstrap-sass/assets/stylesheets/_bootstrap.scss"; +@import "../../bower_components/bootstrap/scss/bootstrap.scss"; // endbower @import "common/global"; diff --git a/bower.json b/bower.json index 72132a89f1..0d79283ef9 100644 --- a/bower.json +++ b/bower.json @@ -7,30 +7,7 @@ "license": "MIT", "private": true, "dependencies": { - "bootstrap-sass": "3.3.6" - }, - "overrides": { - "bootstrap-sass": { - "main": [ - "./assets/stylesheets/_bootstrap.scss", - "./assets/javascripts/bootstrap/transition.js", - "./assets/javascripts/bootstrap/alert.js", - "./assets/javascripts/bootstrap/button.js", - "./assets/javascripts/bootstrap/carousel.js", - "./assets/javascripts/bootstrap/collapse.js", - "./assets/javascripts/bootstrap/dropdown.js", - "./assets/javascripts/bootstrap/modal.js", - "./assets/javascripts/bootstrap/tooltip.js", - "./assets/javascripts/bootstrap/popover.js", - "./assets/javascripts/bootstrap/scrollspy.js", - "./assets/javascripts/bootstrap/tab.js", - "./assets/javascripts/bootstrap/affix.js", - "./assets/fonts/bootstrap/glyphicons-halflings-regular.eot", - "./assets/fonts/bootstrap/glyphicons-halflings-regular.svg", - "./assets/fonts/bootstrap/glyphicons-halflings-regular.ttf", - "./assets/fonts/bootstrap/glyphicons-halflings-regular.woff", - "./assets/fonts/bootstrap/glyphicons-halflings-regular.woff2" - ] - } + "bootstrap": "git://github.com/twbs/bootstrap.git#v4-dev", + "tether": "^1.1.1" } } From e51e41e0eb547e18aa0eb316af92a308288e130f Mon Sep 17 00:00:00 2001 From: QWp6t Date: Sun, 20 Dec 2015 02:12:18 -0800 Subject: [PATCH 07/82] Update dependencies, switch to eslint --- .eslintrc | 16 +++++++++ .jscsrc | 95 ---------------------------------------------------- .jshintrc | 15 --------- .travis.yml | 5 ++- gulpfile.js | 26 +++++++------- package.json | 34 +++++++++---------- 6 files changed, 47 insertions(+), 144 deletions(-) create mode 100644 .eslintrc delete mode 100644 .jscsrc delete mode 100644 .jshintrc diff --git a/.eslintrc b/.eslintrc new file mode 100644 index 0000000000..95a8def2e9 --- /dev/null +++ b/.eslintrc @@ -0,0 +1,16 @@ +{ + "root": true, + "extends": "eslint:recommended", + "globals": { + "wp": true, + }, + "env": { + "browser": true, + "jquery": true, + "node": true, + "amd": true + }, + "rules": { + "no-console": 0 + } +} diff --git a/.jscsrc b/.jscsrc deleted file mode 100644 index 824aeb1813..0000000000 --- a/.jscsrc +++ /dev/null @@ -1,95 +0,0 @@ -{ - "requireCurlyBraces": [ - "if", - "else", - "for", - "while", - "do", - "try", - "catch" - ], - "requireOperatorBeforeLineBreak": true, - "requireCamelCaseOrUpperCaseIdentifiers": true, - "maximumLineLength": { - "value": 80, - "allowComments": true, - "allowRegex": true - }, - "validateIndentation": 2, - "validateQuoteMarks": "'", - "disallowMultipleLineStrings": true, - "disallowMixedSpacesAndTabs": true, - "disallowTrailingWhitespace": true, - "disallowSpaceAfterPrefixUnaryOperators": true, - "disallowMultipleVarDecl": true, - "disallowKeywordsOnNewLine": [ - "else" - ], - "requireSpaceAfterKeywords": [ - "if", - "else", - "for", - "while", - "do", - "switch", - "return", - "try", - "catch" - ], - "requireSpaceBeforeBinaryOperators": [ - "=", - "+=", - "-=", - "*=", - "/=", - "%=", - "<<=", - ">>=", - ">>>=", - "&=", - "|=", - "^=", - "+=", - "+", - "-", - "*", - "/", - "%", - "<<", - ">>", - ">>>", - "&", - "|", - "^", - "&&", - "||", - "===", - "==", - ">=", - "<=", - "<", - ">", - "!=", - "!==" - ], - "requireSpaceAfterBinaryOperators": true, - "requireSpacesInConditionalExpression": true, - "requireSpaceBeforeBlockStatements": true, - "requireSpacesInForStatement": true, - "requireLineFeedAtFileEnd": true, - "requireSpacesInFunctionExpression": { - "beforeOpeningCurlyBrace": true - }, - "disallowSpacesInAnonymousFunctionExpression": { - "beforeOpeningRoundBrace": true - }, - "disallowSpacesInsideObjectBrackets": "all", - "disallowSpacesInsideArrayBrackets": "all", - "disallowSpacesInsideParentheses": true, - "jsDoc": { - "checkParamNames": true, - "requireParamTypes": true - }, - "disallowMultipleLineBreaks": true, - "disallowNewlineBeforeBlockStatements": true -} diff --git a/.jshintrc b/.jshintrc deleted file mode 100644 index 02b1ec42bc..0000000000 --- a/.jshintrc +++ /dev/null @@ -1,15 +0,0 @@ -{ - "bitwise": true, - "browser": true, - "curly": true, - "eqeqeq": true, - "eqnull": true, - "esnext": true, - "immed": true, - "jquery": true, - "latedef": true, - "newcap": true, - "noarg": true, - "node": true, - "strict": false -} diff --git a/.travis.yml b/.travis.yml index 22157178c6..f9d7d43f61 100644 --- a/.travis.yml +++ b/.travis.yml @@ -18,7 +18,7 @@ cache: install: - npm install -g npm@latest - - npm install -g bower gulp jscs + - npm install -g bower gulp eslint - npm install - composer self-update && composer --version - export PATH="$HOME/.composer/vendor/bin:$PATH" @@ -28,7 +28,6 @@ install: script: - npm run build - - npm run jshint - - npm run jscs + - npm run lint - phpcs --standard=ruleset.xml --extensions=php --ignore=node_modules,bower_components,vendor -n -s . - phpmd src text cleancode,codesize,controversial,design,naming,unusedcode diff --git a/gulpfile.js b/gulpfile.js index d14c36ffb3..6c6874a1be 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -8,7 +8,7 @@ var flatten = require('gulp-flatten'); var gulp = require('gulp'); var gulpif = require('gulp-if'); var imagemin = require('gulp-imagemin'); -var jshint = require('gulp-jshint'); +var eslint = require('gulp-eslint'); var lazypipe = require('lazypipe'); var less = require('gulp-less'); var merge = require('merge-stream'); @@ -58,8 +58,8 @@ var enabled = { maps: !argv.production, // Fail styles task on error when `--production` failStyleTask: argv.production, - // Fail due to JSHint warnings only when `--production` - failJSHint: argv.production, + // Fail due to ESLint warnings only when `--production` + failESLint: argv.production, // Strip debug statments from javascript when `--production` stripJSDebug: argv.production }; @@ -184,9 +184,9 @@ gulp.task('styles', ['wiredep'], function() { }); // ### Scripts -// `gulp scripts` - Runs JSHint then compiles, combines, and optimizes Bower JS +// `gulp scripts` - Runs ESLint then compiles, combines, and optimizes Bower JS // and project JS. -gulp.task('scripts', ['jshint'], function() { +gulp.task('scripts', ['lint'], function() { var merged = merge(); manifest.forEachDependency('js', function(dep) { merged.add( @@ -221,15 +221,15 @@ gulp.task('images', function() { .pipe(browserSync.stream()); }); -// ### JSHint -// `gulp jshint` - Lints configuration JSON and project JS. -gulp.task('jshint', function() { +// ### ESLint +// `gulp lint` - Lints configuration JSON and project JS. +gulp.task('lint', function() { return gulp.src([ - 'bower.json', 'gulpfile.js' + 'gulpfile.js' ].concat(project.js)) - .pipe(jshint()) - .pipe(jshint.reporter('jshint-stylish')) - .pipe(gulpif(enabled.failJSHint, jshint.reporter('fail'))); + .pipe(eslint()) + .pipe(eslint.format()) + .pipe(gulpif(enabled.failESLint, eslint.failAfterError())); }); // ### Clean @@ -252,7 +252,7 @@ gulp.task('watch', function() { } }); gulp.watch([path.source + 'styles/**/*'], ['styles']); - gulp.watch([path.source + 'scripts/**/*'], ['jshint', 'scripts']); + gulp.watch([path.source + 'scripts/**/*'], ['lint', 'scripts']); gulp.watch([path.source + 'fonts/**/*'], ['fonts']); gulp.watch([path.source + 'images/**/*'], ['images']); gulp.watch(['bower.json', 'assets/manifest.json'], ['build']); diff --git a/package.json b/package.json index 40b1c12eb5..e333c90a8b 100644 --- a/package.json +++ b/package.json @@ -19,8 +19,7 @@ ], "scripts": { "build": "bower install && gulp", - "jshint": "gulp jshint", - "jscs": "jscs gulpfile.js assets/scripts/*.js" + "lint": "gulp lint" }, "engines": { "node": ">= 0.12.0", @@ -28,31 +27,30 @@ }, "devDependencies": { "asset-builder": "^1.1.0", - "browser-sync": "^2.8.2", - "del": "^1.2.1", + "browser-sync": "^2.10.1", + "del": "^2.2.0", "gulp": "^3.9.0", - "gulp-autoprefixer": "^2.3.1", + "gulp-autoprefixer": "^3.1.0", "gulp-changed": "^1.3.0", "gulp-concat": "^2.6.0", "gulp-cssnano": "^2.1.0", - "gulp-flatten": "0.1.1", - "gulp-if": "^1.2.5", - "gulp-imagemin": "^2.3.0", - "gulp-jshint": "^1.11.2", - "gulp-less": "^3.0.3", + "gulp-eslint": "^1.1.1", + "gulp-flatten": "0.2.0", + "gulp-if": "^2.0.0", + "gulp-imagemin": "^2.4.0", + "gulp-less": "^3.0.5", "gulp-plumber": "^1.0.1", "gulp-rename": "^1.2.2", - "gulp-rev": "^6.0.0", - "gulp-sass": "^2.0.1", - "gulp-sourcemaps": "^1.5.2", - "gulp-uglify": "^1.2.0", + "gulp-rev": "^6.0.1", + "gulp-sass": "^2.1.1", + "gulp-sourcemaps": "^1.6.0", + "gulp-uglify": "^1.5.1", "imagemin-pngcrush": "^4.1.0", - "jshint-stylish": "^2.0.1", "lazypipe": "^1.0.1", "merge-stream": "^1.0.0", - "minimist": "^1.1.3", - "run-sequence": "^1.1.2", + "minimist": "^1.2.0", + "run-sequence": "^1.1.5", "traverse": "^0.6.6", - "wiredep": "^2.2.2" + "wiredep": "^3.0.0" } } From 8712dc8e0238e7bac46cc960ddee95136a93fbe0 Mon Sep 17 00:00:00 2001 From: QWp6t Date: Sun, 20 Dec 2015 08:49:56 -0800 Subject: [PATCH 08/82] Update node in travis, remove unsupported php Note: We specify CXX env because v8 requires a C++11 compiler --- .travis.yml | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/.travis.yml b/.travis.yml index f9d7d43f61..e66ddeebc8 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,24 +1,37 @@ sudo: false language: php php: - - nightly + - 7.0 - 5.6 - 5.5 - - 5.4 - - hhvm + +env: + - TRAVIS_NODE_VERSION="4.2" CXX="g++-4.8" + - TRAVIS_NODE_VERSION="5.3" CXX="g++-4.8" matrix: allow_failures: - - php: nightly + - php: 5.5 + +addons: + apt: + sources: + - ubuntu-toolchain-r-test + packages: + - g++-4.8 cache: directories: - bower_components - node_modules + - vendor install: + - source ~/.nvm/nvm.sh && nvm install $TRAVIS_NODE_VERSION - npm install -g npm@latest - npm install -g bower gulp eslint + - node -v && npm -v && bower -v && gulp -v + - npm rebuild - npm install - composer self-update && composer --version - export PATH="$HOME/.composer/vendor/bin:$PATH" @@ -28,6 +41,5 @@ install: script: - npm run build - - npm run lint - phpcs --standard=ruleset.xml --extensions=php --ignore=node_modules,bower_components,vendor -n -s . - phpmd src text cleancode,codesize,controversial,design,naming,unusedcode From 21210309b298f85a22f7a5162f8acd34a27c4844 Mon Sep 17 00:00:00 2001 From: Stephen Edgar Date: Mon, 21 Dec 2015 14:51:32 +1100 Subject: [PATCH 09/82] Add PHP 7.x "nightlies" to Travis CI and allow to fail --- .travis.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.travis.yml b/.travis.yml index e66ddeebc8..fa0403e870 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,6 +4,7 @@ php: - 7.0 - 5.6 - 5.5 + - nightly env: - TRAVIS_NODE_VERSION="4.2" CXX="g++-4.8" @@ -12,6 +13,7 @@ env: matrix: allow_failures: - php: 5.5 + - php: nightly addons: apt: From d217ba6f57f5e6ce0329bf936e950dd212308ca5 Mon Sep 17 00:00:00 2001 From: Ben Word Date: Sat, 26 Dec 2015 17:05:26 -0600 Subject: [PATCH 10/82] Remove comment-reply JS --- src/setup.php | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/setup.php b/src/setup.php index 1127939e41..3ea0f6281d 100644 --- a/src/setup.php +++ b/src/setup.php @@ -87,10 +87,5 @@ */ add_action('wp_enqueue_scripts', function () { wp_enqueue_style('sage/css', asset_path('styles/main.css'), false, null); - - if (is_single() && comments_open() && get_option('thread_comments')) { - wp_enqueue_script('comment-reply'); - } - wp_enqueue_script('sage/js', asset_path('scripts/main.js'), ['jquery'], null, true); }, 100); From fa0e51faa47d6d4769b4e8e2d2a08845a27ecf4e Mon Sep 17 00:00:00 2001 From: Ben Word Date: Sat, 26 Dec 2015 17:13:00 -0600 Subject: [PATCH 11/82] Update asset handles --- src/setup.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/setup.php b/src/setup.php index 3ea0f6281d..99fe15f284 100644 --- a/src/setup.php +++ b/src/setup.php @@ -86,6 +86,6 @@ * Theme assets */ add_action('wp_enqueue_scripts', function () { - wp_enqueue_style('sage/css', asset_path('styles/main.css'), false, null); - wp_enqueue_script('sage/js', asset_path('scripts/main.js'), ['jquery'], null, true); + wp_enqueue_style('sage/main.css', asset_path('styles/main.css'), false, null); + wp_enqueue_script('sage/main.js', asset_path('scripts/main.js'), ['jquery'], null, true); }, 100); From 67c190fc41947681f1a7066a5c16c10ef6a594be Mon Sep 17 00:00:00 2001 From: Ben Word Date: Sat, 26 Dec 2015 17:23:35 -0600 Subject: [PATCH 12/82] Cleanup --- src/admin.php | 5 +++-- src/filters.php | 7 +++---- src/lib/Sage/Asset.php | 1 - src/lib/Sage/Assets/ManifestInterface.php | 1 - src/lib/Sage/Template.php | 9 +++++++++ src/lib/Sage/Template/Wrapper.php | 3 +-- src/lib/Sage/Template/WrapperInterface.php | 1 - src/setup.php | 19 ++++++++++--------- 8 files changed, 26 insertions(+), 20 deletions(-) diff --git a/src/admin.php b/src/admin.php index 74fa2c480f..6489f8c1f2 100644 --- a/src/admin.php +++ b/src/admin.php @@ -1,9 +1,10 @@ get_setting('blogname')->transport = 'postMessage'; }); @@ -11,5 +12,5 @@ * Customizer JS */ add_action('customize_preview_init', function () { - wp_enqueue_script('sage/customizer', asset_path('scripts/customizer.js'), ['customize-preview'], null, true); + wp_enqueue_script('sage/customizer.js', asset_path('scripts/customizer.js'), ['customize-preview'], null, true); }); diff --git a/src/filters.php b/src/filters.php index a631da64db..1577227d9d 100644 --- a/src/filters.php +++ b/src/filters.php @@ -8,7 +8,7 @@ * @link https://codex.wordpress.org/Conditional_Tags */ add_filter('sage/display_sidebar', function ($display) { - /** The sidebar will NOT be displayed if ANY of the following return true. */ + // The sidebar will NOT be displayed if ANY of the following return true return $display ? !in_array(true, [ is_404(), is_front_page(), @@ -36,15 +36,14 @@ }); /** - * Clean up the_excerpt() + * Add "… Continued" to the excerpt */ add_filter('excerpt_more', function () { return ' … ' . __('Continued', 'sage') . ''; }); - /** - * Use Wrapper by default + * Use theme wrapper */ add_filter('template_include', function ($main) { if (!is_string($main) || !(string) $main) { diff --git a/src/lib/Sage/Asset.php b/src/lib/Sage/Asset.php index 3508ff8729..eb52ce6d7a 100644 --- a/src/lib/Sage/Asset.php +++ b/src/lib/Sage/Asset.php @@ -8,7 +8,6 @@ * @author QWp6t */ class Asset { - public static $dist = '/dist'; /** @var ManifestInterface Currently used manifest */ diff --git a/src/lib/Sage/Assets/ManifestInterface.php b/src/lib/Sage/Assets/ManifestInterface.php index 749185b0e4..714498341b 100644 --- a/src/lib/Sage/Assets/ManifestInterface.php +++ b/src/lib/Sage/Assets/ManifestInterface.php @@ -6,7 +6,6 @@ * @author QWp6t */ interface ManifestInterface { - /** * Get the cache-busted filename * diff --git a/src/lib/Sage/Template.php b/src/lib/Sage/Template.php index 8e828eb95b..d94037fc93 100644 --- a/src/lib/Sage/Template.php +++ b/src/lib/Sage/Template.php @@ -40,6 +40,7 @@ public static function unwrap($slug = '', $context = []) { end(self::$wrappers); $slug = key(self::$wrappers); } + $template = new static(self::$wrappers[$slug]->getTemplate(), $context); unset(self::$wrappers[$slug]); return $template; @@ -61,9 +62,11 @@ public static function unwrap($slug = '', $context = []) { public static function convertParts($template, $delimeter = '-') { $templateParts = explode($delimeter, str_replace('.php', '', (string) $template)); $templates[] = array_shift($templateParts); + foreach ($templateParts as $i => $templatePart) { $templates[] = $templates[$i] . $delimeter . $templatePart; } + return array_reverse($templates); } @@ -102,10 +105,12 @@ public function get() { $context = $this->context; extract($this->context); ob_start(); + if ($template = $this->locate()) { /** @noinspection PhpIncludeInspection */ include $template; } + $this->html = ob_get_clean() ?: ''; return $this->html; } @@ -118,9 +123,11 @@ public function set($template) { $this->templates = self::format($template); return; } + if (!is_string($template) || !(string) $template) { return; } + // At this point, we assume it's something like `content-single.php` or `content-single-audio.php` $this->templates = self::format(self::convertParts($template)); } @@ -135,6 +142,7 @@ protected static function format($templates) { if (substr($template, -4, 4) === '.php') { return $template; } + return $template . '.php'; }, $templates); } @@ -147,6 +155,7 @@ public function locate($templateDir = '') { $templates = array_map(function ($template) use ($templateDir) { return ($templateDir ?: self::$root) . $template; }, $this->templates); + $template = locate_template($templates); return apply_filters('sage/locate_template', $template, $templates) ?: $template; } diff --git a/src/lib/Sage/Template/Wrapper.php b/src/lib/Sage/Template/Wrapper.php index 009b56b07c..6e03fb641a 100644 --- a/src/lib/Sage/Template/Wrapper.php +++ b/src/lib/Sage/Template/Wrapper.php @@ -41,8 +41,7 @@ public function getSlug() { } /** {@inheritdoc} */ - public function getTemplate() - { + public function getTemplate() { return $this->template; } } diff --git a/src/lib/Sage/Template/WrapperInterface.php b/src/lib/Sage/Template/WrapperInterface.php index d7b900458e..6a358eb450 100644 --- a/src/lib/Sage/Template/WrapperInterface.php +++ b/src/lib/Sage/Template/WrapperInterface.php @@ -6,7 +6,6 @@ * @author QWp6t */ interface WrapperInterface { - /** * Get a list of potential wrappers * Useful for passing to WordPress's locate_template() diff --git a/src/setup.php b/src/setup.php index 99fe15f284..bc05d18745 100644 --- a/src/setup.php +++ b/src/setup.php @@ -2,6 +2,14 @@ use Roots\Sage\Template; +/** + * Theme assets + */ +add_action('wp_enqueue_scripts', function () { + wp_enqueue_style('sage/main.css', asset_path('styles/main.css'), false, null); + wp_enqueue_script('sage/main.js', asset_path('scripts/main.js'), ['jquery'], null, true); +}, 100); + /** * Theme setup */ @@ -29,7 +37,7 @@ add_theme_support('title-tag'); /** - * Register wp_nav_menu() menus + * Register navigation menus * @link http://codex.wordpress.org/Function_Reference/register_nav_menus */ register_nav_menus([ @@ -58,7 +66,7 @@ /** * Use main stylesheet for visual editor - * @see /assets/styles/layouts/_tinymce.scss + * @see assets/styles/layouts/_tinymce.scss */ add_editor_style(asset_path('styles/main.css')); }); @@ -82,10 +90,3 @@ register_sidebar($config('Footer')); }); -/** - * Theme assets - */ -add_action('wp_enqueue_scripts', function () { - wp_enqueue_style('sage/main.css', asset_path('styles/main.css'), false, null); - wp_enqueue_script('sage/main.js', asset_path('scripts/main.js'), ['jquery'], null, true); -}, 100); From abeea0f76c793a8283a5ebb5e3f1d08fdc5cf6bb Mon Sep 17 00:00:00 2001 From: Ben Word Date: Sat, 26 Dec 2015 17:34:43 -0600 Subject: [PATCH 13/82] Remove template_part, template_sidebar, temp sidebar fix --- src/helpers.php | 18 ------------------ templates/404.php | 2 +- templates/index.php | 4 ++-- templates/layouts/base.php | 8 ++++---- templates/page.php | 4 ++-- templates/partials/content-search.php | 2 +- templates/partials/content-single.php | 2 +- templates/partials/content.php | 2 +- templates/search.php | 4 ++-- templates/single.php | 2 +- templates/template-custom.php | 4 ++-- 11 files changed, 17 insertions(+), 35 deletions(-) diff --git a/src/helpers.php b/src/helpers.php index 395744a9b6..4a4f0cbc64 100644 --- a/src/helpers.php +++ b/src/helpers.php @@ -15,24 +15,6 @@ function template_unwrap($slug = '', $context = []) { } } -/** - * @param array $context - */ -function template_sidebar($context = []) { - template_part('sidebar', $context); -} - -/** - * @param $template - * @param array $context - */ -function template_part($template, $context = []) { - if ($file = (new Template($template, $context))->locate()) { - /** @noinspection PhpIncludeInspection */ - include $file; - } -} - /** * @param $filename * @return string diff --git a/templates/404.php b/templates/404.php index 23af1ece56..5ef01009db 100644 --- a/templates/404.php +++ b/templates/404.php @@ -1,4 +1,4 @@ - +
diff --git a/templates/index.php b/templates/index.php index 16694b8fda..bb39cccb0e 100644 --- a/templates/index.php +++ b/templates/index.php @@ -1,4 +1,4 @@ - +
@@ -8,7 +8,7 @@ - + diff --git a/templates/layouts/base.php b/templates/layouts/base.php index 54b0de6fbc..e0c8bfe854 100644 --- a/templates/layouts/base.php +++ b/templates/layouts/base.php @@ -1,6 +1,6 @@ > - + >
@@ -18,14 +18,14 @@
diff --git a/templates/page.php b/templates/page.php index 7a1d16710d..dc2adff049 100644 --- a/templates/page.php +++ b/templates/page.php @@ -1,4 +1,4 @@ - - + + diff --git a/templates/partials/content-search.php b/templates/partials/content-search.php index 749f11acd7..2eac1e4e2d 100644 --- a/templates/partials/content-search.php +++ b/templates/partials/content-search.php @@ -1,7 +1,7 @@
>

- +
diff --git a/templates/partials/content-single.php b/templates/partials/content-single.php index 60392e9e48..cd5406e6d2 100644 --- a/templates/partials/content-single.php +++ b/templates/partials/content-single.php @@ -2,7 +2,7 @@
>

- +
diff --git a/templates/partials/content.php b/templates/partials/content.php index 3ae0e4abba..2246a63d5c 100644 --- a/templates/partials/content.php +++ b/templates/partials/content.php @@ -1,7 +1,7 @@
>

- +
diff --git a/templates/search.php b/templates/search.php index e150715b22..f769258c02 100644 --- a/templates/search.php +++ b/templates/search.php @@ -1,4 +1,4 @@ - +
@@ -8,7 +8,7 @@ - + diff --git a/templates/single.php b/templates/single.php index 345b962fb3..8e6e717520 100644 --- a/templates/single.php +++ b/templates/single.php @@ -1 +1 @@ - + diff --git a/templates/template-custom.php b/templates/template-custom.php index 82ef512943..d0bcd124e4 100644 --- a/templates/template-custom.php +++ b/templates/template-custom.php @@ -5,6 +5,6 @@ ?> - - + + From 9eec17dc3f8aad4d2c23bd20fdf1cea1b0d97b66 Mon Sep 17 00:00:00 2001 From: Ben Word Date: Sat, 26 Dec 2015 18:35:40 -0600 Subject: [PATCH 14/82] Fix error --- src/setup.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/setup.php b/src/setup.php index bc05d18745..76b22831dc 100644 --- a/src/setup.php +++ b/src/setup.php @@ -89,4 +89,3 @@ register_sidebar($config('Primary')); register_sidebar($config('Footer')); }); - From f7194cb7c34f20f470006fa5df9a570a1c28a268 Mon Sep 17 00:00:00 2001 From: QWp6t Date: Sun, 27 Dec 2015 13:04:13 -0800 Subject: [PATCH 15/82] Use Kernighan-Ritchie style braces Exclusion of PSR-2 rule for BraceOnSameLine is not enough. We need to specifically force this rule. --- ruleset.xml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/ruleset.xml b/ruleset.xml index 8fb7a9cafb..faf4d39875 100644 --- a/ruleset.xml +++ b/ruleset.xml @@ -39,5 +39,8 @@ - + + + + From d4461fa1e449faf057ae42d88bc83a60e2c33716 Mon Sep 17 00:00:00 2001 From: Ben Word Date: Sun, 27 Dec 2015 17:18:03 -0600 Subject: [PATCH 16/82] Remove sage.pot --- lang/sage.pot | 103 -------------------------------------------------- src/setup.php | 6 --- 2 files changed, 109 deletions(-) delete mode 100644 lang/sage.pot diff --git a/lang/sage.pot b/lang/sage.pot deleted file mode 100644 index 1ee2a85261..0000000000 --- a/lang/sage.pot +++ /dev/null @@ -1,103 +0,0 @@ -msgid "" -msgstr "" -"Content-Type: text/plain; charset=UTF-8\n" -"Content-Transfer-Encoding: 8bit\n" - -#: 404.php:4 -msgid "Sorry, but the page you were trying to view does not exist." -msgstr "" - -#: base.php:14 -msgid "" -"You are using an outdated browser. Please upgrade your browser to improve your experience." -msgstr "" - -#: functions.php:22 -msgid "Error locating %s for inclusion" -msgstr "" - -#: index.php:5 search.php:5 -msgid "Sorry, no results were found." -msgstr "" - -#: lib/extras.php:31 -msgid "Continued" -msgstr "" - -#: lib/setup.php:30 -msgid "Primary Navigation" -msgstr "" - -#: lib/setup.php:57 -msgid "Primary" -msgstr "" - -#: lib/setup.php:66 -msgid "Footer" -msgstr "" - -#: lib/titles.php:13 -msgid "Latest Posts" -msgstr "" - -#: lib/titles.php:18 -msgid "Search Results for %s" -msgstr "" - -#: lib/titles.php:20 -msgid "Not Found" -msgstr "" - -#: templates/comments.php:9 -msgctxt "comments title" -msgid "One response to “%2$s”" -msgid_plural "%1$s responses to “%2$s”" -msgstr[0] "" -msgstr[1] "" - -#: templates/comments.php:19 -msgid "← Older comments" -msgstr "" - -#: templates/comments.php:22 -msgid "Newer comments →" -msgstr "" - -#: templates/comments.php:31 -msgid "Comments are closed." -msgstr "" - -#: templates/content-page.php:2 templates/content-single.php:11 -msgid "Pages:" -msgstr "" - -#: templates/entry-meta.php:2 -msgid "By" -msgstr "" - -#. Theme Name of the plugin/theme -msgid "Sage Starter Theme" -msgstr "" - -#. Theme URI of the plugin/theme -msgid "https://roots.io/sage/" -msgstr "" - -#. Description of the plugin/theme -msgid "" -"Sage is a WordPress starter theme. Contribute on GitHub" -msgstr "" - -#. Author of the plugin/theme -msgid "Roots" -msgstr "" - -#. Author URI of the plugin/theme -msgid "https://roots.io/" -msgstr "" - -#. Template Name of the plugin/theme -msgid "Custom Template" -msgstr "" diff --git a/src/setup.php b/src/setup.php index 76b22831dc..145f0fe849 100644 --- a/src/setup.php +++ b/src/setup.php @@ -24,12 +24,6 @@ add_theme_support('soil-nice-search'); add_theme_support('soil-relative-urls'); - /** - * Make theme available for translation - * @link https://github.com/roots/sage-translations Community translations - */ - load_theme_textdomain('sage', get_template_directory() . '/lang'); - /** * Enable plugins to manage the document title * @link http://codex.wordpress.org/Function_Reference/add_theme_support#Title_Tag From 12d6ac3c513b1627d7d93c0917fb9d2f4d8338ce Mon Sep 17 00:00:00 2001 From: QWp6t Date: Sun, 27 Dec 2015 16:44:51 -0800 Subject: [PATCH 17/82] Remove closure from sidebar registration --- ruleset.xml | 2 +- src/setup.php | 27 ++++++++++++++------------- 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/ruleset.xml b/ruleset.xml index faf4d39875..20f716c97b 100644 --- a/ruleset.xml +++ b/ruleset.xml @@ -41,6 +41,6 @@ - + diff --git a/src/setup.php b/src/setup.php index 145f0fe849..0c11e6bc69 100644 --- a/src/setup.php +++ b/src/setup.php @@ -69,17 +69,18 @@ * Register sidebars */ add_action('widgets_init', function () { - $config = function ($name, $id = '') { - return [ - 'name' => __($name, 'sage'), - 'id' => 'sidebar-' . $id ?: sanitize_title($name), - 'before_widget' => '
', - 'after_widget' => '
', - 'before_title' => '

', - 'after_title' => '

' - ]; - }; - - register_sidebar($config('Primary')); - register_sidebar($config('Footer')); + $config = [ + 'before_widget' => '
', + 'after_widget' => '
', + 'before_title' => '

', + 'after_title' => '

' + ]; + register_sidebar([ + 'name' => __('Primary', 'sage'), + 'id' => 'sidebar-primary' + ] + $config); + register_sidebar([ + 'name' => __('Footer', 'sage'), + 'id' => 'sidebar-footer' + ] + $config); }); From 1df3fee0103a5c45aac70fa5e6f36bcf53e439e0 Mon Sep 17 00:00:00 2001 From: QWp6t Date: Sun, 27 Dec 2015 22:07:25 -0800 Subject: [PATCH 18/82] Remove Template class --- src/.editorconfig | 6 + src/filters.php | 3 +- src/helpers.php | 19 ++- src/lib/Sage/Template.php | 162 -------------------- src/lib/Sage/Template/Wrapper.php | 32 ++-- src/lib/Sage/Template/WrapperCollection.php | 73 +++++++++ src/lib/Sage/Template/WrapperInterface.php | 10 +- templates/layouts/base.php | 2 +- 8 files changed, 117 insertions(+), 190 deletions(-) create mode 100644 src/.editorconfig delete mode 100644 src/lib/Sage/Template.php create mode 100644 src/lib/Sage/Template/WrapperCollection.php diff --git a/src/.editorconfig b/src/.editorconfig new file mode 100644 index 0000000000..0fa0fcda8a --- /dev/null +++ b/src/.editorconfig @@ -0,0 +1,6 @@ +# editorconfig.org + +root = false + +[*.php] +indent_size = 2 diff --git a/src/filters.php b/src/filters.php index 1577227d9d..959b782e8e 100644 --- a/src/filters.php +++ b/src/filters.php @@ -49,6 +49,5 @@ if (!is_string($main) || !(string) $main) { return $main; } - $main = basename($main, '.php'); - return Template::wrap(new Wrapper($main, 'layouts/base.php'))->locate(); + return template_wrap(new Wrapper(basename($main))); }, 109); diff --git a/src/helpers.php b/src/helpers.php index 4a4f0cbc64..0ddea2286c 100644 --- a/src/helpers.php +++ b/src/helpers.php @@ -2,17 +2,16 @@ use Roots\Sage\Asset; use Roots\Sage\Assets\JsonManifest; -use Roots\Sage\Template; +use Roots\Sage\Template\WrapperCollection; +use Roots\Sage\Template\WrapperInterface; -/** - * @param string $slug - * @param array $context - */ -function template_unwrap($slug = '', $context = []) { - if ($file = Template::unwrap($slug, $context)->locate()) { - /** @noinspection PhpIncludeInspection */ - include $file; - } +function template_wrap(WrapperInterface $wrapper, $slug = 'base') { + WrapperCollection::add($wrapper, $slug); + return $wrapper->getWrapper(); +} + +function template_unwrap($slug = 'base') { + return WrapperCollection::get($slug)->getTemplate(); } /** diff --git a/src/lib/Sage/Template.php b/src/lib/Sage/Template.php deleted file mode 100644 index d94037fc93..0000000000 --- a/src/lib/Sage/Template.php +++ /dev/null @@ -1,162 +0,0 @@ -getSlug()] = $wrapper; - return new static($wrapper->getWrappers(), $context); - } - - /** - * @param string $slug - * @param array $context - * @return static - */ - public static function unwrap($slug = '', $context = []) { - if (!$slug) { - // If no slug is specified, we grab the most recently wrapped item - end(self::$wrappers); - $slug = key(self::$wrappers); - } - - $template = new static(self::$wrappers[$slug]->getTemplate(), $context); - unset(self::$wrappers[$slug]); - return $template; - } - - /** - * Converts a delimeted template file into an array of parts - * - * Example: - * Template::getConvertedTemplateParts('content-single-audio.php'); - * => ['content-single-audio.php', 'content-single.php', 'content.php'] - * - * The returned value can then be passed to WordPress's locate_template. - * - * @param string $template - * @param string $delimeter - * @return array - */ - public static function convertParts($template, $delimeter = '-') { - $templateParts = explode($delimeter, str_replace('.php', '', (string) $template)); - $templates[] = array_shift($templateParts); - - foreach ($templateParts as $i => $templatePart) { - $templates[] = $templates[$i] . $delimeter . $templatePart; - } - - return array_reverse($templates); - } - - /** - * Template constructor - * @param string|string[] $template - * @param array $context - */ - public function __construct($template, array $context = []) { - $this->set($template); - $this->context = $context; - } - - /** - * @return string HTML - * @see get - */ - public function __toString() { - return $this->get(); - } - - /** - * Echoes the output HTML - * @see get - */ - public function render() { - echo $this->get(); - } - - /** - * @return string HTML - * @SuppressWarnings(PHPMD.UnusedLocalVariable) - */ - public function get() { - /** @noinspection PhpUnusedLocalVariableInspection $context is passed to the included template */ - $context = $this->context; - extract($this->context); - ob_start(); - - if ($template = $this->locate()) { - /** @noinspection PhpIncludeInspection */ - include $template; - } - - $this->html = ob_get_clean() ?: ''; - return $this->html; - } - - /** - * @param string[]|string $template - */ - public function set($template) { - if (is_array($template)) { - $this->templates = self::format($template); - return; - } - - if (!is_string($template) || !(string) $template) { - return; - } - - // At this point, we assume it's something like `content-single.php` or `content-single-audio.php` - $this->templates = self::format(self::convertParts($template)); - } - - /** - * Ensures that each template in $this->templates is appended with `.php` - * @param $templates - * @return array - */ - protected static function format($templates) { - return array_map(function ($template) { - if (substr($template, -4, 4) === '.php') { - return $template; - } - - return $template . '.php'; - }, $templates); - } - - /** - * @param string $templateDir Specify a template directory relative to your theme directory; e.g., `templates/`, `templates/partials/`, `woocommerce/` - * @return string Filename - */ - public function locate($templateDir = '') { - $templates = array_map(function ($template) use ($templateDir) { - return ($templateDir ?: self::$root) . $template; - }, $this->templates); - - $template = locate_template($templates); - return apply_filters('sage/locate_template', $template, $templates) ?: $template; - } -} diff --git a/src/lib/Sage/Template/Wrapper.php b/src/lib/Sage/Template/Wrapper.php index 6e03fb641a..c62bb58af8 100644 --- a/src/lib/Sage/Template/Wrapper.php +++ b/src/lib/Sage/Template/Wrapper.php @@ -13,26 +13,37 @@ class Wrapper implements WrapperInterface { protected $template = ''; /** @var string[] Array of template wrappers; e.g., `base-singular.php`, `base-page.php`, `base.php` */ - protected $wrappers = []; + protected $wrapper = []; + + /** @var string[] Cache template locations */ + protected static $locations = []; /** * Wrapper constructor * - * @param string $templateSlug Template slug, typically from Template Heirarchy; e.g., `page`, `single`, `singular` + * @param string $template Template file, as from Template Heirarchy; e.g., `page.php`, `single.php`, `singular.php` * @param string $base Wrapper's base template, this is what will wrap around $template */ - public function __construct($templateSlug, $base = 'layouts/base.php') { + public function __construct($template, $base = 'layouts/base.php') { $this->slug = sanitize_title(basename($base, '.php')); - $this->wrappers = [$base]; - $this->template = $templateSlug; + $this->wrapper = [$base]; + $this->template = $template; $str = substr($base, 0, -4); - array_unshift($this->wrappers, sprintf($str . '-%s.php', $templateSlug)); + array_unshift($this->wrapper, sprintf($str . '-%s.php', basename($template, '.php'))); + } + + /** + * @return string + * @see getTemplate + */ + public function __toString() { + return $this->getTemplate(); } /** {@inheritdoc} */ - public function getWrappers() { - $this->wrappers = apply_filters('sage/wrap_' . $this->slug, $this->wrappers) ?: $this->wrappers; - return $this->wrappers; + public function getWrapper() { + $wrappers = apply_filters('sage/wrap_' . $this->slug, $this->wrapper) ?: $this->wrapper; + return locate_template($wrappers); } /** {@inheritdoc} */ @@ -42,6 +53,7 @@ public function getSlug() { /** {@inheritdoc} */ public function getTemplate() { - return $this->template; + $template = apply_filters('sage/unwrap_' . $this->slug, $this->template) ?: $this->template; + return locate_template($template); } } diff --git a/src/lib/Sage/Template/WrapperCollection.php b/src/lib/Sage/Template/WrapperCollection.php new file mode 100644 index 0000000000..b50fd75f85 --- /dev/null +++ b/src/lib/Sage/Template/WrapperCollection.php @@ -0,0 +1,73 @@ +getSlug(); + if (self::instance()->exists($slug) && !$overwriteIfExists) { + throw new \Exception("Wrapper $slug already exists."); + } + self::instance()->wrappers[$slug] = $wrapper; + return self::instance(); + } + + /** + * @param string $slug + * @return $this + */ + public static function remove($slug) { + unset(self::instance()->wrappers[$slug]); + return self::instance(); + } + + /** + * @param string $slug + * @return null|WrapperInterface + */ + public static function get($slug) { + return isset(self::instance()->wrappers[$slug]) ? self::instance()->wrappers[$slug] : null; + } + + /** + * @return string[] Slugs of wrappers in collection + */ + public static function wrappers() { + return array_keys(self::instance()->wrappers); + } + + /** + * @param $slug + * @return bool + */ + public static function exists($slug) { + return isset(self::instance()->wrappers[$slug]); + } +} diff --git a/src/lib/Sage/Template/WrapperInterface.php b/src/lib/Sage/Template/WrapperInterface.php index 6a358eb450..b94cf08bbf 100644 --- a/src/lib/Sage/Template/WrapperInterface.php +++ b/src/lib/Sage/Template/WrapperInterface.php @@ -6,16 +6,16 @@ * @author QWp6t */ interface WrapperInterface { + /** - * Get a list of potential wrappers - * Useful for passing to WordPress's locate_template() + * Get wrapper template file * - * @return string[] List of wrappers; e.g., `base-page.php`, `base.php` + * @return string Wrapper template (FQPN of, e.g., `base-page.php`, `base.php`) */ - public function getWrappers(); + public function getWrapper(); /** - * @return string Template file that is being wrapped; e.g., `page.php`, `single.php`, `singular.php` + * @return string Wrapped template (FQPN of, e.g., `page.php`, `single.php`, `singular.php`) */ public function getTemplate(); diff --git a/templates/layouts/base.php b/templates/layouts/base.php index e0c8bfe854..7d7346e09c 100644 --- a/templates/layouts/base.php +++ b/templates/layouts/base.php @@ -14,7 +14,7 @@
- +
-
-
+
+
Date: Sat, 6 Aug 2016 18:51:06 -0700 Subject: [PATCH 77/82] Update dependencies, incl Bootstrap 4 alpha 3 --- assets/scripts/main.js | 12 +----------- assets/styles/components/_grid.scss | 12 +++++------- package.json | 18 +++++++++--------- 3 files changed, 15 insertions(+), 27 deletions(-) diff --git a/assets/scripts/main.js b/assets/scripts/main.js index b825c66ab3..7ef154ea33 100644 --- a/assets/scripts/main.js +++ b/assets/scripts/main.js @@ -5,17 +5,7 @@ import home from './routes/Home'; import about_us from './routes/About'; // Import npm dependencies -import 'bootstrap/dist/js/umd/util.js'; -import 'bootstrap/dist/js/umd/alert.js'; -import 'bootstrap/dist/js/umd/button.js'; -import 'bootstrap/dist/js/umd/carousel.js'; -import 'bootstrap/dist/js/umd/collapse.js'; -import 'bootstrap/dist/js/umd/dropdown.js'; -import 'bootstrap/dist/js/umd/modal.js'; -import 'bootstrap/dist/js/umd/scrollspy.js'; -import 'bootstrap/dist/js/umd/tab.js'; -import 'bootstrap/dist/js/umd/tooltip.js'; -import 'bootstrap/dist/js/umd/popover.js'; +import 'bootstrap/dist/js/bootstrap'; // Use this variable to set up the common and page specific functions. If you // rename this variable, you will also need to rename the namespace below. diff --git a/assets/styles/components/_grid.scss b/assets/styles/components/_grid.scss index fb3e829a3c..f5d16873d4 100644 --- a/assets/styles/components/_grid.scss +++ b/assets/styles/components/_grid.scss @@ -1,18 +1,16 @@ // Grid system .main { - @include make-col(); - + @extend %grid-column; @include media-breakpoint-up(sm) { - @include make-col-span($main-sm-columns); + @include make-col($main-sm-columns); .sidebar-primary & { - @include make-col-span($main-sm-columns - $sidebar-sm-columns); + @include make-col($main-sm-columns - $sidebar-sm-columns); } } } .sidebar { - @include make-col(); - + @extend %grid-column; @include media-breakpoint-up(sm) { - @include make-col-span($sidebar-sm-columns); + @include make-col($sidebar-sm-columns); } } diff --git a/package.json b/package.json index cf9caef21a..9e31643731 100644 --- a/package.json +++ b/package.json @@ -41,24 +41,24 @@ "clean-webpack-plugin": "^0.1.8", "css-loader": "^0.23.1", "cssnano": "^3.5.2", - "eslint": "^2.5.1", - "eslint-config-airbnb": "^6.2.0", + "eslint": "^3.2.2", + "eslint-config-airbnb": "^10.0.0", "eslint-loader": "^1.3.0", - "eslint-plugin-react": "^4.2.3", + "eslint-plugin-react": "^6.0.0", "extract-text-webpack-plugin": "^1.0.1", - "file-loader": "^0.8.5", - "image-webpack-loader": "^1.6.3", - "imagemin-pngcrush": "^4.1.0", + "file-loader": "^0.9.0", + "image-webpack-loader": "^2.0.0", + "imagemin-pngcrush": "^5.0.0", "imports-loader": "^0.6.5", "minimist": "^1.2.0", "monkey-hot-loader": "0.0.3", "node-sass": "^3.4.2", "optimize-css-assets-webpack-plugin": "^1.3.0", "postcss": "^5.0.18", - "postcss-loader": "^0.8.0", + "postcss-loader": "^0.9.1", "qs": "^6.1.0", "resolve-url-loader": "^1.4.3", - "sass-loader": "^3.1.1", + "sass-loader": "^4.0.0", "style-loader": "^0.13.0", "url-loader": "^0.5.7", "webpack": "^1.12.14", @@ -67,7 +67,7 @@ }, "dependencies": { "babel-runtime": "^6.5.0", - "bootstrap": "^4.0.0-alpha.2", + "bootstrap": "^4.0.0-alpha.3", "jquery": "^2.1.4", "tether": "^1.2.0" } From 25cfd613785608ba97d5f1e904123901db941924 Mon Sep 17 00:00:00 2001 From: Andrew Lau Date: Mon, 8 Aug 2016 15:16:21 +1000 Subject: [PATCH 78/82] Load tether --- webpack.config.js | 1 + 1 file changed, 1 insertion(+) diff --git a/webpack.config.js b/webpack.config.js index 5b4429413c..53461432f5 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -174,6 +174,7 @@ webpackConfig = { $: 'jquery', jQuery: 'jquery', 'window.jQuery': 'jquery', + 'Tether': 'tether', 'window.Tether': 'tether' }) ], From 4d58f88166b5c1efd78f15ef5f1fbb2ca5f2e344 Mon Sep 17 00:00:00 2001 From: QWp6t Date: Sat, 13 Aug 2016 07:37:14 -0700 Subject: [PATCH 79/82] Squashing asset pipeline bugs and other stuff 1. Update dependencies - Add font-awesome as dependency - Switch to Bootstrap 4 dev branch - Remove eslint airbnb style (we're not using it) 2. Imported images and fonts should go into dist/images and dist/fonts, respectively 3. Only lint our own code, not external code (fixes #1633) --- .eslintrc | 2 +- assets/scripts/main.js | 9 +++++---- assets/styles/common/_variables.scss | 3 +++ assets/styles/main.scss | 1 + package.json | 14 ++++++-------- webpack.config.js | 16 ++++++++-------- 6 files changed, 24 insertions(+), 21 deletions(-) diff --git a/.eslintrc b/.eslintrc index 30a5994f7a..56260bda34 100644 --- a/.eslintrc +++ b/.eslintrc @@ -2,7 +2,7 @@ "root": true, "extends": "eslint:recommended", "globals": { - "wp": true, + "wp": true }, "env": { "browser": true, diff --git a/assets/scripts/main.js b/assets/scripts/main.js index 7ef154ea33..48e9a3fd27 100644 --- a/assets/scripts/main.js +++ b/assets/scripts/main.js @@ -1,12 +1,13 @@ -import $ from 'jquery'; +// import external dependencies +import 'jquery' +import 'bootstrap/dist/js/bootstrap' + +// import local dependencies import Router from './util/router'; import common from './routes/Common'; import home from './routes/Home'; import about_us from './routes/About'; -// Import npm dependencies -import 'bootstrap/dist/js/bootstrap'; - // Use this variable to set up the common and page specific functions. If you // rename this variable, you will also need to rename the namespace below. const routes = { diff --git a/assets/styles/common/_variables.scss b/assets/styles/common/_variables.scss index 3a1ae7a760..72048e193a 100644 --- a/assets/styles/common/_variables.scss +++ b/assets/styles/common/_variables.scss @@ -5,3 +5,6 @@ $sidebar-sm-columns: 4; // Colors $brand-primary: #27ae60; + +// Font Awesome | see: http://fontawesome.io/get-started/ +$fa-font-path: '~font-awesome/fonts'; diff --git a/assets/styles/main.scss b/assets/styles/main.scss index e08d453b0b..d2e5cbcffa 100644 --- a/assets/styles/main.scss +++ b/assets/styles/main.scss @@ -2,6 +2,7 @@ // Import npm dependencies @import "~bootstrap/scss/bootstrap"; +@import "~font-awesome/scss/font-awesome"; @import "common/global"; @import "components/buttons"; diff --git a/package.json b/package.json index 9e31643731..fac425687f 100644 --- a/package.json +++ b/package.json @@ -21,8 +21,7 @@ "build:production": "webpack -p --progress --release", "build": "webpack -d --progress", "watch": "node watch.js --watch", - "lint": "eslint -c .eslintrc assets/scripts watch.js webpack.config.js", - "install": "composer install" + "lint": "eslint -c .eslintrc assets/scripts watch.js webpack.config.js" }, "engines": { "node": ">=4" @@ -34,15 +33,15 @@ "babel-core": "^6.7.4", "babel-eslint": "^6.0.0", "babel-loader": "^6.2.4", - "babel-preset-es2015": "^6.1.18", + "babel-preset-es2015": "^6.13.2", "babel-register": "^6.5.2", + "babel-runtime": "^6.5.0", "body-parser": "^1.14.1", "browser-sync": "^2.11.2", "clean-webpack-plugin": "^0.1.8", "css-loader": "^0.23.1", "cssnano": "^3.5.2", "eslint": "^3.2.2", - "eslint-config-airbnb": "^10.0.0", "eslint-loader": "^1.3.0", "eslint-plugin-react": "^6.0.0", "extract-text-webpack-plugin": "^1.0.1", @@ -66,9 +65,8 @@ "webpack-hot-middleware": "^2.10.0" }, "dependencies": { - "babel-runtime": "^6.5.0", - "bootstrap": "^4.0.0-alpha.3", - "jquery": "^2.1.4", - "tether": "^1.2.0" + "bootstrap": "github:twbs/bootstrap#v4-dev", + "font-awesome": "^4.6.3", + "jquery": "^1.12.4" } } diff --git a/webpack.config.js b/webpack.config.js index 5b4429413c..5a36613be3 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -22,8 +22,8 @@ var scriptsFilename = (argv.release) ? 'scripts/[name]_[hash].js' : 'scripts/[na jsLoader = { test: /\.js$/, - exclude: /(node_modules|bower_components)/, - loaders: [ 'babel?presets[]=es2015&cacheDirectory' ] + exclude: [ /(node_modules|bower_components)(?![/|\\](bootstrap|foundation-sites))/ ], + loaders: [ 'babel?presets[]='+path.resolve('./node_modules/babel-preset-es2015')+'&cacheDirectory' ] }; if (argv.watch) { // '--watch' to add monkey-hot @@ -53,7 +53,7 @@ var assetsPluginProcessOutput = function (assets) { } } return JSON.stringify(results); -} +}; /** * Loop through webpack entry @@ -80,7 +80,7 @@ var addHotMiddleware = function (entry) { } } return results; -} +}; webpackConfig = { context: path.resolve(config.context), @@ -94,7 +94,7 @@ webpackConfig = { preLoaders: [ { test: /\.js?$/, - exclude: /(node_modules|bower_components)/, + include: path.resolve('assets'), loader: 'eslint' } ], @@ -120,7 +120,7 @@ webpackConfig = { test: /\.(png|jpg|jpeg|gif)(\?.*)?$/, loaders: [ 'file?' + qs.stringify({ - name: '[path][name].[ext]' + name: 'images/[name]_[md5:hash:hex:8].[ext]' }), 'image-webpack?' + JSON.stringify({ bypassOnDebug:true, @@ -141,7 +141,7 @@ webpackConfig = { { test: /\.(ttf|eot|svg)(\?.*)?$/, loader: 'file?' + qs.stringify({ - name: '[path][name].[ext]' + name: 'fonts/[name]_[md5:hash:hex:8].[ext]' }) }, { @@ -149,7 +149,7 @@ webpackConfig = { loader: 'url?' + qs.stringify({ limit: 10000, mimetype: "application/font-woff", - name: "[path][name].[ext]" + name: "fonts/[name]_[md5:hash:hex:8].[ext]" }) } ] From b6b0f4b9df4ebd8221b83e38084a9e0cd5ec9f5a Mon Sep 17 00:00:00 2001 From: Ben Word Date: Sun, 14 Aug 2016 14:55:13 -0600 Subject: [PATCH 80/82] Ignore .github dir and .travis.yml for Composer installs --- .gitattributes | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 .gitattributes diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000000..b3f91702ad --- /dev/null +++ b/.gitattributes @@ -0,0 +1,3 @@ +/.github export-ignore +/.gitattributes export-ignore +/.travis.yml export-ignore From 97c1a307ec9245f66356606a84eff181959d581f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrick=20V=C3=A9zina?= Date: Fri, 26 Aug 2016 13:34:52 -0400 Subject: [PATCH 81/82] move assets found in node_modules/ to dist/vendor; simpler assets/config.json (#1697) --- assets/config.json | 9 ++------- webpack.config.js | 39 +++++++++++++++++++++++++++------------ 2 files changed, 29 insertions(+), 19 deletions(-) diff --git a/assets/config.json b/assets/config.json index c394d8e338..88d3ab7616 100644 --- a/assets/config.json +++ b/assets/config.json @@ -1,5 +1,4 @@ { - "context": "assets", "entry": { "main": [ "./scripts/main.js", @@ -9,10 +8,6 @@ "./scripts/customizer.js" ] }, - "output": { - "path": "dist", - "publicPath": "/app/themes/sage/dist/" - }, - "devUrl": "http://example.dev", - "devPort": 3000 + "publicPath": "/app/themes/sage", + "devUrl": "http://example.dev" } diff --git a/webpack.config.js b/webpack.config.js index c738ed43ee..13658fd7a4 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -17,6 +17,8 @@ var config = require('./assets/config'); var scriptsFilename = (argv.release) ? 'scripts/[name]_[hash].js' : 'scripts/[name].js', stylesFilename = (argv.release) ? 'styles/[name]_[hash].css' : 'styles/[name].css', sourceMapQueryStr = (argv.release) ? '-sourceMap' : '+sourceMap', + assets = 'assets/', + dist = 'dist/', jsLoader, webpackConfig; @@ -83,18 +85,18 @@ var addHotMiddleware = function (entry) { }; webpackConfig = { - context: path.resolve(config.context), + context: path.resolve(assets), entry: config.entry, output: { - path: path.join(__dirname, config.output.path), - publicPath: config.output.publicPath, + path: path.join(__dirname, dist), + publicPath: path.join(config.publicPath, dist), filename: scriptsFilename }, module: { preLoaders: [ { test: /\.js?$/, - include: path.resolve('assets'), + include: path.resolve(assets), loader: 'eslint' } ], @@ -102,6 +104,7 @@ webpackConfig = { jsLoader, { test: /\.css$/, + include: path.resolve(assets), loader: ExtractTextPlugin.extract('style', [ 'css?' + sourceMapQueryStr, 'postcss' @@ -109,6 +112,7 @@ webpackConfig = { }, { test: /\.scss$/, + include: path.resolve(assets), loader: ExtractTextPlugin.extract('style', [ 'css?' + sourceMapQueryStr, 'postcss', @@ -117,13 +121,14 @@ webpackConfig = { ]) }, { - test: /\.(png|jpg|jpeg|gif)(\?.*)?$/, + test: /\.(png|jpg|jpeg|gif|svg)(\?.*)?$/, + include: path.resolve(assets), loaders: [ 'file?' + qs.stringify({ - name: 'images/[name]_[md5:hash:hex:8].[ext]' + name: '[path][name].[ext]' }), 'image-webpack?' + JSON.stringify({ - bypassOnDebug:true, + bypassOnDebug: true, progressive: true, optimizationLevel: 7, interlaced: true, @@ -139,17 +144,27 @@ webpackConfig = { ] }, { - test: /\.(ttf|eot|svg)(\?.*)?$/, + test: /\.(ttf|eot)(\?.*)?$/, + include: path.resolve(assets), loader: 'file?' + qs.stringify({ - name: 'fonts/[name]_[md5:hash:hex:8].[ext]' + name: '[path][name]_[md5:hash:hex:8].[ext]' }) }, { test: /\.woff(2)?(\?.*)?$/, + include: path.resolve(assets), loader: 'url?' + qs.stringify({ limit: 10000, mimetype: "application/font-woff", - name: "fonts/[name]_[md5:hash:hex:8].[ext]" + name: "[path][name]_[md5:hash:hex:8].[ext]" + }) + }, + // Use file-loader for node_modules/ assets + { + test: /\.(ttf|eot|woff(2)?|png|jpg|jpeg|gif|svg)(\?.*)?$/, + include: /node_modules/, + loader: 'file?' + qs.stringify({ + name: 'vendor/[name]_[md5:hash:hex:8].[ext]' }) } ] @@ -165,7 +180,7 @@ webpackConfig = { jquery: 'jQuery' }, plugins: [ - new Clean([config.output.path]), + new Clean([dist]), new ExtractTextPlugin(stylesFilename, { allChunks: true, disable: (argv.watch === true) // '--watch' disable ExtractTextPlugin @@ -210,7 +225,7 @@ if (argv.watch) { // '--release' to push additional plugins to webpackConfig if (argv.release) { webpackConfig.plugins.push(new AssetsPlugin({ - path: path.join(__dirname, config.output.path), + path: path.join(__dirname, dist), filename: 'assets.json', fullPath: false, processOutput: assetsPluginProcessOutput From 7623ad0511093372df8a0d2f22bdeae80253e6b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrick=20V=C3=A9zina?= Date: Fri, 26 Aug 2016 13:45:50 -0400 Subject: [PATCH 82/82] =?UTF-8?q?Set=20dynamically=20aboslute=20public=20p?= =?UTF-8?q?ath=20on=20'npm=20run=20watch';=20fix=20http/htt=E2=80=A6=20(#1?= =?UTF-8?q?696)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Set dynamically aboslute public path on 'npm run watch'; fix http/https hardcoded in watch.js * WEBPACK_PUBLIC_PATH fix --- assets/config.json | 1 + assets/scripts/util/public-path.js | 8 ++++++++ watch.js | 8 +------- webpack.config.js | 3 +++ 4 files changed, 13 insertions(+), 7 deletions(-) create mode 100644 assets/scripts/util/public-path.js diff --git a/assets/config.json b/assets/config.json index 88d3ab7616..a6edc9793a 100644 --- a/assets/config.json +++ b/assets/config.json @@ -1,6 +1,7 @@ { "entry": { "main": [ + "./scripts/util/public-path.js", "./scripts/main.js", "./styles/main.scss" ], diff --git a/assets/scripts/util/public-path.js b/assets/scripts/util/public-path.js new file mode 100644 index 0000000000..af588c249b --- /dev/null +++ b/assets/scripts/util/public-path.js @@ -0,0 +1,8 @@ +/* globals WEBPACK_PUBLIC_PATH */ + +// Dynamically set absolute public path from current protocol and host +if (WEBPACK_PUBLIC_PATH !== false) { + /* eslint-disable no-undef */ + __webpack_public_path__ = location.protocol + '//' + location.host + WEBPACK_PUBLIC_PATH; + /*eslint-enable no-undef*/ +} diff --git a/watch.js b/watch.js index 95189ff8aa..0a867bf9ee 100644 --- a/watch.js +++ b/watch.js @@ -9,15 +9,9 @@ var webpackConfig = require('./webpack.config'), config = require('./assets/config'); // Internal variables -var host = 'http://localhost', - port = config.devPort || '3000', - compiler; - -webpackConfig.output.publicPath = host + ':' + port + config.output.publicPath; -compiler = webpack(webpackConfig); +var compiler = webpack(webpackConfig); browserSync.init({ - port: port, proxy: { target: config.devUrl, middleware: [ diff --git a/webpack.config.js b/webpack.config.js index 13658fd7a4..ba5de4e7f6 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -191,6 +191,9 @@ webpackConfig = { 'window.jQuery': 'jquery', 'Tether': 'tether', 'window.Tether': 'tether' + }), + new webpack.DefinePlugin({ + WEBPACK_PUBLIC_PATH: (argv.watch === true) ? JSON.stringify(path.join(config.publicPath, dist)) : false }) ], postcss: [