breakpoint 0.3 → 1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.markdown +6 -0
- data/README.markdown +17 -4
- data/lib/breakpoint.rb +2 -2
- data/stylesheets/_breakpoint.scss +221 -122
- metadata +4 -4
data/CHANGELOG.markdown
CHANGED
@@ -1,5 +1,11 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
## 1.0 - June 22, 2012
|
4
|
+
* Refactor of the underlying logic to make everything work better and make the world a happy place.
|
5
|
+
* Added default options for Default Feature, Default Media, and Default Feature Pair.
|
6
|
+
* Changed default media from "Screen" to "All".
|
7
|
+
* Added ability to have all px/pt/percentage media queries transformed into em based media queries.
|
8
|
+
|
3
9
|
## 0.3 - June 18, 2012
|
4
10
|
* Rewrote 'device-pixel-ratio' conversions to change from prefixed nightmarish hell to Resolution standard based on the [W3C Unprefixing -webkit-device-pixel-ratio article](http://www.w3.org/blog/CSS/2012/06/14/unprefix-webkit-device-pixel-ratio/)
|
5
11
|
* Large README update covering feature set, installation, assumptions, and more.
|
data/README.markdown
CHANGED
@@ -6,11 +6,13 @@ Breakpoint aims to make writing media queries in Sass super simple. Create a var
|
|
6
6
|
|
7
7
|
Breakpoint makes the following assumptions:
|
8
8
|
|
9
|
-
* All queries are assumed to be
|
10
|
-
* A single value query is assumed to be against the `min-width` feature. This can be overwritten by adding the feature you'd like to query against.
|
11
|
-
* A two value query is assumed to be against the `min-width`/`max-width` feature pair. This can be overwritten by adding the feature you'd like to query against.
|
9
|
+
* All queries are assumed to be for all media types. This can be overwritten by specifying the media you'd like to query against as the second parameter in the breakpoint mixin.
|
10
|
+
* A single value query is assumed to be against the `min-width` feature. This can be overwritten by adding the feature you'd like to query against or by changing the provided default variable.
|
11
|
+
* A two value query is assumed to be against the `min-width`/`max-width` feature pair. This can be overwritten by adding the feature you'd like to query against or by changing the provided default variable.
|
12
12
|
* Unprefixed `device-pixel-ratio` queries are transformed into the standard `resolution` breakpoint based on the [W3C recommendation for how to do so](http://www.w3.org/blog/CSS/2012/06/14/unprefix-webkit-device-pixel-ratio/). This can be overwritten by passing in prefixed the needed prefixed feature.
|
13
13
|
|
14
|
+
If you'd prefer to use string names to identify your queries as opposed to variables, check out [Respond-To](https://github.com/snugug/respond-to); a string based naming API for Breakpoint.
|
15
|
+
|
14
16
|
## Requirements
|
15
17
|
|
16
18
|
Breakpoint is a Compass extension, so make sure you have [Sass and Compass Installed](http://compass-style.org/install/) in order to use its awesomeness!
|
@@ -28,9 +30,20 @@ Breakpoint is a Compass extension, so make sure you have [Sass and Compass Insta
|
|
28
30
|
#### Import the breakpoint partial at the top of your working file
|
29
31
|
`@import "breakpoint";`
|
30
32
|
|
31
|
-
|
32
33
|
## Setup
|
33
34
|
|
35
|
+
### Breakpoint Options
|
36
|
+
|
37
|
+
Breakpoint provides a few default options that you can change.
|
38
|
+
|
39
|
+
* `$breakpoint-default-media` - Defaults to 'all'. If you do not pass a media type into the breakpoint mixin, this is the media type that will be used.
|
40
|
+
* `$breakpoint-default-feature` - Defaults to 'min-width'. If you write a breakpoint with only a number, this is the feature that is used.
|
41
|
+
* `$breakpoint-default-pair` - Defaults to 'width'. If you write a breakpoint with two numbers but do not specify the feature, this is the feature that is used.
|
42
|
+
* `$breakpoint-to-ems` - Defaults to 'false'. If set to true, all pt/px/percent numbers will be converted to em units for better, more accessable media queries.
|
43
|
+
|
44
|
+
### Usage
|
45
|
+
|
46
|
+
|
34
47
|
```scss
|
35
48
|
// create $breakpoint variables like so
|
36
49
|
// assume $breakpoint-default-feature if only a number
|
data/lib/breakpoint.rb
CHANGED
@@ -1,80 +1,122 @@
|
|
1
|
-
|
2
|
-
//
|
3
|
-
|
4
|
-
|
5
|
-
|
1
|
+
//////////////////////////////
|
2
|
+
// Default Variables
|
3
|
+
//////////////////////////////
|
4
|
+
$breakpoint-default-feature: 'min-width' !default;
|
5
|
+
$breakpoint-default-media: 'all' !default;
|
6
|
+
$breakpoint-default-pair: 'width' !default;
|
7
|
+
$breakpoint-to-ems: false !default;
|
6
8
|
|
7
|
-
|
8
|
-
//
|
9
|
-
|
10
|
-
|
11
|
-
//
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
//
|
17
|
-
|
18
|
-
|
19
|
-
//
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
$breakpoint-
|
9
|
+
//////////////////////////////
|
10
|
+
// Breakpoint Mixin
|
11
|
+
//////////////////////////////
|
12
|
+
@mixin breakpoint($breakpoint, $media: $breakpoint-default-media) {
|
13
|
+
// Query and Media String Defaults
|
14
|
+
$query: false !default;
|
15
|
+
$query-holder: false !default;
|
16
|
+
$media-string: false !default;
|
17
|
+
|
18
|
+
// Holder for Count;
|
19
|
+
$first: true !default;
|
20
|
+
|
21
|
+
// Initialize Query String
|
22
|
+
@if $media != 'all' {
|
23
|
+
$media-string: "#{$media} ";
|
24
|
+
}
|
25
|
+
@else {
|
26
|
+
$media-string: "";
|
27
|
+
}
|
28
|
+
|
29
|
+
// If we have a single query, let's just work with that.
|
30
|
+
@if type-of(nth($breakpoint, 1)) != 'list' {
|
31
|
+
$query: breakpoint-switch($breakpoint, $media-string, true);
|
32
|
+
}
|
33
|
+
@else {
|
34
|
+
@each $bkpt in $breakpoint {
|
35
|
+
@if $first == true {
|
36
|
+
$query: breakpoint-switch($bkpt, $media-string, true);
|
37
|
+
$first: false;
|
38
|
+
}
|
39
|
+
@else {
|
40
|
+
$query: join($query, breakpoint-switch($bkpt, $media-string));
|
41
|
+
}
|
42
|
+
}
|
43
|
+
}
|
44
|
+
|
45
|
+
@media #{$query} {
|
46
|
+
@content;
|
47
|
+
}
|
48
|
+
}
|
30
49
|
|
31
|
-
@
|
32
|
-
// Feature/Value
|
33
|
-
$feature:
|
34
|
-
$
|
35
|
-
|
36
|
-
$
|
37
|
-
$
|
38
|
-
$
|
39
|
-
$
|
40
|
-
|
41
|
-
|
42
|
-
$
|
43
|
-
|
44
|
-
|
45
|
-
$
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
// Min/Max for given
|
65
|
-
$query-string: breakpoint-concatenate($query-string, nth($breakpoint, 1), "min-#{nth($breakpoint, 3)}");
|
66
|
-
$query-string: breakpoint-concatenate($query-string, nth($breakpoint, 2), "max-#{nth($breakpoint, 3)}");
|
50
|
+
@function breakpoint-switch($breakpoint, $media-string, $first: false) {
|
51
|
+
// Feature/Value/Length/Query Placehoders:
|
52
|
+
$feature: false !default;
|
53
|
+
$min-feature: "min-#{$breakpoint-default-pair}" !default;
|
54
|
+
$max-feature: "max-#{$breakpoint-default-pair}" !default;
|
55
|
+
$value: false !default;
|
56
|
+
$min-value: false !default;
|
57
|
+
$max-value: false !default;
|
58
|
+
$length: false !default;
|
59
|
+
$query: false !default;
|
60
|
+
|
61
|
+
$length: length($breakpoint);
|
62
|
+
// Check to see if there is only one item.
|
63
|
+
@if $length == 1 {
|
64
|
+
$value: $breakpoint;
|
65
|
+
@if type-of($breakpoint) == 'number' {
|
66
|
+
$feature: $breakpoint-default-feature;
|
67
|
+
}
|
68
|
+
|
69
|
+
// If EM Breakpoints are active, do it!
|
70
|
+
@if $breakpoint-to-ems and type-of($value) == 'number' {
|
71
|
+
$value: breakpoint-to-base-em($value);
|
72
|
+
}
|
73
|
+
// Build the Query
|
74
|
+
$query: breakpoint-generate($media-string, $feature, $value, $first);
|
75
|
+
}
|
76
|
+
@else if $length == 2 {
|
77
|
+
// If both are numbers, we've got a double!
|
78
|
+
@if type-of(nth($breakpoint, 1)) == 'number' and type-of(nth($breakpoint, 2)) == 'number' {
|
79
|
+
// See which is larger.
|
80
|
+
@if nth($breakpoint, 1) > nth($breakpoint, 2) {
|
81
|
+
$min-value: nth($breakpoint, 2);
|
82
|
+
$max-value: nth($breakpoint, 1);
|
67
83
|
}
|
68
84
|
@else {
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
85
|
+
$min-value: nth($breakpoint, 1);
|
86
|
+
$max-value: nth($breakpoint, 2);
|
87
|
+
}
|
88
|
+
|
89
|
+
// If EM Breakpoints are active, do it!
|
90
|
+
@if $breakpoint-to-ems and type-of($min-value) == 'number' {
|
91
|
+
$min-value: breakpoint-to-base-em($min-value);
|
74
92
|
}
|
93
|
+
@if $breakpoint-to-ems and type-of($max-value) == 'number' {
|
94
|
+
$max-value: breakpoint-to-base-em($max-value);
|
95
|
+
}
|
96
|
+
|
97
|
+
// Min/Max for given
|
98
|
+
$query: breakpoint-generate($media-string, $min-feature, $min-value, $first);
|
99
|
+
$query: join($query, breakpoint-generate($media-string, $max-feature, $max-value));
|
75
100
|
}
|
76
|
-
@else if type-of(nth($breakpoint, 1)) == string
|
77
|
-
|
101
|
+
@else if type-of(nth($breakpoint, 1)) == 'string' and type-of(nth($breakpoint, 2)) == 'string' {
|
102
|
+
@if breakpoint-string-value(nth($breakpoint, 1)) == true {
|
103
|
+
$feature: nth($breakpoint, 1);
|
104
|
+
$value: nth($breakpoint, 2);
|
105
|
+
}
|
106
|
+
@else {
|
107
|
+
$feature: nth($breakpoint, 2);
|
108
|
+
$value: nth($breakpoint, 1);
|
109
|
+
}
|
110
|
+
|
111
|
+
// If EM Breakpoints are active, do it!
|
112
|
+
@if $breakpoint-to-ems and type-of($value) == 'number' {
|
113
|
+
$value: breakpoint-to-base-em($value);
|
114
|
+
}
|
115
|
+
|
116
|
+
// Build the Query
|
117
|
+
$query: breakpoint-generate($media-string, $feature, $value, $first);
|
118
|
+
}
|
119
|
+
@else {
|
78
120
|
// Because we can have either the first or second option be the feature, we switch on it.
|
79
121
|
@if type-of(nth($breakpoint, 1)) == string {
|
80
122
|
$feature: nth($breakpoint, 1);
|
@@ -84,79 +126,127 @@ $breakpoint-default-feature: min-width !default;
|
|
84
126
|
$feature: nth($breakpoint, 2);
|
85
127
|
$value: nth($breakpoint, 1);
|
86
128
|
}
|
87
|
-
|
88
|
-
|
89
|
-
@if $feature == 'device-pixel-ratio' {
|
129
|
+
|
130
|
+
@if $feature == 'device-pixel-ratio' or $feature == 'min-device-pixel-ratio' or $feature == 'max-device-pixel-ratio' {
|
90
131
|
$value: 96 * $value * 1dpi;
|
91
|
-
$feature
|
92
|
-
|
132
|
+
@if $feature == 'device-pixel-ratio' {
|
133
|
+
$feature: 'resolution';
|
134
|
+
}
|
135
|
+
@else if $feature == 'min-device-pixel-ratio' {
|
136
|
+
$feature: 'min-resolution';
|
137
|
+
}
|
138
|
+
@else if $feature == 'max-device-pixel-ratio' {
|
139
|
+
$feature: 'max-resolution';
|
140
|
+
}
|
93
141
|
}
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
$
|
142
|
+
|
143
|
+
// If EM Breakpoints are active, do it!
|
144
|
+
@if $breakpoint-to-ems and type-of($value) == 'number' {
|
145
|
+
$value: breakpoint-to-base-em($value);
|
98
146
|
}
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
147
|
+
|
148
|
+
// Build the Query
|
149
|
+
$query: breakpoint-generate($media-string, $feature, $value, $first);
|
150
|
+
}
|
151
|
+
}
|
152
|
+
@else if $length == 3 {
|
153
|
+
@if type-of(nth($breakpoint, 1)) == 'string' {
|
154
|
+
$feature: nth($breakpoint, 1);
|
155
|
+
// See which is larger.
|
156
|
+
@if nth($breakpoint, 2) > nth($breakpoint, 3) {
|
157
|
+
$min-value: nth($breakpoint, 3);
|
158
|
+
$max-value: nth($breakpoint, 2);
|
103
159
|
}
|
104
160
|
@else {
|
105
|
-
$
|
161
|
+
$min-value: nth($breakpoint, 2);
|
162
|
+
$max-value: nth($breakpoint, 3);
|
106
163
|
}
|
107
164
|
}
|
108
|
-
@else
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
}
|
165
|
+
@else {
|
166
|
+
$feature: nth($breakpoint, 3);
|
167
|
+
// See which is larger.
|
168
|
+
@if nth($breakpoint, 1) > nth($breakpoint, 2) {
|
169
|
+
$min-value: nth($breakpoint, 2);
|
170
|
+
$max-value: nth($breakpoint, 1);
|
171
|
+
}
|
172
|
+
@else {
|
173
|
+
$min-value: nth($breakpoint, 1);
|
174
|
+
$max-value: nth($breakpoint, 2);
|
119
175
|
}
|
120
176
|
}
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
// We have no prefixed query strings, this is mostly to be Future Friendly for now.
|
127
|
-
@if $webkit-query-string {
|
128
|
-
@media #{$webkit-query-string} {
|
129
|
-
@content;
|
177
|
+
|
178
|
+
@if $feature == 'device-pixel-ratio' {
|
179
|
+
$min-value: 96 * $min-value * 1dpi;
|
180
|
+
$max-value: 96 * $max-value * 1dpi;
|
181
|
+
$feature: 'resolution';
|
130
182
|
}
|
131
|
-
|
132
|
-
|
133
|
-
@
|
134
|
-
|
183
|
+
|
184
|
+
// If EM Breakpoints are active, do it!
|
185
|
+
@if $breakpoint-to-ems and type-of($min-value) == 'number' {
|
186
|
+
$min-value: breakpoint-to-base-em($min-value);
|
135
187
|
}
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
188
|
+
@if $breakpoint-to-ems and type-of($max-value) == 'number' {
|
189
|
+
$max-value: breakpoint-to-base-em($max-value);
|
190
|
+
}
|
191
|
+
|
192
|
+
@if breakpoint-min-max($feature) == true {
|
193
|
+
$min-feature: 'min-#{$feature}';
|
194
|
+
$max-feature: 'max-#{$feature}';
|
195
|
+
|
196
|
+
// Min/Max for given
|
197
|
+
$query: breakpoint-generate($media-string, $min-feature, $min-value, $first);
|
198
|
+
$query: join($query, breakpoint-generate($media-string, $max-feature, $max-value));
|
199
|
+
}
|
200
|
+
@else {
|
201
|
+
@warn '#{$feature} cannot have a min/max value!';
|
140
202
|
}
|
141
203
|
}
|
142
|
-
|
143
|
-
|
144
|
-
@content;
|
145
|
-
}
|
146
|
-
}
|
204
|
+
|
205
|
+
@return $query;
|
147
206
|
}
|
148
207
|
|
149
|
-
@function breakpoint-
|
208
|
+
@function breakpoint-generate($media, $feature, $value, $first: false) {
|
150
209
|
$new-string: "";
|
151
|
-
@if $
|
152
|
-
|
210
|
+
@if $media == '' and $first == true {
|
211
|
+
@if $feature != false {
|
212
|
+
$new-string: #{$media}unquote("(#{$feature}: #{$value})");
|
213
|
+
}
|
214
|
+
@else {
|
215
|
+
$new-string: #{$media}unquote("(#{$value})");
|
216
|
+
}
|
153
217
|
}
|
154
218
|
@else {
|
155
|
-
|
219
|
+
@if $feature != false {
|
220
|
+
$new-string: #{$media}unquote("and (#{$feature}: #{$value})");
|
221
|
+
}
|
222
|
+
@else {
|
223
|
+
$new-string: #{$media}unquote("and (#{$value})");
|
224
|
+
}
|
156
225
|
}
|
157
226
|
@return $new-string;
|
158
227
|
}
|
159
228
|
|
229
|
+
@function breakpoint-to-base-em($value) {
|
230
|
+
$unit: unit($value);
|
231
|
+
|
232
|
+
@if $unit == 'px' {
|
233
|
+
@return $value / 16px * 1em;
|
234
|
+
}
|
235
|
+
@else if $unit == '%' {
|
236
|
+
@return $value / 100% * 1em;
|
237
|
+
}
|
238
|
+
@else if $unit == 'em' {
|
239
|
+
@return $value;
|
240
|
+
}
|
241
|
+
@else if $unit == 'pt' {
|
242
|
+
@return $value / 12pt * 1em;
|
243
|
+
}
|
244
|
+
@else {
|
245
|
+
@return $value;
|
246
|
+
// @warn 'Everything is terrible! What have you done?!';
|
247
|
+
}
|
248
|
+
}
|
249
|
+
|
160
250
|
@function breakpoint-min-max($feature) {
|
161
251
|
@if $feature == 'color' or $feature == 'color-index' or $feature == 'aspect-ratio' or $feature == 'device-height' or $feature == 'device-width' or $feature == 'height' or $feature == 'monochrome' or $feature == 'resolution' or $feature == 'width' or $feature == 'device-pixel-ratio' {
|
162
252
|
@return true;
|
@@ -165,3 +255,12 @@ $breakpoint-default-feature: min-width !default;
|
|
165
255
|
@return false;
|
166
256
|
}
|
167
257
|
}
|
258
|
+
|
259
|
+
@function breakpoint-string-value($feature) {
|
260
|
+
@if $feature == 'orientation' or $feature == 'scan' or $feature == 'color' {
|
261
|
+
@return true;
|
262
|
+
}
|
263
|
+
@else {
|
264
|
+
@return false;
|
265
|
+
}
|
266
|
+
}
|
metadata
CHANGED
@@ -3,9 +3,9 @@ name: breakpoint
|
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease: false
|
5
5
|
segments:
|
6
|
+
- 1
|
6
7
|
- 0
|
7
|
-
|
8
|
-
version: "0.3"
|
8
|
+
version: "1.0"
|
9
9
|
platform: ruby
|
10
10
|
authors:
|
11
11
|
- Mason Wendell
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2012-06-
|
17
|
+
date: 2012-06-22 00:00:00 -04:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -47,7 +47,7 @@ files:
|
|
47
47
|
- lib/breakpoint.rb
|
48
48
|
- stylesheets/_breakpoint.scss
|
49
49
|
has_rdoc: true
|
50
|
-
homepage:
|
50
|
+
homepage: https://github.com/canarymason/breakpoint
|
51
51
|
licenses: []
|
52
52
|
|
53
53
|
post_install_message:
|