gridle 1.3.36 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,422 @@
1
+ // Flexbox Mixins
2
+ // http://philipwalton.github.io/solved-by-flexbox/
3
+ // https://github.com/philipwalton/solved-by-flexbox
4
+ //
5
+ // Copyright (c) 2013 Brian Franco
6
+ //
7
+ // Permission is hereby granted, free of charge, to any person obtaining a
8
+ // copy of this software and associated documentation files (the
9
+ // "Software"), to deal in the Software without restriction, including
10
+ // without limitation the rights to use, copy, modify, merge, publish,
11
+ // distribute, sublicense, and/or sell copies of the Software, and to
12
+ // permit persons to whom the Software is furnished to do so, subject to
13
+ // the following conditions:
14
+ // The above copyright notice and this permission notice shall be included
15
+ // in all copies or substantial portions of the Software.
16
+ // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
17
+ // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19
+ // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
20
+ // CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21
+ // TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
22
+ // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23
+ //
24
+ // This is a set of mixins for those who want to mess around with flexbox
25
+ // using the native support of current browsers. For full support table
26
+ // check: http://caniuse.com/flexbox
27
+ //
28
+ // Basically this will use:
29
+ //
30
+ // * Fallback, old syntax (IE10, mobile webkit browsers - no wrapping)
31
+ // * Final standards syntax (FF, Safari, Chrome, IE11, Opera)
32
+ //
33
+ // This was inspired by:
34
+ //
35
+ // * http://dev.opera.com/articles/view/advanced-cross-browser-flexbox/
36
+ //
37
+ // With help from:
38
+ //
39
+ // * http://w3.org/tr/css3-flexbox/
40
+ // * http://the-echoplex.net/flexyboxes/
41
+ // * http://msdn.microsoft.com/en-us/library/ie/hh772069(v=vs.85).aspx
42
+ // * http://css-tricks.com/using-flexbox/
43
+ // * http://dev.opera.com/articles/view/advanced-cross-browser-flexbox/
44
+ // * https://developer.mozilla.org/en-us/docs/web/guide/css/flexible_boxes
45
+
46
+ //----------------------------------------------------------------------
47
+
48
+ // Flexbox Containers
49
+ //
50
+ // The 'flex' value causes an element to generate a block-level flex
51
+ // container box.
52
+ //
53
+ // The 'inline-flex' value causes an element to generate a inline-level
54
+ // flex container box.
55
+ //
56
+ // display: flex | inline-flex
57
+ //
58
+ // http://w3.org/tr/css3-flexbox/#flex-containers
59
+ //
60
+ // (Placeholder selectors for each type, for those who rather @extend)
61
+
62
+ @mixin flexbox {
63
+ @if $gridle-vendor-prefix {
64
+ display: -webkit-box;
65
+ display: -webkit-flex;
66
+ display: -moz-flex;
67
+ display: -ms-flexbox;
68
+ }
69
+ display: flex;
70
+ }
71
+
72
+ %flexbox { @include flexbox; }
73
+
74
+ //----------------------------------
75
+
76
+ @mixin inline-flex {
77
+ @if $gridle-vendor-prefix {
78
+ display: -webkit-inline-box;
79
+ display: -webkit-inline-flex;
80
+ display: -moz-inline-flex;
81
+ display: -ms-inline-flexbox;
82
+ }
83
+ display: inline-flex;
84
+ }
85
+
86
+ %inline-flex { @include inline-flex; }
87
+
88
+ //----------------------------------------------------------------------
89
+
90
+ // Flexbox Direction
91
+ //
92
+ // The 'flex-direction' property specifies how flex items are placed in
93
+ // the flex container, by setting the direction of the flex container's
94
+ // main axis. This determines the direction that flex items are laid out in.
95
+ //
96
+ // Values: row | row-reverse | column | column-reverse
97
+ // Default: row
98
+ //
99
+ // http://w3.org/tr/css3-flexbox/#flex-direction-property
100
+
101
+ @mixin flex-direction($value: row) {
102
+ @if $gridle-vendor-prefix {
103
+ @if $value == row-reverse {
104
+ -webkit-box-direction: reverse;
105
+ -webkit-box-orient: horizontal;
106
+ } @else if $value == column {
107
+ -webkit-box-direction: normal;
108
+ -webkit-box-orient: vertical;
109
+ } @else if $value == column-reverse {
110
+ -webkit-box-direction: reverse;
111
+ -webkit-box-orient: vertical;
112
+ } @else {
113
+ -webkit-box-direction: normal;
114
+ -webkit-box-orient: horizontal;
115
+ }
116
+ -webkit-flex-direction: $value;
117
+ -moz-flex-direction: $value;
118
+ -ms-flex-direction: $value;
119
+ }
120
+ flex-direction: $value;
121
+ }
122
+ // Shorter version:
123
+ @mixin flex-dir($args...) { @include flex-direction($args...); }
124
+
125
+ //----------------------------------------------------------------------
126
+
127
+ // Flexbox Wrap
128
+ //
129
+ // The 'flex-wrap' property controls whether the flex container is single-line
130
+ // or multi-line, and the direction of the cross-axis, which determines
131
+ // the direction new lines are stacked in.
132
+ //
133
+ // Values: nowrap | wrap | wrap-reverse
134
+ // Default: nowrap
135
+ //
136
+ // http://w3.org/tr/css3-flexbox/#flex-wrap-property
137
+
138
+ @mixin flex-wrap($value: nowrap) {
139
+ @if $gridle-vendor-prefix {
140
+ // No Webkit Box fallback.
141
+ -webkit-flex-wrap: $value;
142
+ -moz-flex-wrap: $value;
143
+ @if $value == nowrap {
144
+ -ms-flex-wrap: none;
145
+ } @else {
146
+ -ms-flex-wrap: $value;
147
+ }
148
+ }
149
+ flex-wrap: $value;
150
+ }
151
+
152
+ //----------------------------------------------------------------------
153
+
154
+ // Flexbox Flow (shorthand)
155
+ //
156
+ // The 'flex-flow' property is a shorthand for setting the 'flex-direction'
157
+ // and 'flex-wrap' properties, which together define the flex container's
158
+ // main and cross axes.
159
+ //
160
+ // Values: <flex-direction> | <flex-wrap>
161
+ // Default: row nowrap
162
+ //
163
+ // http://w3.org/tr/css3-flexbox/#flex-flow-property
164
+
165
+ @mixin flex-flow($values: (row nowrap)) {
166
+ @if $gridle-vendor-prefix {
167
+ // No Webkit Box fallback.
168
+ -webkit-flex-flow: $values;
169
+ -moz-flex-flow: $values;
170
+ -ms-flex-flow: $values;
171
+ }
172
+ flex-flow: $values;
173
+ }
174
+
175
+ //----------------------------------------------------------------------
176
+
177
+ // Flexbox Order
178
+ //
179
+ // The 'order' property controls the order in which flex items appear within
180
+ // their flex container, by assigning them to ordinal groups.
181
+ //
182
+ // Default: 0
183
+ //
184
+ // http://w3.org/tr/css3-flexbox/#order-property
185
+
186
+ @mixin order($int: 0) {
187
+ @if $gridle-vendor-prefix {
188
+ -webkit-box-ordinal-group: $int + 1;
189
+ -webkit-order: $int;
190
+ -moz-order: $int;
191
+ -ms-flex-order: $int;
192
+ }
193
+ order: $int;
194
+ }
195
+
196
+ //----------------------------------------------------------------------
197
+
198
+ // Flexbox Grow
199
+ //
200
+ // The 'flex-grow' property sets the flex grow factor. Negative numbers
201
+ // are invalid.
202
+ //
203
+ // Default: 0
204
+ //
205
+ // http://w3.org/tr/css3-flexbox/#flex-grow-property
206
+
207
+ @mixin flex-grow($int: 0) {
208
+ @if $gridle-vendor-prefix {
209
+ -webkit-box-flex: $int;
210
+ -webkit-flex-grow: $int;
211
+ -moz-flex-grow: $int;
212
+ -ms-flex-positive: $int;
213
+ }
214
+ flex-grow: $int;
215
+ }
216
+
217
+ //----------------------------------------------------------------------
218
+
219
+ // Flexbox Shrink
220
+ //
221
+ // The 'flex-shrink' property sets the flex shrink factor. Negative numbers
222
+ // are invalid.
223
+ //
224
+ // Default: 1
225
+ //
226
+ // http://w3.org/tr/css3-flexbox/#flex-shrink-property
227
+
228
+ @mixin flex-shrink($int: 1) {
229
+ @if $gridle-vendor-prefix {
230
+ -webkit-flex-shrink: $int;
231
+ -moz-flex-shrink: $int;
232
+ -ms-flex-negative: $int;
233
+ }
234
+ flex-shrink: $int;
235
+ }
236
+
237
+ //----------------------------------------------------------------------
238
+
239
+ // Flexbox Basis
240
+ //
241
+ // The 'flex-basis' property sets the flex basis. Negative lengths are invalid.
242
+ //
243
+ // Values: Like "width"
244
+ // Default: auto
245
+ //
246
+ // http://www.w3.org/TR/css3-flexbox/#flex-basis-property
247
+
248
+ @mixin flex-basis($value: auto) {
249
+ @if $gridle-vendor-prefix {
250
+ -webkit-flex-basis: $value;
251
+ -moz-flex-basis: $value;
252
+ -ms-flex-preferred-size: $value;
253
+ }
254
+ flex-basis: $value;
255
+ }
256
+
257
+ //----------------------------------------------------------------------
258
+
259
+ // Flexbox "Flex" (shorthand)
260
+ //
261
+ // The 'flex' property specifies the components of a flexible length: the
262
+ // flex grow factor and flex shrink factor, and the flex basis. When an
263
+ // element is a flex item, 'flex' is consulted instead of the main size
264
+ // property to determine the main size of the element. If an element is
265
+ // not a flex item, 'flex' has no effect.
266
+ //
267
+ // Values: none | <flex-grow> <flex-shrink> || <flex-basis>
268
+ // Default: See individual properties (1 1 0).
269
+ //
270
+ // http://w3.org/tr/css3-flexbox/#flex-property
271
+
272
+ @mixin flex($fg: 1, $fs: null, $fb: null) {
273
+
274
+ // Set a variable to be used by box-flex properties
275
+ $fg-boxflex: $fg;
276
+
277
+ // Box-Flex only supports a flex-grow value so let's grab the
278
+ // first item in the list and just return that.
279
+ @if type-of($fg) == 'list' {
280
+ $fg-boxflex: nth($fg, 1);
281
+ }
282
+
283
+ @if $gridle-vendor-prefix {
284
+ -webkit-box-flex: $fg-boxflex;
285
+ -webkit-flex: $fg $fs $fb;
286
+ -moz-box-flex: $fg-boxflex;
287
+ -moz-flex: $fg $fs $fb;
288
+ -ms-flex: $fg $fs $fb;
289
+ }
290
+ flex: $fg $fs $fb;
291
+ }
292
+
293
+ //----------------------------------------------------------------------
294
+
295
+ // Flexbox Justify Content
296
+ //
297
+ // The 'justify-content' property aligns flex items along the main axis
298
+ // of the current line of the flex container. This is done after any flexible
299
+ // lengths and any auto margins have been resolved. Typically it helps distribute
300
+ // extra free space leftover when either all the flex items on a line are
301
+ // inflexible, or are flexible but have reached their maximum size. It also
302
+ // exerts some control over the alignment of items when they overflow the line.
303
+ //
304
+ // Note: 'space-*' values not supported in older syntaxes.
305
+ //
306
+ // Values: flex-start | flex-end | center | space-between | space-around
307
+ // Default: flex-start
308
+ //
309
+ // http://w3.org/tr/css3-flexbox/#justify-content-property
310
+
311
+ @mixin justify-content($value: flex-start) {
312
+ @if $gridle-vendor-prefix {
313
+ @if $value == flex-start {
314
+ -webkit-box-pack: start;
315
+ -ms-flex-pack: start;
316
+ } @else if $value == flex-end {
317
+ -webkit-box-pack: end;
318
+ -ms-flex-pack: end;
319
+ } @else if $value == space-between {
320
+ -webkit-box-pack: justify;
321
+ -ms-flex-pack: justify;
322
+ } @else if $value == space-around {
323
+ -ms-flex-pack: distribute;
324
+ } @else {
325
+ -webkit-box-pack: $value;
326
+ -ms-flex-pack: $value;
327
+ }
328
+ -webkit-justify-content: $value;
329
+ -moz-justify-content: $value;
330
+ }
331
+ justify-content: $value;
332
+ }
333
+ // Shorter version:
334
+ @mixin flex-just($args...) { @include justify-content($args...); }
335
+
336
+ //----------------------------------------------------------------------
337
+
338
+ // Flexbox Align Items
339
+ //
340
+ // Flex items can be aligned in the cross axis of the current line of the
341
+ // flex container, similar to 'justify-content' but in the perpendicular
342
+ // direction. 'align-items' sets the default alignment for all of the flex
343
+ // container's items, including anonymous flex items. 'align-self' allows
344
+ // this default alignment to be overridden for individual flex items. (For
345
+ // anonymous flex items, 'align-self' always matches the value of 'align-items'
346
+ // on their associated flex container.)
347
+ //
348
+ // Values: flex-start | flex-end | center | baseline | stretch
349
+ // Default: stretch
350
+ //
351
+ // http://w3.org/tr/css3-flexbox/#align-items-property
352
+
353
+ @mixin align-items($value: stretch) {
354
+ @if $gridle-vendor-prefix {
355
+ @if $value == flex-start {
356
+ -webkit-box-align: start;
357
+ -ms-flex-align: start;
358
+ } @else if $value == flex-end {
359
+ -webkit-box-align: end;
360
+ -ms-flex-align: end;
361
+ } @else {
362
+ -webkit-box-align: $value;
363
+ -ms-flex-align: $value;
364
+ }
365
+ -webkit-align-items: $value;
366
+ -moz-align-items: $value;
367
+ }
368
+ align-items: $value;
369
+ }
370
+
371
+ //----------------------------------
372
+
373
+ // Flexbox Align Self
374
+ //
375
+ // Values: auto | flex-start | flex-end | center | baseline | stretch
376
+ // Default: auto
377
+
378
+ @mixin align-self($value: auto) {
379
+ @if $gridle-vendor-prefix {
380
+ // No Webkit Box Fallback.
381
+ -webkit-align-self: $value;
382
+ -moz-align-self: $value;
383
+ @if $value == flex-start {
384
+ -ms-flex-item-align: start;
385
+ } @else if $value == flex-end {
386
+ -ms-flex-item-align: end;
387
+ } @else {
388
+ -ms-flex-item-align: $value;
389
+ }
390
+ }
391
+ align-self: $value;
392
+ }
393
+
394
+ //----------------------------------------------------------------------
395
+
396
+ // Flexbox Align Content
397
+ //
398
+ // The 'align-content' property aligns a flex container's lines within the
399
+ // flex container when there is extra space in the cross-axis, similar to
400
+ // how 'justify-content' aligns individual items within the main-axis. Note,
401
+ // this property has no effect when the flexbox has only a single line.
402
+ //
403
+ // Values: flex-start | flex-end | center | space-between | space-around | stretch
404
+ // Default: stretch
405
+ //
406
+ // http://w3.org/tr/css3-flexbox/#align-content-property
407
+
408
+ @mixin align-content($value: stretch) {
409
+ @if $gridle-vendor-prefix {
410
+ // No Webkit Box Fallback.
411
+ -webkit-align-content: $value;
412
+ -moz-align-content: $value;
413
+ @if $value == flex-start {
414
+ -ms-flex-line-pack: start;
415
+ } @else if $value == flex-end {
416
+ -ms-flex-line-pack: end;
417
+ } @else {
418
+ -ms-flex-line-pack: $value;
419
+ }
420
+ }
421
+ align-content: $value;
422
+ }
@@ -4,15 +4,15 @@
4
4
  // |------------------------------------------------------
