responsive-modular-scale 0.0.2 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d1c78cae29c20c0a9fccff36cfab14c74eca1367
|
4
|
+
data.tar.gz: 82f6e8c4000a7b84130b0b9b94f66e5c12e5ea0d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fcb789eb314ee3272b27d203fd73d4ca35166e6b3e69b62f7e3723c65ae484452ad216e0a1f12d07e41cac0438c89763d1258e5937e9e656c91c1ec2a4676252
|
7
|
+
data.tar.gz: 9d5b7f9dc4dd525b1421a1b9f24b843d3d02febbe925bc36b1f1b109405756ac6a8245bee45660485817b08c6ed101ee1fb974437ba1d56c4952b1b2927bc7cc
|
@@ -5,6 +5,6 @@ extension_path = File.expand_path(File.join(File.dirname(__FILE__), ".."))
|
|
5
5
|
Compass::Frameworks.register('responsive-modular-scale', :path => extension_path)
|
6
6
|
|
7
7
|
module ResponsiveModularScale
|
8
|
-
VERSION = "0.0
|
9
|
-
DATE = "
|
8
|
+
VERSION = "0.1.0"
|
9
|
+
DATE = "2014-01-02"
|
10
10
|
end
|
data/readme.md
CHANGED
@@ -16,10 +16,12 @@ Then import it into your stylesheet like so: `@import 'responsive-modular-scale'
|
|
16
16
|
|
17
17
|
## Usage
|
18
18
|
|
19
|
-
|
19
|
+
### Setting scales
|
20
|
+
|
21
|
+
To create a set of scales we need one or more base values and one or more intervals. By default, the scale will use a 16px base value and two intervals: 1.333:1 (a fourth) by default, and 1.5:1 (a fifth) at 768px and above. You can change these values by calling `set-scales()` at the top of your stylesheet.
|
20
22
|
|
21
23
|
```scss
|
22
|
-
// Change just the base values,
|
24
|
+
// Change just the base values, keep the default scales
|
23
25
|
@include set-scales(16px 100px);
|
24
26
|
|
25
27
|
// Use a fourth by default, and a fifth for larger screens
|
@@ -29,7 +31,15 @@ To create a scale we need one or more base values and one or more intervals. By
|
|
29
31
|
@include set-scales(16px, fourth(), 640px augmented-fourth(), 1024px fifth());
|
30
32
|
```
|
31
33
|
|
32
|
-
|
34
|
+
The base values should always be pixel values, but the breakpoints can be pixel- or em-based. By default, responsive-modular-scale will output all breakpoints and font-size values as em values, but you can change to pixels if you'd like.
|
35
|
+
|
36
|
+
```scss
|
37
|
+
// You can call this before or after set-scales()
|
38
|
+
@include use-pixels;
|
39
|
+
|
40
|
+
### Using the scales
|
41
|
+
|
42
|
+
Font sizes are set the same way they are in modular-scale: just pass in a number representing a position on the modular scale.
|
33
43
|
|
34
44
|
```scss
|
35
45
|
h1 {
|
@@ -43,12 +53,51 @@ p {
|
|
43
53
|
}
|
44
54
|
```
|
45
55
|
|
56
|
+
Each call to `rms()` will generate one font-size declaration for each breakpoint/scale pair you've set.
|
57
|
+
|
58
|
+
### Working with ems
|
59
|
+
|
60
|
+
If you're outputting em-based values (the default) and want to adjust your base font size from the usual 16px, you'll need to let responsive-modular-scale know.
|
61
|
+
|
62
|
+
```scss
|
63
|
+
@include set-base(18px);
|
64
|
+
```
|
65
|
+
|
66
|
+
This mixin doesn't output any CSS, it just changes the way ems are calculated internally.
|
67
|
+
|
68
|
+
If `rms()` is called on a container element, calls made on elements inside that container will not be the right size, due to the compounding nature of ems.
|
69
|
+
|
70
|
+
```scss
|
71
|
+
@include set-scales(16px, third(), 768px fourth());
|
72
|
+
|
73
|
+
.container {
|
74
|
+
@include rms(1); // 20px, or 1.25em
|
75
|
+
|
76
|
+
.child {
|
77
|
+
@include rms(1); // 1.25em * 1.25em = 1.56em, or 25px
|
78
|
+
}
|
79
|
+
}
|
80
|
+
|
81
|
+
To correct this behavior, `rms()` includes an optional second parameter which will adjust the base font size used in em calculation. The value of the second parameter is the position on the modular scale that should be used as a base.
|
82
|
+
|
83
|
+
```scss
|
84
|
+
.container {
|
85
|
+
@include rms(1); // 1em is now 1.25em for descendant elements
|
86
|
+
|
87
|
+
.child {
|
88
|
+
// By passing in a different base the resulting em value will be adjusted down
|
89
|
+
// The font sizes for .container and .child will visually be the same, despite having different em values
|
90
|
+
@include rms(1, 1);
|
91
|
+
}
|
92
|
+
}
|
93
|
+
|
94
|
+
Currently the mixin will only correct one level deep.
|
95
|
+
|
46
96
|
## Things to change
|
47
97
|
|
48
98
|
I'm no typography expert, so if you have any suggestions or comments, let me know! In the mean time here are things that need to be added or fixed:
|
49
99
|
|
50
|
-
- Better support for multiple ratios: they'll only work if passed in as `1000px (fourth() fifth())`
|
51
|
-
- Switch to em-based font sizes and breakpoints
|
52
|
-
- Add the ability to correct an em value if the base font size has changed
|
100
|
+
- Better support for multiple ratios in a single scale: they'll only work if passed in as `1000px (fourth() fifth())`
|
53
101
|
- Allow the value of `$n` to be changed at breakpoints, to allow for finer control over font sizes
|
54
102
|
- Expample: `@include set-scales(16px, 1.5, 768px 2); h1 { @include rms(5, 6); }`
|
103
|
+
- Ability to correct em values at more than one level deep
|
@@ -1,5 +1,6 @@
|
|
1
1
|
$rms-base: 16px;
|
2
2
|
$rms-intervals: (0px fourth()), (768px fifth());
|
3
|
+
$rms-usepixels: false;
|
3
4
|
|
4
5
|
/*
|
5
6
|
Sets user-defined values for the modular scale, which replace the default values defined above. The function accepts any number of arguments which should take the form:
|
@@ -42,18 +43,75 @@ $rms-intervals: (0px fourth()), (768px fifth());
|
|
42
43
|
}
|
43
44
|
}
|
44
45
|
|
46
|
+
/*
|
47
|
+
Outputs the values of each scale to the console using modular-scale's modular-scale-list() mixin. The range of values to be returned can be specified; otherwise, 20 values starting from the base value will be returned.
|
48
|
+
|
49
|
+
@param (number) $start: index on the scale to start at (0 is the base value).
|
50
|
+
@param (number) $end: index on the scale to end at.
|
51
|
+
*/
|
52
|
+
@mixin list-scales($start: 0, $end: 20) {
|
53
|
+
@each $scale in $rms-intervals {
|
54
|
+
$scale-breakpoint: nth($scale, 1);
|
55
|
+
$scale-interval: nth($scale, 2);
|
56
|
+
|
57
|
+
@if $scale-breakpoint == 0px {
|
58
|
+
@debug 'Default --';
|
59
|
+
}
|
60
|
+
@else {
|
61
|
+
@debug 'Min-width: #{$scale-breakpoint} --';
|
62
|
+
}
|
63
|
+
|
64
|
+
@include modular-scale-list($start, $end, $rms-base, $scale-interval);
|
65
|
+
}
|
66
|
+
}
|
67
|
+
|
68
|
+
/*
|
69
|
+
Use pixel values for breakpoints and font sizes.
|
70
|
+
|
71
|
+
@param (boolean) $true: if true, the system will use pixels; otherwise, ems.
|
72
|
+
*/
|
73
|
+
@mixin use-pixels($true: true) {
|
74
|
+
$rms-usepixels: $true;
|
75
|
+
}
|
76
|
+
|
77
|
+
/*
|
78
|
+
Change the base font size from the default of 16px, for use by the to-em() function.
|
79
|
+
|
80
|
+
@param (number) $number: pixel value to change to.
|
81
|
+
*/
|
82
|
+
@mixin set-base($number) {
|
83
|
+
$rms-basefont: $number;
|
84
|
+
}
|
85
|
+
|
45
86
|
/*
|
46
87
|
Iterates through the list of breakpoints and intervals, outputting multiple font-size declarations for each breakpoint.
|
47
88
|
|
48
89
|
@param (number) $n: position on the modular scale to use.
|
49
90
|
*/
|
50
|
-
@mixin rms($n: 0) {
|
91
|
+
@mixin rms($n: 0, $base: false) {
|
92
|
+
// Output one font-size defenition for each defined breakpoint
|
51
93
|
@each $interval in $rms-intervals {
|
94
|
+
// Pull the breakpoint and interval from the list and generate the final font size
|
52
95
|
$scale-breakpoint: nth($interval, 1);
|
53
96
|
$scale-interval: nth($interval, 2);
|
54
97
|
$output: ms($n, $rms-base, $scale-interval);
|
55
98
|
|
56
|
-
|
99
|
+
// Convert the px values to em unless otherwise specified
|
100
|
+
@if $rms-usepixels == false {
|
101
|
+
$scale-breakpoint: to-em($scale-breakpoint);
|
102
|
+
$output: to-em($output);
|
103
|
+
|
104
|
+
// If a different base has been passed in, adjust the output font size to compensate
|
105
|
+
@if $base != false {
|
106
|
+
// The base value is the em value derived from the px value at position $base on the scale
|
107
|
+
$base-value: to-em(ms($base, $rms-base, $scale-interval));
|
108
|
+
// The adjusted value is the original value divided by the base value
|
109
|
+
$output: $output / $base-value * 1em;
|
110
|
+
}
|
111
|
+
}
|
112
|
+
|
113
|
+
// Don't insert a 0px/em media query, just output the value
|
114
|
+
@if strip-units($scale-breakpoint) == 0 {
|
57
115
|
font-size: $output;
|
58
116
|
}
|
59
117
|
@else {
|
@@ -1 +1,27 @@
|
|
1
|
-
|
1
|
+
$rms-basefont: 16px;
|
2
|
+
|
3
|
+
/*
|
4
|
+
Take a pixel value and convert it to an em value, using a base font size for reference.
|
5
|
+
|
6
|
+
@param (number) $px: pixel value to convert.
|
7
|
+
@param (number) $base: base font size to use in calculation.
|
8
|
+
@return (number) calculated em value
|
9
|
+
*/
|
10
|
+
@function to-em($px, $base: $rms-basefont) {
|
11
|
+
// If a non-pixel value was passed in, just hand it back
|
12
|
+
// Should probably tweak this behavior
|
13
|
+
@if unit($px) != 'px' {
|
14
|
+
@return $px;
|
15
|
+
}
|
16
|
+
@return ($px / $base) * 1em;
|
17
|
+
}
|
18
|
+
|
19
|
+
/*
|
20
|
+
Strip the units off a number.
|
21
|
+
|
22
|
+
@param (number) $number: number with unit to convert.
|
23
|
+
@return (number) Input number without units.
|
24
|
+
*/
|
25
|
+
@function strip-units($number) {
|
26
|
+
@return $number / ($number * 0 + 1);
|
27
|
+
}
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: responsive-modular-scale
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Geoff Kimball
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2014-01-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: modular-scale
|