breakpoint 1.0.1 → 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,5 +1,11 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.0.2 - July 28, 2012
4
+ * fixed bugs that caused single and triple value single queries to fail. Also bugs with stacking single and triple value tests.
5
+
6
+ ## 1.0.1 - June 27, 2012
7
+ * fixed logic error that would print multiple instences of a media type
8
+
3
9
  ## 1.0 - June 22, 2012
4
10
  * Refactor of the underlying logic to make everything work better and make the world a happy place.
5
11
  * Added default options for Default Feature, Default Media, and Default Feature Pair.
@@ -1,6 +1,6 @@
1
1
  # Breakpoint #
2
2
 
3
- **Media Queries Made Easy**
3
+ **Really Simple Media Queries with Sass**
4
4
 
5
5
  Breakpoint makes writing media queries in Sass super simple. Create a variable using a simplified syntax based on most commonly used media queries, then call it using the `breakpoint` mixin. Breakpoint handles all of the heavy lifting, from writing the media query itself, to handling cross-browser compatibility issues, so you can focus on what's important: making sure your website looks its best.
6
6
 
@@ -11,12 +11,18 @@ Breakpoint makes the following assumptions:
11
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 the semantic awesomeness of 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.
14
+ If you'd prefer the semantic awesomeness of string names to identify your queries as opposed to variables, or want to dynamically generate media queries, check out [Respond-To](https://github.com/snugug/respond-to); a string based naming API for Breakpoint.
15
15
 
16
16
  ## Requirements
17
17
 
18
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!
19
19
 
