modular-scale 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/README.mdown CHANGED
@@ -1,6 +1,6 @@
1
1
  # Sassy Modular Scale
2
2
 
3
- ## A Sass mixin to calculate the incremental values of the modular scale.
3
+ ## Put down the calculator and let Sass do the work.
4
4
 
5
5
  Sassy Modular Scale is a Sass based mixin that calculates the incremental values of the modular scale in proportion to a set size and ratio. It was inspired by and adapted from Tim Brown's modularscale.com.
6
6
 
@@ -27,39 +27,74 @@ Sassy Modular Scale can be used as a function, mixin or a mixin that generates a
27
27
 
28
28
  Examples using the Sass syntax:
29
29
 
30
- // Use as a function. Fill in the multiple, base-size, and ratio
31
- height: modular-scale(7, 14px, $golden)
32
-
33
- // Use as a mixin. Fill in the property, multiple, base-size, and ratio
34
- +modular-scale(line-height, 1, 14px, $golden)
35
-
36
- // This method will generate a range of classes to `@extend`
37
- +modular-scale-classes(6)
30
+ ```sass
31
+ // Use as a function. Fill in the multiple, base-size, and ratio
32
+ height: modular-scale(7, 14px, $golden)
38
33
 
39
- [role="main"]
40
- h1
41
- @extend .ms-2
42
- h2
43
- @extend .ms-1
44
- h3
45
- @extend .ms-0
34
+ // Use as a mixin. Fill in the property, multiple, base-size, and ratio
35
+ +modular-scale(line-height, 1, 14px, $golden)
46
36
 
47
- Examples using the SCSS syntax:
37
+ // This method will generate a range of classes to `@extend`
38
+ +modular-scale-classes(6)
48
39
 
49
- // Use as a function. Fill in the multiple, base-size, and ratio
50
- height: modular-scale(7, 14px, $golden);
40
+ h1
41
+ @extend .ms-2
42
+ h2
43
+ @extend .ms-1
44
+ h3
45
+ @extend .ms-0
51
46
 
52
- // Use as a mixin. Fill in the property, multiple, base-size, and ratio
53
- @include modular-scale(line-height, 1, 14px, $golden);
47
+ // You can also 'lace' multiple ratios together by
48
+ // passing them in as a list (space-separated)
49
+ .lace
50
+ width: ms(7, 14px, $golden $fourth)
51
+
52
+ // You can also set the $base-size variable to a list
53
+ // to interrelate two significant known sizes in your design
54
+ // note: the starting point of the scale will always be the *lowest* value in this list
55
+ .multibases
56
+ width: ms(7, 14px 300px, $golden)
57
+
58
+ // You can use multiple $base-sizes and multiple $ratios together
59
+ .multibase-multiratio
60
+ width: ms(7, 14px 300px, $golden $fourth)
61
+ ```
62
+
63
+ Examples using the SCSS syntax:
64
+
65
+ ```scss
66
+ // Use as a function. Fill in the multiple, base-size, and ratio
67
+ height: modular-scale(7, 14px, $golden);
68
+
69
+ // Use as a mixin. Fill in the property, multiple, base-size, and ratio
70
+ @include modular-scale(line-height, 1, 14px, $golden);
71
+
72
+ // This method will generate a range of classes to `@extend`
73
+ @include modular-scale-classes(6);
74
+
75
+ h1 { @extend .ms-2; }
76
+ h2 { @extend .ms-1; }
77
+ h3 { @extend .ms-0; }
78
+
79
+ // You can also 'lace' multiple ratios together by
80
+ // passing them in as a list (space-separated)
81
+ .lace {
82
+ width: ms(7, 14px, $golden $fourth);
83
+ }
54
84
 
55
- // This method will generate a range of classes to `@extend`
56
- @ionclude modular-scale-classes(6);
85
+ // You can also set the $base-size variable to a list
86
+ // to interrelate two significant known sizes in your design
87
+ // note: the starting point of the scale will always be the *lowest* value in this list
88
+ .multibases {
89
+ width: ms(7, 14px 300px, $golden);
90
+ }
91
+
92
+ // You can use multiple $base-sizes and multiple $ratios together
93
+ .multibase-multiratio {
94
+ width: ms(7, 14px 300px, $golden $fourth);
95
+ }
96
+ ```
57
97
 
