breakpoint 1.0.2 → 1.1

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.markdown CHANGED
@@ -1,7 +1,12 @@
1
1
  # Changelog
2
2
 
3
+
4
+ ## 1.1 - July 29, 2012
5
+ * Added function `breakpoint-get-context($feature)` to allow users to get the current media query context
6
+
3
7
  ## 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.
8
+ * Refixed our 'device-pixel-ratio' conversions because, frankly, the w3c was wrong.
9
+ * fixed bugs that caused single and triple value single queries to fail. Also bugs with stacking single and triple value queries.
5
10
 
6
11
  ## 1.0.1 - June 27, 2012
7
12
  * fixed logic error that would print multiple instences of a media type
data/README.markdown CHANGED
@@ -9,7 +9,8 @@ Breakpoint makes the following assumptions:
9
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
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
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
- * 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.
12
+
13
+ Breakpoint also allows you to get the context of your media queries from your code, allowing you to write dynamic mixins based on their media query context.
13
14
 
14
15
  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
16
 
@@ -279,6 +280,15 @@ With `$breakpoint-to-ems: true;`
279
280
  }
280
281
  ```
281
282
 
283
+ ## Media Query Context
284
+
285
+ Ever wanted to get the context of a media query from within a mixin or function? Well we have, so we've made that possible! Simply call the `breakpoint-get-context($feature)` function which will either return the contextual value for that feature (`min-width`, `max-width`, etc…) or `false`. You can then do all the awesomeness that you've ever wanted to do with that information.
286
+
287
+ Caviats with Media Query context:
288
+
289
+ * If you have `$breakpoint-to-ems` set to true, you will get returns in base ems. You can run non-em based values through `breakpoint-to-base-em($value)` to convert them to base ems.
290
+ * If you are testing for a prefixed feature (such as `device-pixel-ratio`), you need to test for the prefixed value (`-webkit-device-pixel-ratio`, `min--moz-device-pixel-ratio`, etc…).
291
+
282
292
 
283
293
  ## License
284
294
 
data/lib/breakpoint.rb CHANGED
@@ -3,8 +3,8 @@ require 'compass'
3
3
  Compass::Frameworks.register("breakpoint", :path => "#{File.dirname(__FILE__)}/..")
4
4
 
5
5
  module Breakpoint
6
- VERSION = "1.0.2"
7
- DATE = "2012-07-28"
6
+ VERSION = "1.1"
7
+ DATE = "2012-07-29"
8
8
  end
9
9
 
10
10
  module Sass::Script::Functions
@@ -8,6 +8,12 @@ $breakpoint-to-ems: false !default;
8
8
  $breakpoint-prefixes: 'webkit' 'moz' !default;
9
9
  $breakpoint-prefixed-queries: 'device-pixel-ratio' 'min-device-pixel-ratio' 'max-device-pixel-ratio' !default;
10
10
 
11
+ //////////////////////////////
12
+ // Import Breakpoint Helpers
13
+ //////////////////////////////
14
+ @import 'breakpoint/helpers';
15
+ @import 'breakpoint/context';
16
+
11
17
  //////////////////////////////
12
18
  // Breakpoint Mixin
13
19
  //////////////////////////////
@@ -27,9 +33,12 @@ $breakpoint-prefixed-queries: 'device-pixel-ratio' 'min-device-pixel-ratio' 'max
27
33
  $ms: false !default;
28
34
  $ms-first: true !default;
29
35
 
30
- // Holder for Count;
36
+ // Holder for Count
31
37
  $first: true !default;
32
38
 
39
+ // Reset Context
40
+ @include TXkgcmVzZXQhIEdvIGF3YXkh;
41
+
33
42
  // Initialize Query String
34
43
  @if $media != 'all' {
35
44
  $media-string: "#{$media} ";
@@ -161,6 +170,8 @@ $breakpoint-prefixed-queries: 'device-pixel-ratio' 'min-device-pixel-ratio' 'max
161
170
  }
162
171
  }
163
172
  }
173
+
174
+ @include TXkgcmVzZXQhIEdvIGF3YXkh;
164
175
  }
165
176
 
166
177
  @function breakpoint-switch($breakpoint, $media-string, $first: false, $prefix: false) {
@@ -188,6 +199,8 @@ $breakpoint-prefixed-queries: 'device-pixel-ratio' 'min-device-pixel-ratio' 'max
188
199
  }
189
200
  // Build the Query
190
201
  $query: breakpoint-generate($media-string, $feature, $value, $first);
202
+ // Set Context
203
+ $context: U2V0IHlvdXIgb3duIGRhbW4gY29udGV4dHMh($feature, $value);
191
204
  }
192
205
  @else if $length == 2 {
193
206
  // If both are numbers, we've got a double!
@@ -213,6 +226,9 @@ $breakpoint-prefixed-queries: 'device-pixel-ratio' 'min-device-pixel-ratio' 'max
213
226
  // Min/Max for given
214
227
  $query: breakpoint-generate($media-string, $min-feature, $min-value, $first);
215
228
  $query: join($query, breakpoint-generate($media-string, $max-feature, $max-value));
229
+ // Set Context
230
+ $context: U2V0IHlvdXIgb3duIGRhbW4gY29udGV4dHMh($min-feature, $min-value);
231
+ $context: U2V0IHlvdXIgb3duIGRhbW4gY29udGV4dHMh($max-feature, $max-value);
216
232
  }
217
233
  @else if type-of(nth($breakpoint, 1)) == 'string' and type-of(nth($breakpoint, 2)) == 'string' {
218
234
  @if breakpoint-string-value(nth($breakpoint, 1)) == true {
@@ -231,6 +247,8 @@ $breakpoint-prefixed-queries: 'device-pixel-ratio' 'min-device-pixel-ratio' 'max
231
247
 
232
248
  // Build the Query
233
249
  $query: breakpoint-generate($media-string, $feature, $value, $first);
250
+ // Set Context
251
+ $context: U2V0IHlvdXIgb3duIGRhbW4gY29udGV4dHMh($feature, $value);
234
252
  }
235
253
  @else {
236
254
  // Because we can have either the first or second option be the feature, we switch on it.
@@ -264,6 +282,8 @@ $breakpoint-prefixed-queries: 'device-pixel-ratio' 'min-device-pixel-ratio' 'max
264
282
 
265
283
  // Build the Query
266
284
  $query: breakpoint-generate($media-string, $feature, $value, $first);
285
+ // Set Context
286
+ $context: U2V0IHlvdXIgb3duIGRhbW4gY29udGV4dHMh($feature, $value);
267
287
  }
268
288
  }
269
289
  @else if $length == 3 {
@@ -313,6 +333,9 @@ $breakpoint-prefixed-queries: 'device-pixel-ratio' 'min-device-pixel-ratio' 'max
313
333
  // Min/Max for given
314
334
  $query: breakpoint-generate($media-string, $min-feature, $min-value, $first);
315
335
  $query: join($query, breakpoint-generate($media-string, $max-feature, $max-value));
336
+ // Set Context
337
+ $context: U2V0IHlvdXIgb3duIGRhbW4gY29udGV4dHMh($min-feature, $min-value);
338
+ $context: U2V0IHlvdXIgb3duIGRhbW4gY29udGV4dHMh($max-feature, $max-value);
316
339
  }
317
340
  @else {
318
341
  @warn '#{$feature} cannot have a min/max value!';
@@ -354,72 +377,3 @@ $breakpoint-prefixed-queries: 'device-pixel-ratio' 'min-device-pixel-ratio' 'max
354
377
 
355
378
  @return $new-string;
356
379
  }
357
-
358
- @function breakpoint-to-base-em($value) {
359
- $unit: unit($value);
360
-
361
- @if $unit == 'px' {
362
- @return $value / 16px * 1em;
363
- }
364
- @else if $unit == '%' {
365
- @return $value / 100% * 1em;
366
- }
367
- @else if $unit == 'em' {
368
- @return $value;
369
- }
370
- @else if $unit == 'pt' {
371
- @return $value / 12pt * 1em;
372
- }
373
- @else {
374
- @return $value;
375
- // @warn 'Everything is terrible! What have you done?!';
376
- }
377
- }
378
-
379
- @function breakpoint-min-max($feature) {
380
- @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' {
381
- @return true;
382
- }
383
- @else {
384
- @return false;
385
- }
386
- }
387
-
388
- @function breakpoint-string-value($feature) {
389
- @if $feature == 'orientation' or $feature == 'scan' or $feature == 'color' {
390
- @return true;
391
- }
392
- @else {
393
- @return false;
394
- }
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
- }
@@ -0,0 +1,41 @@
1
+ //////////////////////////////
2
+ // Private Breakpoint Variables
3
+ //////////////////////////////
4
+ $TXkgdmFyaWFibGUhIEdvIGF3YXkh: () !default;
5
+
6
+ //////////////////////////////
7
+ // Breakpoint Get Context
8
+ // $feature: Input feature to get it's current MQ context. Returns false if no context
9
+ //////////////////////////////
10
+ @function breakpoint-get-context($feature) {
11
+ @each $context in $TXkgdmFyaWFibGUhIEdvIGF3YXkh {
12
+ @if $feature == nth($context, 1) {
13
+ @return nth($context, 2);
14
+ }
15
+ }
16
+
17
+ @return false;
18
+ }
19
+
20
+ //////////////////////////////
21
+ // Private function to set context
22
+ //////////////////////////////
23
+ @function U2V0IHlvdXIgb3duIGRhbW4gY29udGV4dHMh($feature, $value) {
24
+ @if $value == 'monochrome' {
25
+ $feature: 'monochrome';
26
+ }
27
+
28
+ $append: $feature;
29
+ $append: join($append, $value, space);
30
+
31
+ $TXkgdmFyaWFibGUhIEdvIGF3YXkh: append($TXkgdmFyaWFibGUhIEdvIGF3YXkh, $append, comma);
32
+
33
+ @return true;
34
+ }
35
+
36
+ //////////////////////////////
37
+ // Private function to reset context
38
+ //////////////////////////////
39
+ @mixin TXkgcmVzZXQhIEdvIGF3YXkh {
40
+ $TXkgdmFyaWFibGUhIEdvIGF3YXkh: ();
41
+ }
@@ -0,0 +1,80 @@
1
+ //////////////////////////////
2
+ // Converts the input value to Base EMs
3
+ //////////////////////////////
4
+ @function breakpoint-to-base-em($value) {
5
+ $unit: unit($value);
6
+
7
+ @if $unit == 'px' {
8
+ @return $value / 16px * 1em;
9
+ }
10
+ @else if $unit == '%' {
11
+ @return $value / 100% * 1em;
12
+ }
13
+ @else if $unit == 'em' {
14
+ @return $value;
15
+ }
16
+ @else if $unit == 'pt' {
17
+ @return $value / 12pt * 1em;
18
+ }
19
+ @else {
20
+ @return $value;
21
+ // @warn 'Everything is terrible! What have you done?!';
22
+ }
23
+ }
24
+
25
+ //////////////////////////////
26
+ // Returns whether the feature can have a min/max pair
27
+ //////////////////////////////
28
+ @function breakpoint-min-max($feature) {
29
+ @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' {
30
+ @return true;
31
+ }
32
+ @else {
33
+ @return false;
34
+ }
35
+ }
36
+
37
+ //////////////////////////////
38
+ // Returns whether the feature can have a string value
39
+ //////////////////////////////
40
+ @function breakpoint-string-value($feature) {
41
+ @if $feature == 'orientation' or $feature == 'scan' or $feature == 'color' {
42
+ @return true;
43
+ }
44
+ @else {
45
+ @return false;
46
+ }
47
+ }
48
+
49
+ //////////////////////////////
50
+ // Experimental Media Queries
51
+ //////////////////////////////
52
+ @function breakpoint-experimental($property, $prefix) {
53
+ @if $property == 'min-device-pixel-ratio' {
54
+ @if $prefix == 'webkit' {
55
+ @return '-#{$prefix}-#{$property}';
56
+ }
57
+ @else if $prefix == 'moz' {
58
+ @return 'min--#{$prefix}-device-pixel-ratio';
59
+ }
60
+ @else {
61
+ @warn '#{$property} is not fully supported in -#{prefix}';
62
+ @return 'ERROR';
63
+ }
64
+ }
65
+ @else if $property == 'max-device-pixel-ratio' {
66
+ @if $prefix == 'webkit' {
67
+ @return '-#{$prefix}-#{$property}';
68
+ }
69
+ @else if $prefix == 'moz' {
70
+ @return 'max--#{$prefix}-device-pixel-ratio';
71
+ }
72
+ @else {
73
+ @warn '#{$property} is not fully supported in -#{prefix}';
74
+ @return 'ERROR';
75
+ }
76
+ }
77
+ @else {
78
+ @return '-#{$prefix}-#{$property}';
79
+ }
80
+ }
metadata CHANGED
@@ -4,9 +4,8 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 1
7
- - 0
8
- - 2
9
- version: 1.0.2
7
+ - 1
8
+ version: "1.1"
10
9
  platform: ruby
11
10
  authors:
12
11
  - Mason Wendell
@@ -15,7 +14,7 @@ autorequire:
15
14
  bindir: bin
16
15
  cert_chain: []
17
16
 
18
- date: 2012-07-28 00:00:00 -04:00
17
+ date: 2012-07-29 00:00:00 -04:00
19
18
  default_executable:
20
19
  dependencies:
21
20
  - !ruby/object:Gem::Dependency
@@ -47,6 +46,8 @@ files:
47
46
  - CHANGELOG.markdown
48
47
  - lib/breakpoint.rb
49
48
  - stylesheets/_breakpoint.scss
49
+ - stylesheets/breakpoint/_context.scss
50
+ - stylesheets/breakpoint/_helpers.scss
50
51
  has_rdoc: true
51
52
  homepage: https://github.com/canarymason/breakpoint
52
53
  licenses: []