20
+ Breakpoint also requires Sass 3.2, which is currently in pre-release. Breakpoint should install Sass 3.2 for you when you install it, but in case you are getting errors, open up your terminal and type the following in:
21
+
22
+ `gem install sass --pre`
23
+
24
+ This will install Sass 3.2. If you are compiling with CodeKit, [Chris Coyier has an awesome writeup](http://css-tricks.com/media-queries-sass-3-2-and-codekit/) on how to get CodeKit playing nice with Sass 3.2.
25
+
20
26
  ## Installation
21
27
 
22
28
  `gem install breakpoint`
@@ -3,6 +3,32 @@ require 'compass'
3
3
  Compass::Frameworks.register("breakpoint", :path => "#{File.dirname(__FILE__)}/..")
4
4
 
5
5
  module Breakpoint
6
- VERSION = "1.0.1"
7
- DATE = "2012-06-27"
6
+ VERSION = "1.0.2"
7
+ DATE = "2012-07-28"
8
+ end
9
+
10
+ module Sass::Script::Functions
11
+ def is_breakpoint_list(breakpoint)
12
+ result = false unless breakpoint.class == Sass::Script::List && breakpoint.separator.to_s == 'comma'
13
+ Sass::Script::Bool.new(result)
14
+ end
15
+ def featureExists(feature, list)
16
+ testList = Array.new
17
+ listLength = list.to_a.length - 1
18
+
19
+ for i in 0..listLength
20
+ if list.value[i].class == Sass::Script::List
21
+ subList = list.value[i].to_a.length - 1
22
+
23
+ for j in 0..subList
24
+ testList << list.value[i].value[j]
25
+ end
26
+ else
27
+ testList << list.value[i]
28
+ end
29
+ end
30
+
31
+ result = testList.include?(feature)
32
+ Sass::Script::Bool.new(result)
33
+ end
8
34
  end
@@ -1,10 +1,12 @@
1
1
  //////////////////////////////
2
2
  // Default Variables
3
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;
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;
8
+ $breakpoint-prefixes: 'webkit' 'moz' !default;
9
+ $breakpoint-prefixed-queries: 'device-pixel-ratio' 'min-device-pixel-ratio' 'max-device-pixel-ratio' !default;
8
10
 
9
11
  //////////////////////////////
10
12
  // Breakpoint Mixin
@@ -14,10 +16,20 @@ $breakpoint-to-ems: false !default;
14
16
  $query: false !default;
15
17
  $query-holder: false !default;
16
18
  $media-string: false !default;
17
-
19
+ $do-prefix: false !default;
20
+
21
+ $webkit: false !default;
22
+ $webkit-first: true !default;
23
+ $moz: false !default;
24
+ $moz-first: true !default;
25
+ $o: false !default;
26
+ $o-first: true !default;
27
+ $ms: false !default;
28
+ $ms-first: true !default;
29
+
18
30
  // Holder for Count;
19
31
  $first: true !default;
20
-
32
+
21
33
  // Initialize Query String
22
34
  @if $media != 'all' {
23
35
  $media-string: "#{$media} ";
@@ -25,29 +37,133 @@ $breakpoint-to-ems: false !default;
25
37
  @else {
26
38
  $media-string: "";
27
39
  }
28
-
40
+
29
41
  // 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);
42
+ @if is_breakpoint_list($breakpoint) == false {
43
+ @each $prefix-query in $breakpoint-prefixed-queries {
44
+ @if $do-prefix == false {
45
+ $do-prefix: featureExists($prefix-query, $breakpoint);
46
+ }
47
+ }
48
+ @if $do-prefix {
49
+ @each $prfx in $breakpoint-prefixes {
50
+ @if $prfx == 'webkit' {
51
+ $webkit: breakpoint-switch($breakpoint, $media-string, true, $prfx);
52
+ }
53
+
54
+ @if $prfx == 'moz' {
55
+ $moz: breakpoint-switch($breakpoint, $media-string, true, $prfx);
56
+ }
57
+
58
+ @if $prfx == 'o' {
59
+ $o: breakpoint-switch($breakpoint, $media-string, true, $prfx);
60
+ }
61
+
62
+ @if $prfx == 'ms' {
63
+ $ms: breakpoint-switch($breakpoint, $media-string, true, $prfx);
64
+ }
65
+ }
66
+ }
67
+ @else {
68
+ $query: breakpoint-switch($breakpoint, $media-string, true);
69
+ }
32
70
  }
33
71
  @else {
34
- @each $bkpt in $breakpoint {
35
- @if $first == true {
36
- $query: breakpoint-switch($bkpt, $media-string, true);
37
- $first: false;
72
+ // See if Prefix Query exists
73
+ @each $prefix-query in $breakpoint-prefixed-queries {
74
+ @if $do-prefix == false {
75
+ $do-prefix: featureExists($prefix-query, $breakpoint);
38
76
  }
39
- @else {
40
- $query: join($query, breakpoint-switch($bkpt, $media-string));
77
+ }
78
+
79
+ @if $do-prefix {
80
+ @each $prfx in $breakpoint-prefixes {
81
+ @each $bkpt in $breakpoint {
82
+ @if $prfx == 'webkit' {
83
+ @if $webkit-first {
84
+ $webkit: breakpoint-switch($bkpt, $media-string, true, $prfx);
85
+ $webkit-first: false;
86
+ }
87
+ @else {
88
+ $webkit: join($webkit, breakpoint-switch($bkpt, $media-string, $prefix: $prfx));
89
+ }
90
+ }
91
+
92
+ @if $prfx == 'moz' {
93
+ @if $moz-first {
94
+ $moz: breakpoint-switch($bkpt, $media-string, true, $prfx);
95
+ $moz-first: false;
96
+ }
97
+ @else {
98
+ $moz: join($moz, breakpoint-switch($bkpt, $media-string, $prefix: $prfx));
99
+ }
100
+ }
101
+
102
+ @if $prfx == 'o' {
103
+ @if $o-first {
104
+ $o: breakpoint-switch($bkpt, $media-string, true, $prfx);
105
+ $o-first: false;
106
+ }
107
+ @else {
108
+ $o: join($o, breakpoint-switch($bkpt, $media-string, $prefix: $prfx));
109
+ }
110
+ }
111
+
112
+ @if $prfx == 'ms' {
113
+ @if $ms-first {
114
+ $ms: breakpoint-switch($bkpt, $media-string, true, $prfx);
115
+ $ms-first: false;
116
+ }
117
+ @else {
118
+ $ms: join($ms, breakpoint-switch($bkpt, $media-string, $prefix: $prfx));
119
+ }
120
+ }
121
+ }
122
+ }
123
+ }
124
+ @else {
125
+ @each $bkpt in $breakpoint {
126
+ @if $first == true {
127
+ $query: breakpoint-switch($bkpt, $media-string, true);
128
+ $first: false;
129
+ }
130
+ @else {
131
+ $query: join($query, breakpoint-switch($bkpt, $media-string));
132
+ }
41
133
  }
42
134
  }
43
135
  }
44
-
45
- @media #{$query} {
46
- @content;
136
+
137
+ @if not $webkit and not $moz and not $o and not $ms {
138
+ @media #{$query} {
139
+ @content;
140
+ }
141
+ }
142
+ @else {
143
+ @if $webkit {
144
+ @media #{$webkit} {
145
+ @content;
146
+ }
147
+ }
148
+ @if $moz {
149
+ @media #{$moz} {
150
+ @content;
151
+ }
152
+ }
153
+ @if $o {
154
+ @media #{$o} {
155
+ @content;
156
+ }
157
+ }
158
+ @if $ms {
159
+ @media #{$ms} {
160
+ @content;
161
+ }
162
+ }
47
163
  }
48
164
  }
49
165
 
50
- @function breakpoint-switch($breakpoint, $media-string, $first: false) {
166
+ @function breakpoint-switch($breakpoint, $media-string, $first: false, $prefix: false) {
51
167
  // Feature/Value/Length/Query Placehoders:
52
168
  $feature: false !default;
53
169
  $min-feature: "min-#{$breakpoint-default-pair}" !default;
@@ -57,7 +173,7 @@ $breakpoint-to-ems: false !default;
57
173
  $max-value: false !default;
58
174
  $length: false !default;
59
175
  $query: false !default;
60
-
176
+
61
177
  $length: length($breakpoint);
62
178
  // Check to see if there is only one item.
63
179
  @if $length == 1 {
@@ -65,7 +181,7 @@ $breakpoint-to-ems: false !default;
65
181
  @if type-of($breakpoint) == 'number' {
66
182
  $feature: $breakpoint-default-feature;
67
183
  }
68
-
184
+
69
185
  // If EM Breakpoints are active, do it!
70
186
  @if $breakpoint-to-ems and type-of($value) == 'number' {
71
187
  $value: breakpoint-to-base-em($value);
@@ -85,7 +201,7 @@ $breakpoint-to-ems: false !default;
85
201
  $min-value: nth($breakpoint, 1);
86
202
  $max-value: nth($breakpoint, 2);
87
203
  }
88
-
204
+
89
205
  // If EM Breakpoints are active, do it!
90
206
  @if $breakpoint-to-ems and type-of($min-value) == 'number' {
91
207
  $min-value: breakpoint-to-base-em($min-value);
@@ -93,7 +209,7 @@ $breakpoint-to-ems: false !default;
93
209
  @if $breakpoint-to-ems and type-of($max-value) == 'number' {
94
210
  $max-value: breakpoint-to-base-em($max-value);
95
211
  }
96
-
212
+
97
213
  // Min/Max for given
98
214
  $query: breakpoint-generate($media-string, $min-feature, $min-value, $first);
99
215
  $query: join($query, breakpoint-generate($media-string, $max-feature, $max-value));
@@ -107,12 +223,12 @@ $breakpoint-to-ems: false !default;
107
223
  $feature: nth($breakpoint, 2);
108
224
  $value: nth($breakpoint, 1);
109
225
  }
110
-
226
+
111
227
  // If EM Breakpoints are active, do it!
112
228
  @if $breakpoint-to-ems and type-of($value) == 'number' {
113
229
  $value: breakpoint-to-base-em($value);
114
230
  }
115
-
231
+
116
232
  // Build the Query
117
233
  $query: breakpoint-generate($media-string, $feature, $value, $first);
118
234
  }
@@ -126,25 +242,26 @@ $breakpoint-to-ems: false !default;
126
242
  $feature: nth($breakpoint, 2);
127
243
  $value: nth($breakpoint, 1);
128
244
  }
129
-
245
+
130
246
  @if $feature == 'device-pixel-ratio' or $feature == 'min-device-pixel-ratio' or $feature == 'max-device-pixel-ratio' {
131
- $value: 96 * $value * 1dpi;
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
- }
247
+ $feature: breakpoint-experimental($feature, $prefix);
248
+ //$value: 96 * $value * 1dpi;
249
+ // @if $feature == 'device-pixel-ratio' {
250
+ // $feature: 'resolution';
251
+ // }
252
+ // @else if $feature == 'min-device-pixel-ratio' {
253
+ // $feature: 'min-resolution';
254
+ // }
255
+ // @else if $feature == 'max-device-pixel-ratio' {
256
+ // $feature: 'max-resolution';
257
+ // }
141
258
  }
142
-
259
+
143
260
  // If EM Breakpoints are active, do it!
144
261
  @if $breakpoint-to-ems and type-of($value) == 'number' {
145
262
  $value: breakpoint-to-base-em($value);
146
263
  }
147
-
264
+
148
265
  // Build the Query
149
266
  $query: breakpoint-generate($media-string, $feature, $value, $first);
150
267
  }
@@ -174,13 +291,7 @@ $breakpoint-to-ems: false !default;
174
291
  $max-value: nth($breakpoint, 2);
175
292
  }
176
293
  }
177
-
178
- @if $feature == 'device-pixel-ratio' {
179
- $min-value: 96 * $min-value * 1dpi;
180
- $max-value: 96 * $max-value * 1dpi;
181
- $feature: 'resolution';
182
- }
183
-
294
+
184
295
  // If EM Breakpoints are active, do it!