5
5
  // |------------------------------------------------------
6
6
 
7
- /**
8
- * Str replace
9
- *
10
- * @param {string} $string String that you want to replace
11
- * @param {string} $substr String that is to be replaced by `$newsubstr`
12
- * @param {string} $newsubstr String that replaces `$substr`
13
- * @param {number*} $all Flag for replaceing all (1+) or not (0)
14
- * @return {string}
15
- */
7
+ //
8
+ // Str replace
9
+ //
10
+ // @param {string} $string String that you want to replace
11
+ // @param {string} $substr String that is to be replaced by `$newsubstr`
12
+ // @param {string} $newsubstr String that replaces `$substr`
13
+ // @param {number*} $all Flag for replaceing all (1+) or not (0)
14
+ // @return {string}
15
+ //
16
16
  @function str-replace($string, $substr, $newsubstr, $all: 0) {
17
17
  $position-found: str-index($string, $substr);
18
18
  $processed: ();
@@ -40,44 +40,146 @@
40
40
  @return $string;
41
41
  }
42
42
 
43
- /**
44
- * Map set
45
- *
46
- * @param Map $map The map to use
47
- * @param String $key The key to update
48
- * @param Mixed $value The new value
49
- * @return Map The new map
50
- */
43
+ //
44
+ // Map set
45
+ //
46
+ // @param Map $map The map to use
47
+ // @param String $key The key to update
48
+ // @param Mixed $value The new value
49
+ // @return Map The new map
50
+ //
51
51
  @function map-set($map, $key, $value) {
52
52
  $new: ($key: $value);
53
53
  @return map-merge($map, $new);
54
54
  }
