Skip to content
This repository has been archived by the owner on Sep 13, 2024. It is now read-only.

Commit

Permalink
Use Sass maps for global settings
Browse files Browse the repository at this point in the history
- Default settings are contained within the `$_bourbon-defaults` map
- User settings to override defaults are placed within a `$bourbon` map
  • Loading branch information
Tyson Gach committed Feb 5, 2016
1 parent 98f9473 commit 4e43c2d
Show file tree
Hide file tree
Showing 10 changed files with 113 additions and 50 deletions.
5 changes: 2 additions & 3 deletions core/_bourbon.scss
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@
// Copyright 2011 thoughtbot, inc.
// MIT License

@import "bourbon/settings/asset-pipeline";
@import "bourbon/settings/global-font-file-formats";
@import "bourbon/settings/scales";
@import "bourbon/settings/modular-scale";
@import "bourbon/settings/settings";
@import "bourbon/settings/bourbon-get-setting";

@import "bourbon/functions/assign-inputs";
@import "bourbon/functions/collapse-directionals";
Expand Down
17 changes: 10 additions & 7 deletions core/bourbon/addons/_font-face.scss
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
/// use the Rails Asset Pipeline (place the fonts in `app/assets/fonts/').
///
/// @argument {list} $file-formats [$global-font-file-formats]
/// `$global-font-file-formats` is set to `ttf woff2 woff` by default. Pass a
/// `$global-font-file-formats` is set to `("ttf", "woff2", "woff")` by default. Pass a
/// list of file formats to support. E.g. `eot woff2 woff ttf svg`.
///
/// @example scss
Expand All @@ -31,14 +31,17 @@
/// @require {function} font-url-prefixer
///
/// @require {function} font-source-declaration
///
/// @require {function} _bourbon-get-setting

@mixin font-face(
$font-family,
$file-path,
$weight: normal,
$style: normal,
$asset-pipeline: $asset-pipeline,
$file-formats: $global-font-file-formats) {
$font-family,
$file-path,
$weight: normal,
$style: normal,
$asset-pipeline: _bourbon-get-setting("rails-asset-pipeline"),
$file-formats: _bourbon-get-setting("global-font-file-formats")
) {

$font-url-prefix: font-url-prefixer($asset-pipeline);

Expand Down
11 changes: 7 additions & 4 deletions core/bourbon/addons/_modular-scale.scss
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,14 @@
///
/// @return {number}
///
/// @require {variable} $modular-scale-ratio
///
/// @require {variable} $modular-scale-base
/// @require {function} _bourbon-get-setting

@function modular-scale(
$increment,
$value: _bourbon-get-setting("modular-scale-base"),
$ratio: _bourbon-get-setting("modular-scale-ratio")
) {

@function modular-scale($increment, $value: $modular-scale-base, $ratio: $modular-scale-ratio) {
$v1: nth($value, 1);
$v2: nth($value, length($value));
$value: $v1;
Expand Down
7 changes: 0 additions & 7 deletions core/bourbon/settings/_asset-pipeline.scss

This file was deleted.

12 changes: 12 additions & 0 deletions core/bourbon/settings/_bourbon-get-setting.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/// Return a Bourbon setting.
///
/// @argument {string} $setting
///
/// @example scss
/// _bourbon-get-setting(rails-asset-pipeline)
///
/// @access private

@function _bourbon-get-setting($setting) {
@return map-get(map-merge($_bourbon-defaults, $bourbon), $setting);
}
12 changes: 0 additions & 12 deletions core/bourbon/settings/_global-font-file-formats.scss

This file was deleted.

17 changes: 0 additions & 17 deletions core/bourbon/settings/_modular-scale.scss

This file was deleted.

33 changes: 33 additions & 0 deletions core/bourbon/settings/_settings.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
@charset "UTF-8";

/// Default Bourbon configuration settings.
///
/// @type map
///
/// @property {list} global-font-file-formats [("ttf", "woff2", "woff")]
/// Global font file formats for the `font-face` mixin.
///
/// @property {number (with unit)} modular-scale-base [1em]
/// Global base value for the `modular-scale` function
///
/// @property {number (unitless)} modular-scale-ratio [$major-third (1.25)]
/// Global base ratio for the `modular-scale` function
///
/// @property {bool} rails-asset-pipeline [false]
/// Enable or disable the `$asset-pipeline` variable for all functions that
/// accept it.
///
/// @access private

$_bourbon-defaults: (
"global-font-file-formats": ("ttf", "woff2", "woff"),
"modular-scale-base": 1em,
"modular-scale-ratio": $major-third,
"rails-asset-pipeline": false,
);

/// User overrides of Bourbon configuration settings
///
/// @type map

$bourbon: () !default;
33 changes: 33 additions & 0 deletions spec/bourbon/settings/bourbon_get_setting_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
require "spec_helper"

describe "_bourbon-get-setting" do
before(:all) do
ParserSupport.parse_file("settings/bourbon-get-setting")
end

context "gets the modular-scale-base setting" do
it "and returns the default value" do
expect(".test-1").to have_rule("content: 1em")
end
end

context "gets the rails-asset-pipeline setting" do
it "and returns the user-overridden value" do
expect(".test-2").to have_rule("content: true")
end
end

context "called from the font-face mixin" do
it "outputs user-overridden font file formats" do
ruleset = 'font-family: "source-sans-pro"; ' +
"font-style: normal; " +
"font-weight: normal; " +
'src: font-url("source-sans-pro-regular.woff2") ' +
'format("woff2"), ' +
'font-url("source-sans-pro-regular.woff") ' +
'format("woff");'

expect("@font-face").to have_ruleset(ruleset)
end
end
end
16 changes: 16 additions & 0 deletions spec/fixtures/settings/bourbon-get-setting.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
@import "setup";

$bourbon: (
"global-font-file-formats": ("woff2", "woff"),
"rails-asset-pipeline": true,
);

.test-1 {
content: _bourbon-get-setting("modular-scale-base");
}

.test-2 {
content: _bourbon-get-setting("rails-asset-pipeline");
}

@include font-face("source-sans-pro", "source-sans-pro-regular");

0 comments on commit 4e43c2d

Please sign in to comment.