185
296
  @if $breakpoint-to-ems and type-of($min-value) == 'number' {
186
297
  $min-value: breakpoint-to-base-em($min-value);
@@ -188,10 +299,16 @@ $breakpoint-to-ems: false !default;
188
299
  @if $breakpoint-to-ems and type-of($max-value) == 'number' {
189
300
  $max-value: breakpoint-to-base-em($max-value);
190
301
  }
191
-
302
+
192
303
  @if breakpoint-min-max($feature) == true {
193
- $min-feature: 'min-#{$feature}';
194
- $max-feature: 'max-#{$feature}';
304
+ @if $feature == 'device-pixel-ratio' {
305
+ $min-feature: breakpoint-experimental('min-#{$feature}', $prefix);
306
+ $max-feature: breakpoint-experimental('max-#{$feature}', $prefix);
307
+ }
308
+ @else {
309
+ $min-feature: 'min-#{$feature}';
310
+ $max-feature: 'max-#{$feature}';
311
+ }
195
312
 
196
313
  // Min/Max for given
197
314
  $query: breakpoint-generate($media-string, $min-feature, $min-value, $first);
@@ -201,14 +318,14 @@ $breakpoint-to-ems: false !default;
201
318
  @warn '#{$feature} cannot have a min/max value!';
202
319
  }
203
320
  }
204
-
321
+
205
322
  @return $query;
206
323
  }
207
324
 
208
325
  @function breakpoint-generate($media, $feature, $value, $first: false) {
209
326
  // Media Query string to be returned
210
327
  $new-string: "";
211
-
328
+
212
329
  // If it's the first item, it gets special treatment
213
330
  @if $first == true {
214
331
  // And Statement
@@ -217,7 +334,7 @@ $breakpoint-to-ems: false !default;
217
334
  @if $media == '' {
218
335
  $and: '';
219
336
  }
220
-
337
+
221
338
  @if $feature != false {
222
339
  $new-string: #{$media}unquote("#{$and}(#{$feature}: #{$value})");
223
340
  }
@@ -225,7 +342,7 @@ $breakpoint-to-ems: false !default;
225
342
  $new-string: #{$media}unquote("#{$and}(#{$value})");
226
343
  }
227
344
  }
228
-
345
+
229
346
  @else {
230
347
  @if $feature != false {
231
348
  $new-string: unquote("and (#{$feature}: #{$value})");
@@ -234,13 +351,13 @@ $breakpoint-to-ems: false !default;
234
351
  $new-string: unquote("and (#{$value})");
235
352
  }
236
353
  }
237
-
354
+
238
355
  @return $new-string;
239
356
  }
240
357
 
241
358
  @function breakpoint-to-base-em($value) {
242
359
  $unit: unit($value);
243
-
360
+
244
361
  @if $unit == 'px' {
245
362
  @return $value / 16px * 1em;
246
363
  }
@@ -275,4 +392,34 @@ $breakpoint-to-ems: false !default;
275
392
  @else {
276
393
  @return false;
277
394
  }
278
- }
395
+ }
396
+
397
+ @function breakpoint-experimental($property, $prefix) {
398
+ @if $property == 'min-device-pixel-ratio' {
399
+ @if $prefix == 'webkit' {
400
+ @return '-#{$prefix}-#{$property}';
401
+ }
402
+ @else if $prefix == 'moz' {
403
+ @return 'min--#{$prefix}-device-pixel-ratio';
404
+ }
405
+ @else {
406
+ @warn '#{$property} is not fully supported in -#{prefix}';
407
+ @return 'ERROR';
408
+ }
409
+ }
410
+ @else if $property == 'max-device-pixel-ratio' {
411
+ @if $prefix == 'webkit' {
412
+ @return '-#{$prefix}-#{$property}';
413
+ }
414
+ @else if $prefix == 'moz' {
415
+ @return 'max--#{$prefix}-device-pixel-ratio';
416
+ }
417
+ @else {
418
+ @warn '#{$property} is not fully supported in -#{prefix}';
419
+ @return 'ERROR';
420
+ }
421
+ }
422
+ @else {
423
+ @return '-#{$prefix}-#{$property}';
424
+ }
425
+ }
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 1
7
7
  - 0
8
- - 1
9
- version: 1.0.1
8
+ - 2
9
+ version: 1.0.2
10
10
  platform: ruby
11
11
  authors:
12
12
  - Mason Wendell
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2012-06-27 00:00:00 -04:00
18
+ date: 2012-07-28 00:00:00 -04:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency