Skip to content

Commit 8907a28

Browse files
author
Jeff Escalante
committed
Merge pull request #26 from jenius/named-scales
added support for named scale items
2 parents 90f7664 + a3f87dd commit 8907a28

File tree

5 files changed

+50
-4
lines changed

5 files changed

+50
-4
lines changed

readme.md

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,21 @@ A list of values that you can reference by index in most of the mixins listed be
4343
rupture.scale = 0 400px 600px 800px 1050px
4444
```
4545

46+
##### `rupture.scale-names`
47+
A list of strings you can reference that correspond to their index location in `rupture.scale`. This works exactly like [breakpoint-slicer](https://github.com/lolmaus/breakpoint-slicer#calling-slices-by-names-rather-than-numbers)
48+
49+
```
50+
rupture.scale = 0 400px 600px 800px 1050px
51+
52+
// └────┬────┘ └────┬────┘ └────┬────┘ └────┬────┘ └────┬────
53+
// Slice numbers: 1 2 3 4 5
54+
rupture.scale-names: 'xs' 's' 'm' 'l' 'xl'
55+
```
56+
57+
```js
58+
rupture.scale-names = 'xs' 's' 'm' 'l' 'xl'
59+
```
60+
4661
##### `rupture.enable-em-breakpoints`
4762
Enables Rupture's [PX to EM unit conversion](#px-to-em-unit-conversion) feature. If set to true, pixel breakpoint values will be automatically converted into em values.
4863

@@ -190,7 +205,7 @@ rupture.anti-overlap = 1px 0.0625em 0.0625rem // explicit relative values will b
190205
If you don't want to enable anti-overlapping globally, you can enable or disable it locally by passing the `anti-overlap` keyword argument to any of the mixins except `retina()`. This works exactly like the global `rupture.anti-overlap` variable, except you can specify it per mixin call. For example:
191206

192207
```
193-
.overlap-force
208+
.overlap-force
194209
text-align center
195210
+at(2, anti-overlap: true)
196211
text-align right
@@ -224,7 +239,7 @@ rupture.anti-overlap = 1px
224239
text-align right
225240
+at(3)
226241
text-align left
227-
242+
228243
/**
229244
* compiles to:
230245
* .some-ui-element {

rupture/index.styl

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,14 @@ rupture = {
1111
}
1212

1313
rupture.scale = 0 (rupture.mobile-cutoff) 600px 800px (rupture.desktop-cutoff)
14+
rupture.scale-names = 'xs' 's' 'm' 'l' 'xl'
15+
16+
-get-index(item, list)
17+
index = false
18+
for list-item, i in list
19+
if list-item is item
20+
index = i
21+
return index
1422

1523
-convert-to(to-unit, value, context = rupture.base-font-size)
1624
from-unit = unit(value)
@@ -44,7 +52,7 @@ rupture.scale = 0 (rupture.mobile-cutoff) 600px 800px (rupture.desktop-cutoff)
4452
if (side is 'min' and -shift > 0) or (side is 'max' and -shift < 0)
4553
n = n + -shift
4654
return n
47-
55+
4856
-is-positive(n)
4957
return n >= 0
5058

@@ -76,6 +84,13 @@ rupture.scale = 0 (rupture.mobile-cutoff) 600px 800px (rupture.desktop-cutoff)
7684
// - +between(200px, 4) custom:scale
7785

7886
between(min, max, anti-overlap = rupture.anti-overlap, density = null, orientation = null)
87+
88+
if typeof(min) is 'string'
89+
min = rupture.scale[-get-index(min, rupture.scale-names)]
90+
91+
if typeof(max) is 'string'
92+
max = rupture.scale[-get-index(max, rupture.scale-names)]
93+
7994
-min = rupture.scale[min - 1] unless -is-zero(min) or (not -on-scale(min))
8095
-max = rupture.scale[max] unless not -on-scale(max)
8196
-min ?= min

test/fixtures/expected/named.css

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
.hello {
2+
color: #f00;
3+
}
4+
@media only screen and (min-width: 400px) and (max-width: 800px) {
5+
.hello {
6+
color: #fff;
7+
}
8+
}

test/fixtures/named.styl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
.hello
2+
color: red
3+
4+
+between('s', 'l')
5+
color: white

test/test.coffee

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,4 +54,7 @@ describe 'basic', ->
5454
match_expected('ems.styl', done)
5555

5656
it 'adds anti-overlap correction to prevent overlapping media queries', (done) ->
57-
match_expected('overlap.styl', done)
57+
match_expected('overlap.styl', done)
58+
59+
it 'supports named scale units', (done) ->
60+
match_expected('named.styl', done)

0 commit comments

Comments
 (0)