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 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 screen queries. 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.
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
@@ -4,7 +4,7 @@ Compass::Frameworks.register("breakpoint", :path => "#{File.dirname(__FILE__)}/.
4
4
 
5
5
  module Breakpoint
6
6
 
7
- VERSION = "0.3"
8
- DATE = "2012-06-21"
7
+ VERSION = "1.0"
8
+ DATE = "2012-06-22"
9
9
 
10
10
  end
@@ -1,80 +1,122 @@
1
- // experimental - depends on Sass 3.2 or higher
2
- // define your own breakpoints
3
- // styles nested in the mixin will pass thru in @content
4
- // resist the urge to settle on common device sizes
5
- // http://marcdrummond.com/responsive-web-design/2011/12/29/default-breakpoints-are-dead
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
- // BREAKPOINT
9
- // breakpoint($breakpoint, $media: 'screen')
10
- //
11
- // // create $breakpoint variables like so
12
- // // assume $breakpoint-default-feature if only a number
13
- // $breakpoint1: 500px
14
- // $breakpoint2: 30em
15
- // // set min-width/max-width if both values are numbers
16
- // $breakpoint3: 500px 700px
17
- // // set min/max of feature if there are two numbers
18
- // $breakpoint4: 400px 700px 'height'
19
- // // if one value is a string, assume a feature/value pair
20
- // $breakpoint5: min-width 700px
21
- // $breakpoint6: max-width 700px
22
- // // for multidimensional lists, assume each item is a feature/value pair
23
- // $breakpoint7: max-width 700px, orientation portrait
24
- // // handle one-sided features (ie. monochrome)
25
- // $breakpoint8: max-width 700px, orientation portrait, monochrome
26
- // $breakpoint9: monochrome
27
- ////////////////////////////
28
-
29
- $breakpoint-default-feature: min-width !default;
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
- @mixin breakpoint($breakpoint, $media: "screen") {
32
- // Feature/Value Placeholders
33
- $feature: false !default;
34
- $value: false !default;
35
- // Prefixed Queries (We have none for now, mostly to be Future Friendly)
36
- $webkit-query-string: false !default;
37
- $moz-query-string: false !default;
38
- $ms-query-string: false !default;
39
- $o-query-string: false !default;
40
- // @debug $breakpoint;
41
- // initialize string
42
- $query-string: "#{$media} ";
43
- @if type-of($breakpoint) == number {
44
- // assume max-width if only a number
45
- $query-string: breakpoint-concatenate($query-string, $breakpoint);
46
- }
47
- @if type-of($breakpoint) == string {
48
- // handle one-sided features (ie. monochrome)
49
- $query-string: breakpoint-concatenate($query-string, $breakpoint, false);
50
- }
51
- @else if type-of($breakpoint) == list {
52
- // set min/max if both values are numbers
53
- @if type-of(nth($breakpoint, 1)) == number and type-of(nth($breakpoint, 2)) == number {
54
- // Optionally pass in 3rd parameter
55
- @if length($breakpoint) == 3 and breakpoint-min-max(nth($breakpoint, 3)) {
56
- // If the feature is device-pixel-ratio, let's convert it to the standard resolution media query!
57
- // - via http://www.w3.org/blog/CSS/2012/06/14/unprefix-webkit-device-pixel-ratio/
58
- @if nth($breakpoint, 3) == 'device-pixel-ratio' {
59
- $value1: 96 * nth($breakpoint, 1) * 1dpi;
60
- $value2: 96 * nth($breakpoint, 2) * 1dpi;;
61
- $feature: 'resolution';
62
- $breakpoint: $value1 $value2 $feature;
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
- @if length($breakpoint) == 3 and breakpoint-min-max(nth($breakpoint, 3)) != true {
70
- @warn '#{nth($breakpoint, 3)} does not accept a min/max value.'
71
- }
72
- $query-string: breakpoint-concatenate($query-string, nth($breakpoint, 1), "min-width");
73
- $query-string: breakpoint-concatenate($query-string, nth($breakpoint, 2), "max-width");
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 or type-of(nth($breakpoint, 2)) == string {
77
- // if one value is a string, assume a feature/value pair
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
- // If the feature is device-pixel-ratio, let's convert it to the standard resolution media query!
88
- // - via http://www.w3.org/blog/CSS/2012/06/14/unprefix-webkit-device-pixel-ratio/
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: 'resolution';
92
- $query-string: breakpoint-concatenate($query-string, $value, $feature);
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
- @else if $feature == 'min-device-pixel-ratio' {
95
- $value: 96 * $value * 1dpi;
96
- $feature: 'min-resolution';
97
- $query-string: breakpoint-concatenate($query-string, $value, $feature);
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
- @else if $feature == 'max-device-pixel-ratio' {
100
- $value: 96 * $value * 1dpi;
101
- $feature: 'max-resolution';
102
- $query-string: breakpoint-concatenate($query-string, $value, $feature);
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
- $query-string: breakpoint-concatenate($query-string, $value, $feature);
161
+ $min-value: nth($breakpoint, 2);
162
+ $max-value: nth($breakpoint, 3);
106
163
  }
107
164
  }
108
- @else if type-of(nth($breakpoint, 1)) == list {
109
- // for multidimensional lists, assume each item is a feature value pair
110
- @each $item in $breakpoint {
111
- @if type-of($item) == list {
112
- // $query-string: #{$query-string}unquote("and (#{nth($item, 1)}: #{nth($item, 2)}) ")
113
- $query-string: breakpoint-concatenate($query-string, nth($item, 2), nth($item, 1));
114
- }
115
- @else {
116
- // handle one-sided features (ie. monochrome)
117
- $query-string: breakpoint-concatenate($query-string, $item, false);
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
- // write out the media query
123
- @media #{$query-string} {
124
- @content;
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
- @if $moz-query-string {
133
- @media #{$moz-query-string} {
134
- @content;
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
- @if $ms-query-string {
138
- @media #{$ms-query-string} {
139
- @content;
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
- @if $o-query-string {
143
- @media #{$o-query-string} {
144
- @content;
145
- }
146
- }
204
+
205
+ @return $query;
147
206
  }
148
207
 
149
- @function breakpoint-concatenate($query-string, $new-value, $feature: $breakpoint-default-feature) {
208
+ @function breakpoint-generate($media, $feature, $value, $first: false) {
150
209
  $new-string: "";
151
- @if $feature != false {
152
- $new-string: #{$query-string}unquote("and (#{$feature}: #{$new-value}) ");
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
- $new-string: #{$query-string}unquote("and (#{$new-value}) ");
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
- - 3
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-21 00:00:00 -04:00
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: http://thecodingdesigner.com
50
+ homepage: https://github.com/canarymason/breakpoint
51
51
  licenses: []
52
52
 
53
53
  post_install_message: