sane-scale 0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: f1c3c844f2da6800cc3529504aeb55450d04b506
4
+ data.tar.gz: b19e2024fc6edf08ae908ebbb754d55a9ad9bf5b
5
+ SHA512:
6
+ metadata.gz: 351aeacda072ea1ee1ef212703139bdbe357beb3090a041d529b1aafd30c0fa05f84c45604b3699570ce7f168c86f9d5c6b0fb2848407865d03fc03c92f387a7
7
+ data.tar.gz: 1c28ba05d43e6ebefd652160702160ee808a5a8c56a0c0003df65a48f89f11349137796db58270ddc6a7c6c0d6df17baa21ed424a95e17377e72b1c277480c97
@@ -0,0 +1,124 @@
1
+ # Sane Scale
2
+
3
+ Sane Scale is a framework for defining and applying typographic styles. Its goal is to generate a complex, nuanced typographic system from only a few key variables.
4
+
5
+ ## Features
6
+
7
+ 1. Modular. Typographic measurements are based on proportional lists of values.
8
+ 2. Responsive. Typography adjusts to the constraints of each breakpoint.
9
+ 3. Font rebalancing. Different fonts set to the same size often don't appear to be. Fonts are normalized, so every font appears to be exactly the size you intend.
10
+
11
+ ## Install
12
+
13
+ * Terminal: `gem install sane-scale`
14
+ * Compass config.rb: `require 'sane-scale'`
15
+ * SCSS: `@import 'sane-scale';`
16
+
17
+ ## Usage
18
+
19
+ ### Declare your fonts
20
+
21
+ For Sane Scale, fonts are defined via SASS maps in the following format:
22
+
23
+ ```scss
24
+ // Default font
25
+
26
+ $font-georgia: (
27
+ "family": unquote("Georgia, serif"),
28
+ "normalize-ratio": 1.00
29
+ );
30
+
31
+ // Additional fonts
32
+
33
+ $font-verdana: (
34
+ "family": unquote("Verdana, sans-serif"),
35
+ "normalize-ratio": 0.89
36
+ );
37
+
38
+ $font-feather: (
39
+ "family": unquote("'Feather'"),
40
+ "normalize-ratio": 0.95
41
+ );
42
+ ```
43
+
44
+ Oftentimes two fonts set to different sizes do not appear to be the same size. This is because the height of their lowercase letters is not equal. The `normalize-ratio` is the ratio we'll use to adjust the size of anything set in this font.
45
+
46
+ For example, Verdana appears 11% larger than Georgia. To normalize it with Georgia, we need to decrease size by 11% (normalize-ratio: 0.89). The normalized sizes of Verdana will appear to be the same size as Georgia.
47
+
48
+ ### Define your breakpoints
49
+
50
+ Sane scale uses a SASS map of breakpoints (with relevant parameters) in the following format:
51
+
52
+ ```scss
53
+ $breakpoints: (
54
+
55
+ // Phone sizes
56
+ "default": (
57
+ "base-font-size": 18px,
58
+ "base-line-height": 1.5,
59
+ "max-font-size": 28px,
60
+ "max-line-height": 1.35,
61
+ "rounding": false
62
+ ),
63
+
64
+ // Tablet sizes and larger
65
+ "tablet": (
66
+ "media-query": "screen and (min-width: 600px)",
67
+ "base-font-size": 20px,
68
+ "base-line-height": 1.6,
69
+ "max-font-size": 42px,
70
+ "max-line-height": 1.25,
71
+ "rounding": false
72
+ )
73
+ );
74
+ ```
75
+ For each breakpoint, you'll need to specify a font-size and line-height for both the base size and the max size. Additional sizes and line-heights will be interpolated from these constraints.
76
+
77
+ You'll also need to specify a `media-query` for all breakpoints, excluding your `default` breakpoint. Feel free to name the other breakpoints whatever you like.
78
+
79
+ ### Build the scale
80
+
81
+ All thats left to do is to define the sizes you need and build the scale itself:
82
+
83
+ ```scss
84
+ $numb-smaller-sizes: 1;
85
+ $numb-larger-sizes: 4;
86
+
87
+ $sane-scale: ss-make-responsive-font-scale($breakpoints, $numb-smaller-sizes, $numb-larger-sizes);
88
+ ```
89
+ That's it! Note that `sane-scale` is a key variable. This map will be used by the following mixins to lookup and apply sizes.
90
+
91
+ ### Apply responsize sizing
92
+
93
+ Use `@include ss-set-responsive-font-size($font, $size)` to apply a responsive size. The sizes available to you are based on your parameters:
94
+ * 0 is your base size.
95
+ * 1, 2, 3... are your increasingly large sizes.
96
+ * -1, -2, -3... are your increasingly small sizes.
97
+
98
+ ```scss
99
+ p.lead {
100
+ @include ss-set-responsive-font-size($font-georgia, 1);
101
+ }
102
+ ```
103
+ We just created a responsive lead paragraph style. It will use `$font-georgia` at size 1 for each breakpoint: 20.1px by default, and then resizing to 24.1px for tablets and larger.
104
+
105
+ ```scss
106
+ .h4 {
107
+ @include ss-set-responsive-font-size($font-verdana, 1);
108
+ }
109
+ ```
110
+ We justed used the same size `.h4` heading, but with `$font-verdana`. That will result in a font-size of 17.9px by default and 21.4px for tablets and larger. Mathematically different, but visually equal.
111
+
112
+
113
+
114
+ ### Apply static sizing
115
+
116
+ You might occassionally want finer-grained control of your type styles. For these cases, use the `ss-set-font-size()` mixin which accepts an additional `$breakpoint` parameter:
117
+
118
+ ```scss
119
+ .h4 {
120
+ @include ss-set-font-size($font-verdana, 1, "tablet");
121
+ }
122
+ ```
123
+
124
+ Here we just styled our h4 to have the size 1 for only the tablet breakpoint. With `ss-set-responsive-font-size()` the corresponding sizes for each other breakpoint would have also been applied.
@@ -0,0 +1,29 @@
1
+ # All gems that are required for this extension to work should go here.
2
+ # These are the requires you would normally put in your config.rb file
3
+ # By default, you should always included Compass. Do not include your
4
+ # extension.
5
+ require 'compass'
6
+
7
+ # This tells Compass what your Compass extension is called,
8
+ # and where to find its files. Replace 'extension' with the
9
+ # name of your extension. Spaces allowed.
10
+ extension_path = File.expand_path(File.join(File.dirname(__FILE__), ".."))
11
+ Compass::Frameworks.register('sane-scale', :path => extension_path)
12
+
13
+ # Version and date of version for your Compass extension.
14
+ # Replace Extension with the name of your extension. Letters,
15
+ # numbers, and underscores only. Version is a number. If a
16
+ # version contains alphas, it will be created as a
17
+ # prerelease version. Date is in the form of YYYY-MM-DD
18
+ module SaneScale
19
+ VERSION = "0.1"
20
+ DATE = "2016-05-09"
21
+ end
22
+
23
+ # This is where any custom SassScript should be placed. The functions will be
24
+ # available on require of your extension without the need for users to import
25
+ # any partials. Uncomment below.
26
+
27
+ # module Sass::Script::Functions
28
+ #
29
+ # end
@@ -0,0 +1,8 @@
1
+ @import "sane-scale/map-deep-get";
2
+ @import "sane-scale/make-scale";
3
+ @import "sane-scale/make-font-scale";
4
+ @import "sane-scale/make-responsive-font-scale";
5
+
6
+ $sane-scale: ss-make-responsive-font-scale() !default;
7
+
8
+ @import "sane-scale/set-font-size";
@@ -0,0 +1,47 @@
1
+
2
+ // Create a modular font scale.
3
+ // Returns a nested list of font-size and line-height values.
4
+
5
+ @function ss-make-font-scale(
6
+ $base-size,
7
+ $base-line-height,
8
+ $max-size,
9
+ $max-line-height,
10
+ $numb-smaller-sizes: 1,
11
+ $numb-larger-sizes: 4,
12
+ $rounding: false
13
+ ) {
14
+
15
+ // If line-height params are unitless values,
16
+ // covert to unit values.
17
+ $base-line-height: if(unitless($base-line-height), $base-size * $base-line-height, $base-line-height);
18
+ $max-line-height: if(unitless($max-line-height), $max-size * $max-line-height, $max-line-height);
19
+
20
+ // Create font-size and line-height scales
21
+ $font-size-scale: ss-make-scale($base-size, $max-size, $numb-smaller-sizes, $numb-larger-sizes, $rounding);
22
+ $line-height-scale: ss-make-scale($base-line-height, $max-line-height, $numb-smaller-sizes, $numb-larger-sizes, $rounding);
23
+
24
+ $font-scale: ();
25
+
26
+ // Pair each size with the correponding font-size
27
+ // and line-height, then add the size to the scale.
28
+ @for $i from -$numb-smaller-sizes to $numb-larger-sizes + 1 {
29
+
30
+ // Calculate array position in order to lookup sizes in lists.
31
+ $arr-position: $i + $numb-smaller-sizes + 1;
32
+
33
+ // Key for size
34
+ $name-of-size: $i;
35
+
36
+ // Values for size
37
+ $values: (
38
+ font-size: nth($font-size-scale, $arr-position),
39
+ line-height: nth($line-height-scale, $arr-position)
40
+ );
41
+
42
+ // Merge into $font-scale.
43
+ $font-scale: map-merge($font-scale, ($name-of-size: $values));
44
+ }
45
+
46
+ @return $font-scale;
47
+ }
@@ -0,0 +1,51 @@
1
+
2
+ // Augments a breakpoint map by building a "scale" property
3
+ // containing the specified sizes to each breakpoint.
4
+
5
+ @function ss-make-responsive-font-scale(
6
+ $breakpoints: (
7
+ // Phone sizes
8
+ "default": (
9
+ "base-font-size": 18px,
10
+ "base-line-height": 1.5,
11
+ "max-font-size": 28px,
12
+ "max-line-height": 1.35,
13
+ "rounding": false
14
+ ),
15
+ // Tablet sizes and larger
16
+ "tablet": (
17
+ "media-query": "screen and (min-width: 600px)",
18
+ "base-font-size": 20px,
19
+ "base-line-height": 1.6,
20
+ "max-font-size": 42px,
21
+ "max-line-height": 1.25,
22
+ "rounding": false
23
+ )
24
+ ),
25
+ $numb-smaller-sizes: 1,
26
+ $numb-larger-sizes: 4
27
+ ) {
28
+
29
+ $sane-scale: ();
30
+
31
+ // Create a scale for each breakpoint.
32
+ @each $breakpoint-name, $breakpoint-value in $breakpoints {
33
+
34
+ // Create a font scale.
35
+ $scale: ss-make-font-scale(
36
+ map-get($breakpoint-value, "base-font-size"),
37
+ map-get($breakpoint-value, "base-line-height"),
38
+ map-get($breakpoint-value, "max-font-size"),
39
+ map-get($breakpoint-value, "max-line-height"),
40
+ $numb-smaller-sizes,
41
+ $numb-larger-sizes,
42
+ map-get($breakpoint-value, "rounded")
43
+ );
44
+
45
+ // Merge into responsive scale.
46
+ $new-breakpoint-value: map-merge($breakpoint-value, ("scale": $scale));
47
+ $sane-scale: map-merge($sane-scale, ($breakpoint-name: $new-breakpoint-value));
48
+ }
49
+
50
+ @return $sane-scale;
51
+ }
@@ -0,0 +1,41 @@
1
+
2
+ // Create a modular scale. Returns a list of values.
3
+
4
+ @function ss-make-scale(
5
+ $base: 16px,
6
+ $max: 32px,
7
+ $smaller-values: 1,
8
+ $larger-values: 4,
9
+ $rounding: false
10
+ ) {
11
+
12
+ $scale: ();
13
+
14
+ // The ratio we'll use to calculate the missing sizes.
15
+ $scaling-ratio: nth-root($max / $base, $larger-values);
16
+
17
+ // Calculate and add smaller values to the scale.
18
+ @for $i from -$smaller-values through -1 {
19
+ $size: $base * power($scaling-ratio, $i);
20
+ $scale: append($scale, $size);
21
+ }
22
+
23
+ // Add the base value to the scale.
24
+ $scale: append($scale, $base);
25
+
26
+ // Calculate and add larger values to the scale.
27
+ @for $i from 1 through ($larger-values) {
28
+ $size: $base * power($scaling-ratio, $i);
29
+ $scale: append($scale, $size);
30
+ }
31
+
32
+ // Optionally round the scale.
33
+ @if $rounding == true {
34
+ @each $size-name, $size-value in $scale {
35
+ $new-value: round($size-value);
36
+ $scale: map-merge($scale, ($size-name: $new-value));
37
+ }
38
+ }
39
+
40
+ @return $scale;
41
+ }
@@ -0,0 +1,6 @@
1
+ @function map-deep-get($map, $keys...) {
2
+ @each $key in $keys {
3
+ $map: map-get($map, $key);
4
+ }
5
+ @return $map;
6
+ }
@@ -0,0 +1,42 @@
1
+ /******************************************************
2
+ * MIXINS
3
+ ******************************************************/
4
+
5
+ // Apply styles for a specific font, breakpoint, and size.
6
+ @mixin ss-apply-font-styles($font, $size, $breakpoint-name) {
7
+
8
+ // Get font-size and adjust by the normalize ratio.
9
+ $normalize-ratio: map-get($font, "normalize-ratio");
10
+ font-size: map-deep-get($sane-scale, $breakpoint-name, "scale", $size, "font-size") * $normalize-ratio;
11
+
12
+ // Get line-height, but don't adjust by the normalize ratio.
13
+ line-height: map-deep-get($sane-scale, $breakpoint-name, "scale", $size, "line-height");
14
+ }
15
+
16
+ // Apply non-responsive styling. Only the size used for
17
+ // the specified media query will be applied.
18
+ @mixin ss-set-font-size($font, $size, $breakpoint-name) {
19
+ font-family: map-get($font, "family");
20
+ @include ss-apply-font-styles($font, $size, $breakpoint-name);
21
+ }
22
+
23
+ // Apply responsive styling. Corresponding sizes for
24
+ // each media query will be applied.
25
+ @mixin ss-set-responsive-font-size($font, $size) {
26
+ font-family: map-get($font, "family");
27
+ @each $breakpoint-name, $breakpoint-value in $sane-scale {
28
+
29
+ // For the default styles, don't include a media query.
30
+ @if $breakpoint-name == "default" {
31
+ @include ss-apply-font-styles($font, $size, $breakpoint-name);
32
+ }
33
+
34
+ // For other breakpoints, set style with a media query.
35
+ @else {
36
+ $media-query: map-deep-get($sane-scale, $breakpoint-name, "media-query");
37
+ @media #{$media-query} {
38
+ @include ss-apply-font-styles($font, $size, $breakpoint-name);
39
+ }
40
+ }
41
+ }
42
+ }
metadata ADDED
@@ -0,0 +1,82 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sane-scale
3
+ version: !ruby/object:Gem::Version
4
+ version: '0.1'
5
+ platform: ruby
6
+ authors:
7
+ - David Fusilier
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-05-09 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: sass
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '3.3'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '3.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: compass
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: 1.0.3
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: 1.0.3
41
+ description: Modular, responsive, scalable typography
42
+ email:
43
+ - dfusil2@gmail.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - README.md
49
+ - lib/sane-scale.rb
50
+ - stylesheets/_sane-scale.scss
51
+ - stylesheets/sane-scale/_make-font-scale.scss
52
+ - stylesheets/sane-scale/_make-responsive-font-scale.scss
53
+ - stylesheets/sane-scale/_make-scale.scss
54
+ - stylesheets/sane-scale/_map-deep-get.scss
55
+ - stylesheets/sane-scale/_set-font-size.scss
56
+ homepage: http://www.davidfusilier.com
57
+ licenses: []
58
+ metadata: {}
59
+ post_install_message:
60
+ rdoc_options: []
61
+ require_paths:
62
+ - lib
63
+ required_ruby_version: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - '>='
66
+ - !ruby/object:Gem::Version
67
+ version: '0'
68
+ required_rubygems_version: !ruby/object:Gem::Requirement
69
+ requirements:
70
+ - - '>='
71
+ - !ruby/object:Gem::Version
72
+ version: 1.3.6
73
+ requirements: []
74
+ rubyforge_project: sane-scale
75
+ rubygems_version: 2.6.4
76
+ signing_key:
77
+ specification_version: 4
78
+ summary: A SASS framework for defining and applying typographic styles. Generate a
79
+ nuanced typographic system that is both modular and responsive with only a few key
80
+ variables. Using multiple fonts? Sane scale makes it simple to normalize your fonts
81
+ so they appear visually equal when set to the same size.
82
+ test_files: []