55
55
 
56
+ //
57
+ // Remove item from list
58
+ //
59
+ @function remove-nth($list, $index) {
60
+ $result: null;
61
+
62
+ @if type-of($index) != number {
63
+ @warn "$index: #{quote($index)} is not a number for `remove-nth`.";
64
+ }
65
+
66
+ @else if $index == 0 {
67
+ @warn "List index 0 must be a non-zero integer for `remove-nth`.";
68
+ }
69
+
70
+ @else if abs($index) > length($list) {
71
+ @warn "List index is #{$index} but list is only #{length($list)} item long for `remove-nth`.";
72
+ }
73
+
74
+ @else {
75
+ $result: ();
76
+ $index: if($index < 0, length($list) + $index + 1, $index);
77
+
78
+ @for $i from 1 through length($list) {
79
+ @if $i != $index {
80
+ $result: append($result, nth($list, $i));
81
+ }
82
+ }
83
+ }
84
+
85
+ @return $result;
86
+ }
87
+
88
+ //
89
+ // List shift
90
+ //
91
+ // @param List $list The list to use
92
+ // @return List The processed list
93
+ //
94
+ @function list-shift($list) {
95
+ @return remove-nth($list,1);
96
+ }
97
+
98
+ //
99
+ // List pop
100
+ //
101
+ // @param List $list The list to use
102
+ // @return List The processed list
103
+ //
104
+ @function list-pop($list) {
105
+ @return remove-nth($list,length($list));
106
+ }
107
+
108
+ //
109
+ // In map
110
+ // Determine if something is in the provided map
111
+ //
112
+ // @param Map $map The map to use
113
+ // @param Mixed $needle What to search
114
+ // @return Boolean True|false
115
+ //
116
+ @function in-map($map, $needle) {
117
+ @each $v in $map {
118
+ @if $v == $needle {
119
+ @return true;
120
+ }
121
+ }
122
+ @return false;
123
+ }
124
+
125
+
126
+ //
127
+ // Get states count
128
+ //
129
+ // @return int The number of states defined
130
+ //
131
+ @function gridle_states_count() {
132
+ @return length($_gridle_states);
133
+ }
134
+
135
+
136
+ //
137
+ // Get the current state
138
+ //
139
+ @function gridle_current_state() {
140
+ @return $_gridle_current_state;
141
+ }
142
+
143
+
144
+ //
145
+ // Get the current state name
146
+ //
147
+ @function gridle_current_state_name() {
148
+ @return $_gridle_current_stateName;
149
+ }
56
150
 
57
- /**
58
- * Get the column width in percent for the global or a specific context
59
- *
60
- * @param int $columns The number of columns to calculate
61
- * @param int $context : $gridle-columns-count The context to use
62
- * @return percentage The width in percent
63
- */
64
- @function gridle_get_column_width(
151
+
152
+ //
153
+ // Get the column width in percent for the global or a specific context
154
+ //
155
+ // @param int $columns The number of columns to calculate
156
+ // @param int $context : $gridle-columns-count The context to use
157
+ // @return percentage The width in percent
158
+ //
159
+ @function gridle_column_width(
65
160
  $columns : 1,
66
161
  $stateMap-or-stateName : null
67
162
  ) {
163
+ $context : gridle_get_state_var(context, $stateMap-or-stateName);
68
164
  @return percentage(1 / $context * $columns);
69
165
  }
70
166
 
71
167
 
72
- /**
73
- * Get a state map
74
- *
75
- * @param string $name The name of the state to get
76
- * @return map A state map object
77
- */
78
- @function _gridle_get_state(
79
- $stateMap-or-stateName
168
+ //
169
+ // Get a state map
170
+ //
171
+ // @param string $name The name of the state to get
172
+ // @return map A state map object
173
+ //
174
+ @function gridle_get_state(
175
+ $stateMap-or-stateName : current
80
176
  ) {
177
+
178
+ // check if need to return the current state
179
+ @if $stateMap-or-stateName == current {
180
+ @return gridle_current_state();
181
+ }
182
+
81
183
  // check if has a state named like this
82
184
  @if (type-of($stateMap-or-stateName) == string
83
185
  and map-has-key($_gridle_states, unquote("#{$stateMap-or-stateName}")))
@@ -85,11 +187,25 @@
85
187
  @return map-get($_gridle_states, unquote("#{$stateMap-or-stateName}"));
86
188
  }
87
189
 
190
+ // check if it's a registered state as map passed
191
+ @if type-of($stateMap-or-stateName) == map
192
+ and map-get($stateMap-or-stateName, name) {
193
+ $name : map-get($stateMap-or-stateName, name);
194
+ @if gridle_has_state($name) {
195
+ @return $stateMap-or-stateName;
196
+ }
197
+ }
198
+
88
199
  // a map is passed, so it's a state himself
89
200
  @if $stateMap-or-stateName
90
201
  and type-of($stateMap-or-stateName) == map
91
202
  {
92
- @return map-merge($_gridle-settings, $stateMap-or-stateName);
203
+ // create a new state by merging given one with defaul one
204
+ $state : map-merge($_gridle-settings, $stateMap-or-stateName);
205
+ // set the name with random name
206
+ $state : map-set($state, name, unique-id());
207
+ // return the custom state
208
+ @return $state;
93
209
  }
94
210
 
95
211
  // return the default one if exist
@@ -103,13 +219,13 @@
103
219
  }
104
220
 
105
221
 
106
- /**
107
- * Check if a state exist :
108
- *
109
- * @param string $name The name of the state to check
110
- * @return Boolean true is exist
111
- */
112
- @function _gridle_has_state(
222
+ //
223
+ // Check if a state exist :
224
+ //
225
+ // @param string $name The name of the state to check
226
+ // @return Boolean true is exist
227
+ //
228
+ @function gridle_has_state(
113
229
  $stateName
114
230
  ) {
115
231
  @if map-has-key($_gridle_states, unquote("#{$stateName}")) {
@@ -120,54 +236,25 @@
120
236
  }
121
237
 
122
238
 
123
- /**
124
- * Get the media queries variables :
125
- *
126
- * @param int $index The media query indes
127
- * @param String $var The media query variable name
128
- * @return String|int The variable value
129
- */
130
- @function _gridle_get_state_var(
131
- $stateName,
132
- $var : "name"
133
- ) {
134
-
135
- // get the state :
136
- $state : _gridle_get_state($stateName);
137
-
138
- // check ig state and if has the variable :
139
- @if $state
140
- and map-has-key($state,unquote("#{$var}"))
141
- {
142
- @return map-get($state,unquote("#{$var}"));
143
- }
144
-
145
- // nothing getted :
146
- @return null;
147
- }
148
-
149
-
150
- /**
151
- * Get a variable
152
- *
153
- * @param String $varName The variable name
154
- * @param String $stateMap-or-stateName The state name or a map state value
155
- * @return Mixed The finded value
156
- */
157
- @function _gridle_get_var_value(
239
+ //
240
+ // Get a variable
241
+ //
242
+ // @param String $varName The variable name
243
+ // @param String $stateMap-or-stateName The state name or a map state value
244
+ // @return Mixed The finded value
245
+ //
246
+ @function gridle_get_state_var(
158
247
  $varName,
159
248
  $stateMap-or-stateName : null
160
249
  ) {
161
250
  // if is a state :
162
251
  $state : null;
163
252
 
164
- // get the state (if no state find, return the default one) :
165
- $state : _gridle_get_state($stateMap-or-stateName);
253
+ // get the state (if no state find, return the current one) :
254
+ $state : gridle_get_state($stateMap-or-stateName);
166
255
 
167
- // extend default state with given state :
168
- $props : map-merge($_gridle-settings, $state);
169
-
170
- @if map-has-key($props, unquote("#{$varName}")) {
256
+ // check if has key
257
+ @if map-has-key($state, unquote("#{$varName}")) {
171
258
  @return map-get($state, unquote("#{$varName}"));
172
259
  }
173
260
 
@@ -176,20 +263,20 @@
176
263
  }
177
264
 
178
265
 
179
- /**
180
- * Set a variable in a state
181
- * @param Mixed $stateName-or-stateIndex The state name of state index
182
- * @param String $var Variable name to assign
183
- * @param Mixed $newValue The new value to assign
184
- * @return List The states list (full)
185
- */
186
- @function _gridle_set_state_var(
187
- $stateName,
266
+ //
267
+ // Set a variable in a state
268
+ // @param Mixed $stateName-or-stateIndex The state name of state index
269
+ // @param String $var Variable name to assign
270
+ // @param Mixed $newValue The new value to assign
271
+ // @return List The states list (full)
272
+ //
273
+ @function gridle_set_state_var(
188
274
  $var,
189
- $newValue
275
+ $newValue,
276
+ $stateName : default
190
277
  ) {
191
278
  // get the state :
192
- $state : _gridle_get_state($stateName);
279
+ $state : gridle_get_state($stateName);
193
280
 
194
281
  // check ig state and if has the variable :
195
282
  @if $state
@@ -210,14 +297,72 @@
210
297
  }
211
298
 
212
299
 
213
- /**
214
- * Generate a column
215
- *
216
- * @param String $name The column name (often count)
217
- * @param int $columns The column count that the column will take
218
- * @param int $context The context on witch the with will be calculed
219
- * @param Boolean $generateClasses Set if the column has to be generated in css
220
- */
300
+ //
301
+ // get the registered gridle states
302
+ //
303
+ @function gridle_get_states() {
304
+ @return $_gridle_states;
305
+ }
306
+
307
+
308
+ //
309
+ // Get the states names
310
+ //
311
+ @function gridle_get_states_names() {
312
+ $list : ();
313
+ @each $stateName, $state in $_gridle_states {
314
+ $list : append($list, $stateName);
315
+ }
316
+ @return $list;
317
+ }
318
+
319
+
320
+ //
321
+ // Get the apply css for map for a certain class and state
322
+ //
323
+ @function gridle_get_apply_css_for_map(
324
+ $for,
325
+ $stateName : default
326
+ ) {
327
+ // check if has some extend for this state
328
+ $map : map-get($_gridle_apply_css_for, $stateName);
329
+ @if $map == null { @return null; }
330
+
331
+ // check if has some extend for the requested for
332
+ $extend : map-get($map, $for);
333
+
334
+ // return the resulting extend map
335
+ @return $extend;
336
+ }
337
+
338
+
339
+ //
340
+ // Get the extend map for a certain class and state
341
+ //
342
+ @function gridle_get_extend_class_map(
343
+ $for,
344
+ $stateName : default
345
+ ) {
346
+ // check if has some extend for this state
347
+ $map : map-get($_gridle_extend_base_classes, $stateName);
348
+ @if $map == null { @return null; }
349
+
350
+ // check if has some extend for the requested for
351
+ $extend : map-get($map, $for);
352
+
353
+ // return the resulting extend map
354
+ @return $extend;
355
+ }
356
+
357
+
358
+ //
359
+ // Generate a column
360
+ //
361
+ // @param String $name The column name (often count)
362
+ // @param int $columns The column count that the column will take
363
+ // @param int $context The context on witch the with will be calculed
364
+ // @param Boolean $generateClasses Set if the column has to be generated in css
365
+ //
221
366
  @function _gridle_create_column(
222
367
  $name,
223
368
  $columns,
@@ -233,79 +378,262 @@
233
378
  }
234
379
 
235
380
 
236
- /**
237
- * Generate classname
238
- *
239
- * @param List $parrern The pattern to use to generate classname
240
- * @param String $state The state
241
- * @param int $count The column count
242
- */
381
+ // get columns names in a list
382
+ @function gridle_get_columns(
383
+ $state : default
384
+ ) {
385
+ // get variables
386
+ $context : gridle_get_state_var(context, $state);
387
+ $name-multiplicator : gridle_get_state_var(name-multiplicator, $state);
388
+
389
+ // get specials columns
390
+ $columnsMap : map-merge((), $_gridle_columns);
391
+
392
+ // loop through context
393
+ @for $i from 0 through $context {
394
+
395
+ // name
396
+ $columnName : "#{$i*$name-multiplicator}";
397
+ $columnWidth : $i * $name-multiplicator;
398
+
399
+ // // create a column
400
+ $col : _gridle_create_column($columnName, $columnWidth, $context, $name-multiplicator);
401
+
402
+ // // add column in columns map
403
+ $columnsMap : map-set($columnsMap, $columnName, $col);
404
+ }
405
+
406
+ // return columns
407
+ @return $columnsMap;
408
+ }
409
+
410
+
411
+ //
412
+ // Get the padding value
413
+ //
414
+ @function _gridle_forge_gutters_map(
415
+ $side-or-size,
416
+ $state : current
417
+ ) {
418
+ $map : ();
419
+ // check if is number passed
420
+ @if type-of($side-or-size) == map {
421
+ @each $side in (top right bottom left) {
422
+ @if map-get($side-or-size, $side) {
423
+ $map : map-set($map, $side, map-get($side-or-size, $side));
424
+ } @else {
425
+ $map : map-set($map, $side, 0);
426
+ }
427
+ }
428
+ } @else if type-of($side-or-size) == number {
429
+ $map : (
430
+ top : 0,
431
+ right : $side-or-size * .5,
432
+ bottom : 0,
433
+ left : $side-or-size * .5
434
+ );
435
+ } @else if type-of($side-or-size) == list or type-of($side-or-size) == string {
436
+
437
+ // check if is a full number list
438
+ $list-number : true;
439
+ @each $s in $side-or-size {
440
+ @if type-of($s) != number {
441
+ $list-number : false;
442
+ }
443
+ }
444
+
445
+ @if $list-number {
446
+
447
+ @if length($side-or-size) == 2 {
448
+ $val1 : nth($side-or-size,1) * .5;
449
+ $val2 : nth($side-or-size,2) * .5;
450
+ $map : (
451
+ top : $val1,
452
+ right : $val2,
453
+ bottom : $val1,
454
+ left : $val2
455
+ )
456
+ } @else if length($side-or-size) == 4 {
457
+ $map : (
458
+ top : nth($side-or-size,1),
459
+ right : nth($side-or-size,2),
460
+ bottom : nth($side-or-size,3),
461
+ left : nth($side-or-size,4)
462
+ )
463
+ }
464
+
465
+ } @else {
466
+ // forge the map with registered values
467
+ @each $side in (top right bottom left) {
468
+ @if index($side-or-size, $side) {
469
+ $map : map-set($map, $side, gridle_get_state_var("gutter-#{$side}", $state));
470
+ } @else {
471
+ $map : map-set($map, $side, 0);
472
+ }
473
+ }
474
+ // @debug("get gutters from registered #{inspect($map)}");
475
+ }
476
+ } @else {
477
+ // unable to generate a gutter map
478
+ @return false;
479
+ }
480
+
481
+ // return the padding map
482
+ @return $map;
483
+ }
484
+
485
+
486
+ //
487
+ // Get the attribute selector
488
+ //
489
+ @function gridle_selector(
490
+ $for,
491
+ $states : null,
492
+ $values : null
493
+ ) {
494
+ $sel : ();
495
+
496
+ @if length($for) > 1 {
497
+ @each $f in $for {
498
+ $sel : append($sel, gridle_selector($f, $states, $values), comma);
499
+ }
500
+ } @else {
501
+
502
+ // get all states if not specified
503
+ @if $states == null {
504
+ $states : gridle_get_states_names();
505
+ }
506
+
507
+ // get the pattern
508
+ $pattern : map-get($_gridle-packages, $for);
509
+ $pattern : map-get($pattern, classname);
510
+
511
+ @each $stateName in $states {
512
+ @if $values != null {
513
+ $sel : append($sel, _gridle_classname($for, $stateName, $values), comma);
514
+ } @else if index($pattern, '%column') {
515
+ @each $columnName, $column in gridle_get_columns() {
516
+ $sel : append($sel, _gridle_classname($for, $stateName, $columnName), comma);
517
+ }
518
+ } @else if index($pattern, '%column-count') {
519
+ @for $i from 0 through length(gridle_get_columns()) {
520
+ $sel : append($sel, _gridle_classname($for, $stateName, $i), comma);
521
+ }
522
+ @if $for == flex-order {
523
+ $sel : append($sel, _gridle_classname($for, $stateName, first), comma);
524
+ $sel : append($sel, _gridle_classname($for, $stateName, last), comma);
525
+ }
526
+ } @else if index($pattern, '%align') {
527
+ @each $a in map-get($_gridle-names-tokens, align) {
528
+ $sel : append($sel, _gridle_classname($for, $stateName, $a), comma);
529
+ }
530
+ } @else if index($pattern, '%count') and $for == clear-each {
531
+ @each $idx, $clearEach in $_gridle_clear_classes {
532
+ $count : map-get($clearEach, clearEach);
533
+ $sel : append($sel, _gridle_classname($for, $stateName, $count), comma);
534
+ }
535
+ } @else if index($pattern, '%side') {
536
+ @each $side in map-get($_gridle-names-tokens, side) {
537
+ $sel : append($sel, _gridle_classname($for, $stateName, $side), comma);
538
+ }
539
+ } @else if index($pattern, '%float') {
540
+ @each $float in map-get($_gridle-names-tokens, float) {
541
+ $sel : append($sel, _gridle_classname($for, $stateName, $float), comma);
542
+ }
543
+ } @else if index($pattern, '%reverse') {
544
+ @each $reverse in map-get($_gridle-names-tokens, reverse) {
545
+ $sel : append($sel, _gridle_classname($for, $stateName, $reverse), comma);
546
+ }
547
+ } @else {
548
+ $sel : append($sel, _gridle_classname($for, $stateName), comma);
549
+ }
550
+ }
551
+ }
552
+ @return $sel;
553
+ }
554
+
555
+
556
+ //
557
+ // Generate classname
558
+ //
559
+ // @param List $parrern The pattern to use to generate classname
560
+ // @param String $state The state
561
+ // @param int $count The column count
562
+ //
243
563
  @function _gridle_classname(
244
- $pattern,
564
+ $for,
245
565
  $state : null,
246
- $count : null
566
+ $value : null
247
567
  ) {
248
568
 
249
- // init selector :
250
- $sel : ".";
569
+ // get the pattern
570
+ $pattern : $for;
571
+ @if type-of($for) == string {
572
+ $pattern : map-get($_gridle-packages, $for);
573
+ $pattern : map-get($pattern, classname);
574
+ }
251
575
 
252
576
  // delete default :
253
577
  @if unquote("#{$state}") == default {
254
578
  $state : null;
255
579
  }
256
-
257
- // add class prefix :
258
- @if $gridle-class-prefix and $gridle-class-prefix != '' {
259
- $sel : "#{$sel}#{$gridle-class-prefix}";
260
- @if $gridle-class-separator {
261
- $sel : "#{$sel}#{$gridle-class-separator}";
262
- }
263
- }
264
580
 
265
581
  // construct class name :
266
- $i : 1;
267
- @each $var in $pattern {
268
-
269
- // replace tokens :
270
- @if $var == '%state' and $state {
271
- $sel : "#{$sel}#{$state}";
272
- }
273
- @if $var == '%count' and $count {
274
- $sel : "#{$sel}#{$count}";
275
- }
276
- @if $var != '%state' and $var != '%count' and $var != '%-' and $var != '-' and $var != '--' and $var != '_' and $var != '__' and $var != '%prefix' {
277
- $sel : "#{$sel}#{$var}";
582
+ $removeSeparator : false;
583
+ @for $i from length($pattern) through 1 {
584
+ $var : nth($pattern, $i);
585
+
586
+ @if $var == '@' {
587
+ $pattern : set-nth($pattern, $i, '\\@');
278
588
  }
279
589
 
280
- // handle separators :
281
- @if ($var == '%-' or $var == '-' or $var == '--' or $var == '_' or $var == '__') and $i < length($pattern) {
282
- $index : $i + 1;
283
- $value : nth($pattern, $index);
284
- @if $value != '%state' and $value != '%count' and $value != '%-' and $value != '-' and $value != '--' and $value != '_' and $value != '__' and $value != '%prefix' {
285
- @if $var == '%-' {
286
- $sel : "#{$sel}#{$gridle-class-separator}";
287
- } @else {
288
- $sel : "#{$sel}#{$var}";
289
- }
590
+ @if index($_gridle_names-separators, $var) {
591
+ // check if need to remove separator
592
+ @if $removeSeparator {
593
+ $pattern : set-nth($pattern, $i, null);
290
594
  }
291
- @if $value == '%state' and $state {
292
- @if $var == '%-' {
293
- $sel : "#{$sel}#{$gridle-class-separator}";
294
- } @else {
295
- $sel : "#{$sel}#{$var}";
296
- }
595
+ $removeSeparator : false;
596
+ } @else if $var == "%state" {
597
+ @if $state == null {
598
+ $pattern : set-nth($pattern, $i, null);
599
+ $removeSeparator : true;
600
+ } @else {
601
+ $pattern : set-nth($pattern, $i, $state);
297
602
  }
298
- @if $value == '%count' and $count {
299
- @if $var == '%-' {
300
- $sel : "#{$sel}#{$gridle-class-separator}";
301
- } @else {
302
- $sel : "#{$sel}#{$var}";
603
+ } @else if $var and str-index($var, '%') == 1 {
604
+ $token : str-slice($var, 2);
605
+ // check that the value is part of the token
606
+ $tokens : map-get($_gridle-names-tokens, $token);
607
+ @if $tokens {
608
+ $pattern : set-nth($pattern, $i, $value);
609
+ @if $value == null {
610
+ $removeSeparator : true;
303
611
  }
304
612
  }
305
613
  }
614
+ }
306
615
 
307
- // update i :
308
- $i : $i + 1;
616
+ // clean selector
617
+ $list: ();
618
+ @each $var in $pattern {
619
+ @if $var {
620
+ $list: append($list, $var);
621
+ }
622
+ }
623
+ $pattern : $list;
624
+
625
+ // build selector
626
+ $sel : "";
627
+ $prefix : gridle_get_state_var(classes-prefix, $state);
628
+ @each $part in $pattern {
629
+ @if $part {
630
+ $sel : "#{$sel}#{$part}";
631
+ }
632
+ }
633
+ @if $prefix and str-slice($sel,1,str_length($prefix)) != $prefix {
634
+ $sel : ".#{$prefix}#{$sel}";
635
+ } @else {
636
+ $sel : ".#{$sel}";
309
637
  }
310
638
 
311
639
  // return generated class :
@@ -313,21 +641,103 @@
313
641
  }
314
642
 
315
643
 
316
- /**
317
- * Get the media query for a particular state, or with, etc...
318
- *
319
- * @param Mixed $state-or-min-width The state name of the min with
320
- * @param Mixed $max-width The max width if first param is a min width
321
- * @return String The media query string without the @media
322
- */
323
- @function _gridle_get_media_query(
324
- $state-or-settings
644
+ //
645
+ // Get the current driver
646
+ //
647
+ @function gridle_get_driver() {
648
+ @return $_gridle-driver;
649
+ }
650
+
651
+
652
+ //
653
+ // Is driver
654
+ //
655
+ @function gridle_is_driver($driver) {
656
+ @each $d in $driver {
657
+ @if $d == gridle_get_driver() {
658
+ @return true;
659
+ }
660
+ }
661
+ @return false;
662
+ }
663
+
664
+
665
+ //
666
+ // Check if we need to generate the class or not
667
+ //
668
+ // @param List $for Name of the class map
669
+ // @param List $what The map that set which class map to include and exclude
670
+ // @return Boolean true if need to generate, false if not
671
+ //
672
+ @function _gridle_need_to_generate(
673
+ $package,
674
+ $what
675
+ ) {
676
+ // check that the wanted package exist in system
677
+ @if map-get($_gridle-packages, $package) {
678
+ $package : map-get($_gridle-packages, $package);
679
+ $package : map-get($package, package);
680
+ } @else {
681
+ @return false;
682
+ }
683
+
684
+ // if we have a what param, need to check if the package is needed
685
+ @if $what and $what != all {
686
+
687
+ // check if we have only some - in the states list
688
+ // mean that we want to only remove these specified states
689
+ // from the all states list
690
+ $onlyRemove : true;
691
+ @each $w in $what {
692
+ @if str-slice($w,1,1) != '-' {
693
+ $onlyRemove : false;
694
+ }
695
+ }
696
+
697
+ @if $onlyRemove {
698
+ @each $name in $package {
699
+ @if index($what, unquote("-#{$name}")) {
700
+ @return false;
701
+ }
702
+ }
703
+ @return true;
704
+ } @else {
705
+ @each $name in $package {
706
+ @if index($what, unquote("#{$name}")) {
707
+ @return true;
708
+ }
709
+ }
710
+ @return false;
711
+ }
712
+ }
713
+ // we don't have a what param so the package is
714
+ @return true;
715
+ }
716
+
717
+
718
+ //
719
+ // Check if is in generate mode
720
+ //
721
+ @function _gridle_is_in_generate_phase() {
722
+ @return $_gridle_is_in_generate_phase;
723
+ }
724
+
725
+
726
+ //
727
+ // Get the media query for a particular state, or with, etc...
728
+ //
729
+ // @param Mixed $state-or-min-width The state name of the min with
730
+ // @param Mixed $max-width The max width if first param is a min width
731
+ // @return String The media query string without the @media
732
+ //
733
+ @function gridle_get_media_query(
734
+ $state-or-settings : current
325
735
  ) {
326
736
  // check if is a string :
327
737
  $state : null;
328
738
  @if type-of($state-or-settings) == string
329
739
  {
330
- $state : _gridle_get_state($state-or-settings);
740
+ $state : gridle_get_state($state-or-settings);
331
741
  }
332
742
  @else if $state-or-settings == null
333
743
  {
@@ -374,14 +784,4 @@
374
784
  {
375
785
  @return null;
376
786
  }
377
- }
378
-
379
-
380
- /**
381
- * Get states count
382
- *
383
- * @return int The number of states defined
384
- */
385
- @function _gridle_get_states_count() {
386
- @return length($_gridle_states) / length($_gridle_states_vars_pattern);
387
787
  }