58
- [role="main"] {
59
- h1 { @extend .ms-2; }
60
- h2 { @extend .ms-1; }
61
- h3 { @extend .ms-0; }
62
- }
63
98
 
64
99
  ## Ratios
65
100
 
@@ -84,7 +119,7 @@ Sassy Modular Scale was adapted from [modularscale.com](http://modularscale.com/
84
119
 
85
120
  ## License
86
121
 
87
- Copyright (c) 2011 [Scott Kellum](http://www.scottkellum.com/) ([@scottkellum](http://twitter.com/scottkellum)), [Adam Stacoviak](http://adamstacoviak.com/) ([@adamstac](http://twitter.com/adamstac)) and [Mason Wendell](http://birdsandmonkeys.com/) ([@canarymason](http://twitter.com/canarymason))
122
+ Copyright (c) 2011 [Scott Kellum](http://www.scottkellum.com/) ([@scottkellum](http://twitter.com/scottkellum)), [Adam Stacoviak](http://adamstacoviak.com/) ([@adamstac](http://twitter.com/adamstac)) and [Mason Wendell](http://thecodingdesigner.com/) ([@canarymason](http://twitter.com/canarymason))
88
123
 
89
124
  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
90
125
 
data/lib/modular-scale.rb CHANGED
@@ -3,7 +3,7 @@ Compass::Frameworks.register("modular-scale", :path => "#{File.dirname(__FILE__)
3
3
 
4
4
  module ModularScale
5
5
 
6
- VERSION = "0.0.2"
6
+ VERSION = "0.0.3"
7
7
  DATE = "2011-08-14"
8
8
 
9
9
  end
@@ -20,22 +20,179 @@ $class-slug: ms !default
20
20
 
21
21
  // Modular Scale function
22
22
  @function modular-scale($multiple, $base-size, $ratio)
23
+ // return the $base-size if $multiple is zero
24
+ @if $multiple == 0
25
+ @if type-of($base-size) == 'list'
26
+ $base-size: sort-list($base-size)
27
+ @return nth($base-size, 1)
28
+ // return just the simple $base-size value if it's not a list
29
+ @return $base-size
23
30
 
24
- // On init, $modular-scale equals the default value of $base-size or the value passed to the function
25
- $modular-scale: $base-size
31
+ // if multiple base-sizes are passed in as a list
32
+ // and multiple ratios are passed in as a list
33
+ // calculate values in using each base-size / ratio combination
34
+ @if type-of($base-size) == 'list' and type-of($ratio) == 'list'
35
+ @return ms-multibase-multiratio($multiple, $base-size, $ratio)
36
+
37
+ // if multiple base-sizes are passed in as a list
38
+ // calculate values in using each base-size
39
+ @if type-of($base-size) == 'list' and type-of($ratio) == 'number'
40
+ @return ms-multibase($multiple, $base-size, $ratio)
41
+
42
+ // if multiple ratios are passed in as a list
43
+ // calculate values in using each ratio
44
+ @if type-of($base-size) == 'number' and type-of($ratio) == 'list'
45
+ @return ms-multiratio($multiple, $base-size, $ratio)
46
+
47
+ // If there are no lists just run the simple function
48
+ @return exponent($ratio, $multiple) * $base-size
49
+
50
+
51
+ // calculate values in using each base-size / ratio combination
52
+ @function ms-multibase-multiratio($multiple, $base-size, $ratio)
53
+ // start with an empty list to place all values in
54
+ $scale-values: ()
55
+ // make sure base sizes are in ascending order
56
+ $base-size: sort-list($base-size)
57
+ // take each base-size in turn
58
+ $k: 1
59
+ @while $k <= length($base-size)
60
+ // add each $base-size to the list except the first
61
+ @if $k > 1
62
+ $scale-values: append($scale-values, nth($base-size, $k))
63
+ // take each ratio in turn
64
+ $j: 1
65
+ @while $j <= length($ratio)
66
+ // reset $modular-scale for each set
67
+ $modular-scale: nth($base-size, $k)
68
+ // do the scale for each base-size using this ratio
69
+ @if $multiple > 0
70
+ // up $multiple times
71
+ // and add the result to $scale-values
72
+ @for $i from 1 through $multiple
73
+ $modular-scale: exponent(nth($ratio, $j), $i) * nth($base-size, $k)
74
+ $scale-values: append($scale-values, $modular-scale)
75
+ // and down until the value is lower than the lowest $base-size
76
+ // and add the result to $scale-values
77
+ $i: -1
78
+ $modular-scale: nth($base-size, $k)
79
+ @while $modular-scale >= nth($base-size, 1)
80
+ $modular-scale: exponent(nth($ratio, $j), $i) * nth($base-size, $k)
81
+ $scale-values: append($scale-values, $modular-scale)
82
+ $i: $i - 1
83
+ @if $multiple < 0
84
+ // do the scale down for each set to below 1px
85
+ $i: -1
86
+ $modular-scale: nth($base-size, $k)
87
+ @while $modular-scale > 1
88
+ $modular-scale: exponent(nth($ratio, $j), $i) * nth($base-size, $k)
89
+ $scale-values: append($scale-values, $modular-scale)
90
+ $i: $i - 1
91
+ $j: $j + 1
92
+ $k: $k + 1
93
+ // return trimmed and sorted final list
94
+ @return trim-sort($multiple, $scale-values, $base-size)
95
+
96
+
97
+ // calculate values in using each base-size
98
+ @function ms-multibase($multiple, $base-size, $ratio)
99
+ // start with an empty list to place all values in
100
+ $scale-values: ()
101
+ // make sure base sizes are in ascending order
102
+ $base-size: sort-list($base-size)
103
+ // take each base-size in turn
104
+ $k: 1
105
+ @while $k <= length($base-size)
106
+ // add each $base-size to the list except the first
107
+ @if $k > 1
108
+ $scale-values: append($scale-values, nth($base-size, $k))
109
+ // reset $modular-scale for each set
110
+ $modular-scale: nth($base-size, $k)
111
+ // do the scale for each base-size using this ratio
112
+ @if $multiple > 0
113
+ // up $multiple times
114
+ // and add the result to $scale-values
115
+ @for $i from 1 through $multiple
116
+ $modular-scale: exponent($ratio, $i) * nth($base-size, $k)
117
+ $scale-values: append($scale-values, $modular-scale)
118
+ // and down until the value is lower than the lowest $base-size
119
+ // and add the result to $scale-values
120
+ $i: -1
121
+ $modular-scale: nth($base-size, $k)
122
+ @while $modular-scale >= nth($base-size, 1)
123
+ $modular-scale: exponent($ratio, $i) * nth($base-size, $k)
124
+ $scale-values: append($scale-values, $modular-scale)
125
+ $i: $i - 1
126
+ @if $multiple < 0
127
+ // do the scale down for each set to below 1px
128
+ $i: -1
129
+ $modular-scale: nth($base-size, $k)
130
+ @while $modular-scale > 1
131
+ $modular-scale: exponent($ratio, $i) * nth($base-size, $k)
132
+ $scale-values: append($scale-values, $modular-scale)
133
+ $i: $i - 1
134
+ $k: $k + 1
135
+ // return trimmed and sorted final list
136
+ @return trim-sort($multiple, $scale-values, $base-size)
26
137
 
138
+
139
+ // calculate values in using each ratio
140
+ @function ms-multiratio($multiple, $base-size, $ratio)
141
+ // start with an empty list to place all values in
142
+ $scale-values: ()
27
143
  // If $multiple is a positive integer (up the scale)
28
144
  @if $multiple > 0
29
- @for $i from 1 through $multiple
30
- $modular-scale: $modular-scale * $ratio
31
-
145
+ // take each ratio in turn
146
+ $j: 1
147
+ @while $j <= length($ratio)
148
+ // reset $modular-scale for each set
149
+ $modular-scale: $base-size
150
+ // do the scale using this ratio thru the multiple, and add the result to $scale-values
151
+ @for $i from 1 through $multiple
152
+ $modular-scale: exponent(nth($ratio, $j), $i) * $base-size
153
+ $scale-values: append($scale-values, $modular-scale)
154
+ $j: $j + 1
155
+ // sort acsending
156
+ $scale-values: sort-list($scale-values)
157
+ // return the final value using the laced list
158
+ @return nth($scale-values, $multiple)
32
159
  // If $multiple is a negative integer (down the scale)
33
160
  @if $multiple < 0
34
- @for $i from 1 through ($multiple * -1)
35
- $modular-scale: $modular-scale / $ratio
36
-
37
- // Return the new or unchanged value of $modular-scale
38
- @return $modular-scale
161
+ // take each ratio in turn
162
+ $j: 1
163
+ @while $j <= length($ratio)
164
+ // reset $modular-scale for each set
165
+ $modular-scale: $base-size
166
+ // do the scale using this ratio thru the multiple, and add the result to $scale-values
167
+ @for $i from 1 through ($multiple * -1)
168
+ $modular-scale: exponent(nth($ratio, $j), -$i) * $base-size
169
+ $scale-values: append($scale-values, $modular-scale)
170
+ $j: $j + 1
171
+ // sort decending
172
+ $scale-values: sort-list($scale-values, 'dec')
173
+ // return the final value using the laced list
174
+ @return nth($scale-values, $multiple * -1)
175
+
176
+
177
+ // trim and sort the final list
178
+ @function trim-sort($multiple, $scale-values, $base-size)
179
+ @if $multiple > 0
180
+ // trim list so we can count from the lowest $base-size
181
+ $scale-values: trim-list($scale-values, nth($base-size, 1))
182
+ // sort acsending
183
+ $scale-values: sort-list($scale-values)
184
+ // return the final value using the laced list
185
+ @return nth($scale-values, $multiple)
186
+ @else
187
+ // trim list so we can count from the lowest $base-size
188
+ $scale-values: trim-list($scale-values, nth($base-size, 1), 'dec')
189
+ // sort acsending
190
+ $scale-values: sort-list($scale-values, 'dec')
191
+ // return the final value using the laced list
192
+ @return nth($scale-values, -$multiple)
193
+
194
+
195
+ /////////////////////////////////////////////////////////////////////////
39
196
 
40
197
  // Shortcut
41
198
  @function ms($multiple, $base-size, $ratio)
@@ -48,9 +205,90 @@ $class-slug: ms !default
48
205
  #{$property}: modular-scale($multiple, $base-size, $ratio)
49
206
 
50
207
  // Classes Mixin
51
- =modular-scale-classes($multiple, $property)
52
-
208
+ =modular-scale-classes($multiple, $property, $class-slug, $base-size, $ratio)
53
209
  // Loop from 0 through the value of $multiple and generate a range of classes
54
210
  @for $i from 0 through $multiple
55
211
  .#{$class-slug}-#{$i}
56
- +modular-scale($property, $i)
212
+ +modular-scale($property, $i, $base-size, $ratio)
213
+
214
+ /////////////////////////////////////////////////////////////////////////
215
+
216
+
217
+ // Sass exponent support
218
+ @function exponent($base, $exponent)
219
+ // reset value
220
+ $value: $base
221
+ // positive intergers get multiplied
222
+ @if $exponent > 1
223
+ @for $i from 2 through $exponent
224
+ $value: $value * $base
225
+ // negitive intergers get divided. A number divided by itself is 1
226
+ @if $exponent < 1
227
+ @for $i from 0 through -$exponent
228
+ $value: $value / $base
229
+ // return the last value written
230
+ @return $value
231
+
232
+
233
+ // Sass list sorting support
234
+ @function sort-list($list, $dir: 'asc')
235
+ // built-in list sorting in Sass would make this go away.
236
+ // declare some empty lists to put our new order and temporary values
237
+ $new-order: ()
238
+ $temp: ()
239
+ // fill $temp with the contents of $list
240
+ $temp: join($temp, $list)
241
+ // if sorting ascending
242
+ @if $dir == 'asc'
243
+ // loop through all values in $list
244
+ @for $i from 1 through length($list)
245
+ // impossibly high starter value to compare
246
+ $low: 1000000
247
+ // check for lowest value in $temp
248
+ @for $j from 1 through length($temp)
249
+ @if nth($temp, $j) < $low
250
+ $low: nth($temp, $j)
251
+ // add lowest value to $new-order
252
+ $new-order: append($new-order, $low)
253
+ // empty $temp for the next comparison
254
+ $temp: ()
255
+ // re-populate $temp with remaining values to sort
256
+ @for $k from 1 through length($list)
257
+ @if nth($list, $k) > $low
258
+ $temp: append($temp, nth($list, $k))
259
+ @if $dir == 'dec'
260
+ // loop through all values in $list
261
+ @for $i from 1 through length($list)
262
+ // 0 starter value
263
+ $high: 0
264
+ // check for highest value in $temp
265
+ @for $j from 1 through length($temp)
266
+ @if nth($temp, $j) > $high
267
+ $high: nth($temp, $j)
268
+ $new-order: append($new-order, $high)
269
+ // empty $temp for the next comparison
270
+ $temp: ()
271
+ // re-populate $temp with remaining values to sort
272
+ @for $k from 1 through length($list)
273
+ @if nth($list, $k) < $high
274
+ $temp: append($temp, nth($list, $k))
275
+ @return $new-order
276
+
277
+
278
+ // Sass list trimming support
279
+ @function trim-list($list, $start, $dir: 'asc')
280
+ // built-in list trimming in Sass would make this go away.
281
+ // declare some empty lists to put our trimmed values
282
+ $trimmed: ()
283
+ // if sorting ascending
284
+ @if $dir == 'asc'
285
+ // loop through all values in $list
286
+ @for $i from 1 through length($list)
287
+ @if nth($list, $i) >= $start
288
+ $trimmed: append($trimmed, nth($list, $i))
289
+ @if $dir == 'dec'
290
+ // loop through all values in $list
291
+ @for $i from 1 through length($list)
292
+ @if nth($list, $i) <= $start
293
+ $trimmed: append($trimmed, nth($list, $i))
294
+ @return $trimmed
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: modular-scale
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.0.2
5
+ version: 0.0.3
6
6
  platform: ruby
7
7
  authors:
8
8
  - Scott Kellum
@@ -27,7 +27,7 @@ dependencies:
27
27
  version_requirements: *id001
28
28
  description: Sassy Modular Scale calculates the incremental values of the modular scale.
29
29
  email:
30
- - scott@treesaver.net
30
+ - scott@scottkellum.com
31
31
  - adam@stacoviak.com
32
32
  - mason@zivtech.com
33
33
  executables: []
@@ -53,7 +53,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
53
53
  requirements:
54
54
  - - ">="
55
55
  - !ruby/object:Gem::Version
56
- hash: -2068545331778000288
56
+ hash: 2683294284608242582
57
57
  segments:
58
58
  - 0
59
59
  version: "0"