Commit 867ea286 authored by alchemyunited's avatar alchemyunited

adopted SCSS 7-1 pattern

parent dd4d1215
......@@ -239,12 +239,22 @@ class ClassSetup {
// add_action( 'wp_enqueue_scripts', [ $new_styles, 'wpEnqueueStyleParent' ] );
$this->_arr_actions[] = [
'active' => true, // <<<
'active' => false, // <<<
'hook' => 'wp_enqueue_scripts',
'component' => $new_styles,
'callback' => 'wpEnqueueStyleParent'
];
// DEqueue the parent
// important - be sure to update the parent style property in ClassStyles
$this->_arr_actions[] = [
'active' => true, // <<<
'hook' => 'wp_print_styles',
'component' => $new_styles,
'callback' => 'wpDequeueStyleParent',
'priority' => 100
];
// add_action( 'wp_enqueue_scripts', [ $new_styles, 'wpEnqueueStyleChild' ], 10 );
$this->_arr_actions[] = [
......
......@@ -8,7 +8,7 @@ class ClassStyles {
protected $_str_parent_style = 'parent-style';
// Update the ver_ anytime the parent theme is updated
protected $_str_parent_style_ver = 'v1.4';
protected $_str_child_style = 'custom-style';
protected $_str_child_style = 'main-style';
protected $_str_child_style_ver = 'v20180101.1';
public function __construct() {
......@@ -29,43 +29,11 @@ class ClassStyles {
wp_enqueue_style(
$this->_str_child_style,
get_stylesheet_directory_uri() . '/app/assets/dist/css/custom.min.css',
get_stylesheet_directory_uri() . '/app/assets/dist/css/main.min.css',
[ $this->_str_parent_style ],
$this->_str_child_style_ver );
}
/**
* TODO . Move to somewhere else
*/
public function wpEnqueueScriptsWPAddInlineStyle() {
global $post;
$mix_id = get_post_thumbnail_id( $post->ID );
if ( ! empty( $mix_id ) ) {
$img = wp_get_attachment_image_url( $mix_id, '' );
$med_lrg = wp_get_attachment_image_url( $mix_id, 'wpsight-large' );
$lrg = wp_get_attachment_image_url( $mix_id, 'wpsight-full' );
// if we don't have the right size, fallback to the next best available size
if ( empty( $lrg ) ) {
$lrg = $img;
if ( empty( $med_lrg ) ) {
$med_lrg = $img;
}
} elseif ( empty( $med_lrg ) ) {
$med_lrg = $lrg;
}
// site-header site-header-featured_image site-header-no-filter
$str = '@media (max-width: 767px) {body .site-header-featured_image{background-image: url(' . $med_lrg . ')}}';
$str .= '@media (min-width: 768px) {body .site-header-featured_image{background-image: url(' . $lrg . ')}}';
wp_add_inline_style( $this->_ver_child_style, $str );
}
}
}
\ No newline at end of file
# Sass Boilerplate
More info: https://github.com/HugoGiraudel/sass-boilerplate
This is a sample project using the 7-1 architecture pattern and sticking to Sass Guidelines writing conventions.
Each folder of this project has its own README.md file to explain the purpose and add extra information. Be sure to browse the repository to see how it works.
# Main file
The main file (usually labelled `main.scss`) should be the only Sass file from the whole code base not to begin with an underscore. This file should not contain anything but `@import` and comments.
*Note: when using [Eyeglass](https://github.com/sass-eyeglass/eyeglass) for distribution, it might be a fine idea to name this file `index.scss` rather than `main.scss` in order to stick to [Eyeglass modules specifications](https://github.com/sass-eyeglass/eyeglass#writing-an-eyeglass-module-with-sass-files). See [#21](https://github.com/HugoGiraudel/sass-boilerplate/issues/21) for reference.*
Reference: [Sass Guidelines](http://sass-guidelin.es/) > [Architecture](http://sass-guidelin.es/#architecture) > [Main file](http://sass-guidelin.es/#main-file)
# Abstracts
The `abstracts/` folder gathers all Sass tools and helpers used across the project. Every global variable, function, mixin and placeholder should be put in here.
The rule of thumb for this folder is that it should not output a single line of CSS when compiled on its own. These are nothing but Sass helpers.
Reference: [Sass Guidelines](http://sass-guidelin.es/) > [Architecture](http://sass-guidelin.es/#architecture) > [Abstracts folder](http://sass-guidelin.es/#abstracts-folder)
// -----------------------------------------------------------------------------
// This file contains all application-wide Sass functions.
// -----------------------------------------------------------------------------
/// Native `url(..)` function wrapper
/// @param {String} $base - base URL for the asset
/// @param {String} $type - asset type folder (e.g. `fonts/`)
/// @param {String} $path - asset path
/// @return {Url}
@function asset($base, $type, $path) {
@return url($base + $type + $path);
}
/// Returns URL to an image based on its path
/// @param {String} $path - image path
/// @param {String} $base [$base-url] - base URL
/// @return {Url}
/// @require $base-url
@function image($path, $base: $base-url) {
@return asset($base, 'images/', $path);
}
/// Returns URL to a font based on its path
/// @param {String} $path - font path
/// @param {String} $base [$base-url] - base URL
/// @return {Url}
/// @require $base-url
@function font($path, $base: $base-url) {
@return asset($base, 'fonts/', $path);
}
// -----------------------------------------------------------------------------
// This file contains all application-wide Sass mixins.
// -----------------------------------------------------------------------------
/// Event wrapper
/// @author Harry Roberts
/// @param {Bool} $self [false] - Whether or not to include current selector
/// @link https://twitter.com/csswizardry/status/478938530342006784 Original tweet from Harry Roberts
@mixin on-event($self: false) {
@if $self {
&,
&:hover,
&:active,
&:focus {
@content;
}
} @else {
&:hover,
&:active,
&:focus {
@content;
}
}
}
/// Make a context based selector a little more friendly
/// @author Hugo Giraudel
/// @param {String} $context
@mixin when-inside($context) {
#{$context} & {
@content;
}
}
// -----------------------------------------------------------------------------
// This file contains all application-wide Sass variables.
// -----------------------------------------------------------------------------
$font-base: 18;
$font-increment: 3;
$font-unit: 'px';
$white: #fff;
$grey-lt: #dee0e5;
$grey-mid: #a7a9ac;
$grey-dk: #000000;
$black: #343235;
$blue: #1c75bc;
/// Regular font family
/// @type List
$text-font-stack: 'Open Sans', 'Helvetica Neue Light', 'Helvetica Neue', 'Helvetica', 'Arial', sans-serif !default;
$headline-font-stack: $taxt-font-stack;
/// Code (monospace) font family
/// @type List
$code-font-stack: 'Courier New', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Monaco', monospace !default;
/// Copy text color
/// @type Color
$text-color: rgb(34, 34, 34) !default;
/// Main brand color
/// @type Color
$brand-color: rgb(229, 0, 80) !default;
/// Light grey
/// @type Color
$light-grey: rgb(237, 237, 237) !default;
/// Medium grey
/// @type Color
$mid-grey: rgb(153, 153, 153) !default;
/// Dark grey
/// @type Color
$dark-grey: rgb(68, 68, 68) !default;
/// Container's maximum width
/// @type Length
$max-width: 1180px !default;
/// Breakpoints map
/// @prop {String} keys - Keys are identifiers mapped to a given length
/// @prop {Map} values - Values are actual breakpoints expressed in pixels
$breakpoints: (
'small': 320px,
'medium': 768px,
'large': 1024px,
) !default;
/*
TODO - These are Bootstrap 3 breakpoints
$xs-min : "only screen and (min-width:none)";
$xs-max : "only screen and (max-width:767px)";
$xs-sm : "only screen (min-width: none) and (max-width:767px)";
$sm-min : "only screen and (min-width:768px)";
$sm-max : "only screen and (max-width:991px)";
$sm-md : "only screen (min-width: 768px) and (max-width:991px)";
$md-min : "only screen and (min-width:992px)";
$md-max : "only screen and (max-width:1199px)";
$md-lg : "only screen (min-width: 992px) and (max-width:1199px)";
$lg-min : "only screen and (min-width:1200px)";
$lg-max : "only screen and (max-width:none)";
*/
/// Relative or absolute URL where all assets are served from
/// @type String
/// @example scss - When using a CDN
/// $base-url: 'http://cdn.example.com/assets/';
$base-url: '/assets/' !default;
# Base
The `base/` folder holds what we might call the boilerplate code for the project. In there, you might find some typographic rules, and probably a stylesheet (that I’m used to calling `_base.scss`), defining some standard styles for commonly used HTML elements.
Reference: [Sass Guidelines](http://sass-guidelin.es/) > [Architecture](http://sass-guidelin.es/#architecture) > [Base folder](http://sass-guidelin.es/#base-folder)
// -----------------------------------------------------------------------------
// This file contains very basic styles.
// -----------------------------------------------------------------------------
/**
* Set up a decent box model on the root element
*/
html {
box-sizing: border-box;
}
/**
* Make all elements from the DOM inherit from the parent box-sizing
* Since `*` has a specificity of 0, it does not override the `html` value
* making all elements inheriting from the root box-sizing value
* See: https://css-tricks.com/inheriting-box-sizing-probably-slightly-better-best-practice/
*/
*,
*::before,
*::after {
box-sizing: inherit;
}
body {
font-size: #{$font-base }#{$font-unit};
}
/**
* Basic styles for links
*/
a {
color: $brand-color;
text-decoration: none;
@include on-event {
color: $text-color;
text-decoration: underline;
}
}
// TODO - make this a function / mixin
$font-size-h1: #{$font-base + (5 * $font-increment)}#{$font-unit};
$font-size-h2: #{$font-base + (4 * $font-increment)}#{$font-unit};
$font-size-h3: #{$font-base + (3 * $font-increment)}#{$font-unit};
......@@ -5,30 +48,33 @@ $font-size-h4: #{$font-base + (2 * $font-increment)}#{$font-unit};
$font-size-h5: #{$font-base + (1 * $font-increment)}#{$font-unit};
$font-size-h6: #{$font-base + (0 * $font-increment)}#{$font-unit};
%h-font-family{
font-family: $headline-font-stack;
}
h1, .h1 {
font-size: $font-size-h1
font-size: $font-size-h1;
@extend %h-font-family;
}
h2, .h2 {
font-size: $font-size-h2
font-size: $font-size-h2;
@extend %h-font-family;
}
h3, .h3 {
font-size: $font-size-h3
font-size: $font-size-h3;
@extend %h-font-family;
}
h4, .h4 {
font-size: $font-size-h4
font-size: $font-size-h4;
@extend %h-font-family;
}
h5, .h5 {
font-size: $font-size-h5
font-size: $font-size-h5;
@extend %h-font-family;
}
h6, .h6 {
font-size: $font-size-h6
font-size: $font-size-h6;
@extend %h-font-family;
}
body {
font-size: #{$font-base }#{$font-unit};
}
a{
text-decoration: none;
}
\ No newline at end of file
// -----------------------------------------------------------------------------
// This file contains all @font-face declarations, if any.
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
// This file contains CSS helper classes.
// -----------------------------------------------------------------------------
/**
* Clear inner floats
*/
.clearfix::after {
clear: both;
content: '';
display: table;
}
/**
* Main content containers
* 1. Make the container full-width with a maximum width
* 2. Center it in the viewport
* 3. Leave some space on the edges, especially valuable on small screens
*/
.container {
max-width: $max-width; /* 1 */
margin-left: auto; /* 2 */
margin-right: auto; /* 2 */
padding-left: 20px; /* 3 */
padding-right: 20px; /* 3 */
width: 100%; /* 1 */
}
/**
* Hide text while making it readable for screen readers
* 1. Needed in WebKit-based browsers because of an implementation bug;
* See: https://code.google.com/p/chromium/issues/detail?id=457146
*/
.hide-text {
overflow: hidden;
padding: 0; /* 1 */
text-indent: 101%;
white-space: nowrap;
}
/**
* Hide element while making it readable for screen readers
* Shamelessly borrowed from HTML5Boilerplate:
* https://github.com/h5bp/html5-boilerplate/blob/master/src/css/main.css#L119-L133
*/
.visually-hidden {
border: 0;
clip: rect(0 0 0 0);
height: 1px;
margin: -1px;
overflow: hidden;
padding: 0;
position: absolute;
width: 1px;
}
/**
* Basic typography style for copy text
*/
body {
color: $text-color;
font: normal 125% / 1.4 $text-font-stack;
}
# Components
For small components, there is the `components/` folder. While `layout/` is macro (defining the global wireframe), `components/` is more focused on widgets. It contains all kind of specific modules like a slider, a loader, a widget, and basically anything along those lines. There are usually a lot of files in components/ since the whole site/application should be mostly composed of tiny modules.
Reference: [Sass Guidelines](http://sass-guidelin.es/) > [Architecture](http://sass-guidelin.es/#architecture) > [Components folder](http://sass-guidelin.es/#components-folder)
// -----------------------------------------------------------------------------
// This file contains all styles related to the button component.
// -----------------------------------------------------------------------------
# Layout
The `layout/` folder contains everything that takes part in laying out the site or application. This folder could have stylesheets for the main parts of the site (header, footer, navigation, sidebar…), the grid system or even CSS styles for all the forms.
Reference: [Sass Guidelines](http://sass-guidelin.es/) > [Architecture](http://sass-guidelin.es/#architecture) > [Layout folder](http://sass-guidelin.es/#layout-folder)
// -----------------------------------------------------------------------------
// This file contains all styles related to the footer of the site/application.
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
// This file contains all styles related to the header of the site/application.
// -----------------------------------------------------------------------------
@charset 'UTF-8';
// 1. Configuration and helpers
@import
'abstracts/variables',
'abstracts/functions',
'abstracts/mixins';
// 2. Vendors
@import
'vendors/normalize';
// 3. Base stuff
@import
'base/base',
'base/fonts',
'base/typography',
'base/helpers';
// 4. Layout-related sections
@import
'layout/header',
'layout/footer';
// 5. Components
@import
'components/button';
// 6. Page-specific styles
@import
'pages/home';
// 7. Themes
@import
'themes/default';
# Pages
If you have page-specific styles, it is better to put them in a `pages/` folder, in a file named after the page. For instance, it’s not uncommon to have very specific styles for the home page hence the need for a `_home.scss` file in `pages/`.
*Note — Depending on your deployment process, these files could be called on their own to avoid merging them with the others in the resulting stylesheet. It is really up to you.*
Reference: [Sass Guidelines](http://sass-guidelin.es/) > [Architecture](http://sass-guidelin.es/#architecture) > [Pages folder](http://sass-guidelin.es/#pages-folder)
// -----------------------------------------------------------------------------
// This file contains styles that are specific to the home page.
// -----------------------------------------------------------------------------
# Theme
On large sites and applications, it is not unusual to have different themes. There are certainly different ways of dealing with themes but I personally like having them all in a `themes/` folder.
*Note — This is very project-specific and is likely to be non-existent on many projects.*
Reference: [Sass Guidelines](http://sass-guidelin.es/) > [Architecture](http://sass-guidelin.es/#architecture) > [Themes folder](http://sass-guidelin.es/#themes-folder)
// -----------------------------------------------------------------------------
// When having several themes, this file contains everything related to the
// default one.
// -----------------------------------------------------------------------------
# Vendors
Most projects will have a `vendors/` folder containing all the CSS files from external libraries and frameworks – Normalize, Bootstrap, jQueryUI, FancyCarouselSliderjQueryPowered, and so on. Putting those aside in the same folder is a good way to say “Hey, this is not from me, not my code, not my responsibility”.
If you have to override a section of any vendor, I recommend you have an 8th folder called `vendors-extensions/` in which you may have files named exactly after the vendors they overwrite. For instance, `vendors-extensions/_bootstrap.scss` is a file containing all CSS rules intended to re-declare some of Bootstrap’s default CSS. This is to avoid editing the vendor files themselves, which is generally not a good idea.
Reference: [Sass Guidelines](http://sass-guidelin.es/) > [Architecture](http://sass-guidelin.es/#architecture) > [Vendors folder](http://sass-guidelin.es/#vendors-folder)
/*! normalize.css v5.0.0 | MIT License | github.com/necolas/normalize.css */
/**
* 1. Change the default font family in all browsers (opinionated).
* 2. Correct the line height in all browsers.
* 3. Prevent adjustments of font size after orientation changes in
* IE on Windows Phone and in iOS.
*/
/* Document
========================================================================== */
html {
font-family: sans-serif; /* 1 */
line-height: 1.15; /* 2 */
-ms-text-size-adjust: 100%; /* 3 */
-webkit-text-size-adjust: 100%; /* 3 */
}
/* Sections
========================================================================== */
/**
* Remove the margin in all browsers (opinionated).
*/
body {
margin: 0;
}
/**
* Add the correct display in IE 9-.
*/
article,
aside,
footer,
header,
nav,
section {
display: block;
}
/**
* Correct the font size and margin on `h1` elements within `section` and
* `article` contexts in Chrome, Firefox, and Safari.
*/
h1 {
font-size: 2em;
margin: 0.67em 0;
}
/* Grouping content
========================================================================== */