Skip to content

Commit 8a503c4

Browse files
author
Jeff Escalante
committed
Merge pull request #18 from jenius/scoped-globals
Scope global variables under 'rupture'
2 parents 7d20f69 + 5f8bd1f commit 8a503c4

File tree

4 files changed

+36
-31
lines changed

4 files changed

+36
-31
lines changed

readme.md

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,19 +28,19 @@ Before getting started, I would recommend [reading this](https://github.com/lolm
2828

2929
### Variables
3030

31-
A few variables are exposed that can be customized, each of them are listed below:
31+
A few variables are exposed that can be customized, each of them are listed below. All of these variables are scoped under `rupture` so that there are no conflicts with css keywords or other libraries.
3232

33-
##### `mobile-cutoff`
33+
##### `rupture.mobile-cutoff`
3434
Pixel value where the `mobile` mixin kicks in, also the lower bound of the `tablet` mixin.
3535

36-
##### `desktop-cutoff`
36+
##### `rupture.desktop-cutoff`
3737
Pixel value where the `desktop` mixin kicks in, also the upper bound of the `tablet` mixin.
3838

39-
##### `scale`
39+
##### `rupture.scale`
4040
A list of values that you can reference by index in most of the mixins listed below. This works exactly like [breakpoint-slicer](https://github.com/lolmaus/breakpoint-slicer). Default looks like this:
4141

4242
```js
43-
scale = 0 400px 600px 800px 1050px
43+
rupture.scale = 0 400px 600px 800px 1050px
4444
```
4545

4646
### Mixins
@@ -63,16 +63,16 @@ Alias of `below`. Styles take effect from zero up to the provided [measure](#wha
6363
When the screen size is _between_ the two provided [measure](#what-is-a-measure), the styles in the block will take effect.
6464

6565
##### `+at(measure)`
66-
Intended for use with scale measures, when the screen size is between the provided scale [measure](#what-is-a-measure) and the one below it, the styles in the block will take effect. For example, if your scale was something like `scale = 0 400px 600px`, and you used the mixin like `+at(2)`, it would kick in between 400 and 600px (remember, scale is zero indexed, so 2 is the third value, and one less is the second). If you use this with a value, it will not have much effect, as it will be at one specific pixel value rather than a range like you want.
66+
Intended for use with scale measures, when the screen size is between the provided scale [measure](#what-is-a-measure) and the one below it, the styles in the block will take effect. For example, if your scale was something like `rupture.scale = 0 400px 600px`, and you used the mixin like `+at(2)`, it would kick in between 400 and 600px (remember, scale is zero indexed, so 2 is the third value, and one less is the second). If you use this with a value, it will not have much effect, as it will be at one specific pixel value rather than a range like you want.
6767

6868
##### `+mobile()`
69-
When the screen size is 400px (defined by `mobile-cutoff`) or less, the styles in the block will take effect.
69+
When the screen size is 400px (defined by `rupture.mobile-cutoff`) or less, the styles in the block will take effect.
7070

7171
##### `+tablet()`
72-
When the screen size is between 1050px (defined by `desktop-cutoff`) and 400px (defined by `mobile-cutoff`), the styles in the block will take effect.
72+
When the screen size is between 1050px (defined by `rupture.desktop-cutoff`) and 400px (defined by `mobile-cutoff`), the styles in the block will take effect.
7373

7474
##### `+desktop()`
75-
When the screen size is 1050px (defined by `desktop-cutoff`) or more, the styles in the block will take effect.
75+
When the screen size is 1050px (defined by `rupture.desktop-cutoff`) or more, the styles in the block will take effect.
7676

7777
##### `+retina()`
7878
When the device has a pixel density of over 1.5 (retina), the styles in the block will take effect.
@@ -83,15 +83,15 @@ It is a popular opinion that using `em` units for media queries is a good practi
8383

8484
Rupture allows you to automatically convert all your breakpoint units from `px` to `em`.
8585

86-
All you need to do to enable this behavior is to define an optional `base-font-size` (unless already defined) and set `enable-em-breakpoints` to `true`.
86+
All you need to do to enable this behavior is to define an optional `rupture.base-font-size` (unless already defined) and set `rupture.enable-em-breakpoints` to `true`.
8787

88-
`base-font-size` defaults to `16px`.
88+
`rupture.base-font-size` defaults to `16px`.
8989

9090
Example:
9191

9292
```
9393
// base-font-size = 18px (commented out because it's optional and we want 16px)
94-
enable-em-breakpoints = true
94+
rupture.enable-em-breakpoints = true
9595
9696
.some-ui-element
9797
width: 50%

rupture/index.styl

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,22 @@
1-
mobile-cutoff ?= 400px
2-
desktop-cutoff ?= 1050px
3-
enable-em-breakpoints ?= false
4-
base-font-size ?= 16px
5-
scale ?= 0 mobile-cutoff 600px 800px desktop-cutoff
1+
base-font-size ?= 16px
62

7-
-convert-to-ems(target, context = base-font-size)
3+
rupture = {
4+
mobile-cutoff: 400px
5+
desktop-cutoff: 1050px
6+
enable-em-breakpoints: false
7+
base-font-size: base-font-size
8+
}
9+
10+
rupture.scale = 0 400px 600px 800px 1050px
11+
12+
-convert-to-ems(target, context = rupture.base-font-size)
813
return unit((target / context), 'em')
914

1015
-on-scale(n)
1116
return unit(n) is ''
1217

1318
-larger-than-scale(n)
14-
return (n > (length(scale) - 1)) and -on-scale(n)
19+
return (n > (length(rupture.scale) - 1)) and -on-scale(n)
1520

1621
-is-zero(n)
1722
return n is 0
@@ -27,24 +32,24 @@ scale ?= 0 mobile-cutoff 600px 800px desktop-cutoff
2732

2833
between(min, max)
2934
if (-on-scale(min)) and (-on-scale(max))
30-
-min = -is-zero(min) ? 0 : scale[min - 1]
31-
-max = scale[max]
35+
-min = -is-zero(min) ? 0 : rupture.scale[min - 1]
36+
-max = rupture.scale[max]
3237
else if (-on-scale(min)) and (not -on-scale(max))
33-
-min = -is-zero(min) ? 0 : scale[min - 1]
38+
-min = -is-zero(min) ? 0 : rupture.scale[min - 1]
3439
-max = max
3540
else if (not -on-scale(min)) and (-on-scale(max))
3641
-min = min
37-
-max = scale[max]
42+
-max = rupture.scale[max]
3843
else
3944
-min = min
4045
-max = max
4146
if -min is not 0
42-
-min = -convert-to-ems(-min) if enable-em-breakpoints
47+
-min = -convert-to-ems(-min) if rupture.enable-em-breakpoints
4348
condition = 'only screen and (min-width: %s)' % (-min)
4449
else
4550
condition = 'only screen'
4651
unless -larger-than-scale(max)
47-
-max = -convert-to-ems(-max) if enable-em-breakpoints
52+
-max = -convert-to-ems(-max) if rupture.enable-em-breakpoints
4853
condition = condition + ' and (max-width: %s)' % (-max)
4954
@media condition
5055
{block}
@@ -54,7 +59,7 @@ at(scale-point)
5459
{block}
5560

5661
from(scale-point)
57-
+between(scale-point, length(scale))
62+
+between(scale-point, length(rupture.scale))
5863
{block}
5964

6065
above = from
@@ -66,15 +71,15 @@ to(scale-point)
6671
below = to
6772

6873
mobile()
69-
+below(mobile-cutoff)
74+
+below(rupture.mobile-cutoff)
7075
{block}
7176

7277
tablet()
73-
+between(mobile-cutoff, desktop-cutoff)
78+
+between(rupture.mobile-cutoff, rupture.desktop-cutoff)
7479
{block}
7580

7681
desktop()
77-
+above(desktop-cutoff)
82+
+above(rupture.desktop-cutoff)
7883
{block}
7984

8085
retina()

test/fixtures/between.styl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,5 @@
1313
+between(0, 500px)
1414
color: #eee
1515

16-
+between(200px, length(scale))
16+
+between(200px, length(rupture.scale))
1717
color: #ccc

test/fixtures/ems.styl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
enable-em-breakpoints = true
1+
rupture.enable-em-breakpoints = true
22

33
.thing
44
color: red

0 commit comments

Comments
 (0)