layout-tools-for-susy 0.1.7 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0a06f492038c161c9160dd02d377f3f57c1821d8
4
- data.tar.gz: 96e79b7ee7ab98a9640aad024d18f0d30c166bcc
3
+ metadata.gz: 8b75bf3940e1f7a74739b2ee94da01f5d2586eb3
4
+ data.tar.gz: aab3d23f999e15af17c248903e880fa91fcb1380
5
5
  SHA512:
6
- metadata.gz: 94e8d596e65e91d97e1035fa91da0f9f6c3213fd37da00b0391f59a1a57d056e50d94733f52ccc905214b1a55418014c1e243e37cb3ec8ad8e2a928aa6cf1a8e
7
- data.tar.gz: 7ce8f63259e0184558376f347d38d1f17a5458f1c844928f8a4cae444e49648d94087e832f4f5c437b2d6a0d129d30377bdc4a0f9aee934668243bccac43dc42
6
+ metadata.gz: 99f46292aa593ddd4c1390c05dc455e7d2b36f2b4700b89232151ef35f8bb68e1bd8f2cdd2c9a5ed8e0691f8a6f7a0013c0fc0352b7a8b663dc6eda085a77c97
7
+ data.tar.gz: b20b1373b056401a28fc7503d90c2062d3ad55f9c9b922b10fe9a9b411e1c60ab5d19b0e185c0fd0147e49dd51227616b8e6093d420653a2df8a0a794ee7ab18
data/README.md CHANGED
@@ -32,7 +32,7 @@ $ npm install layout-tools-for-susy --save-dev
32
32
  This installs layout tools and Susy. Include tools in your stylesheets like this:
33
33
  ```scss
34
34
  // file: src/stylesheets/styles.scss
35
- @import '../../node_modules/susy/sass/susy',
35
+ @import '../../node_modules/layout-tools-for-susy/node_modules/susy/sass/susy',
36
36
  '../../node_modules/layout-tools-for-susy/stylesheets/layout-tools-for-susy';
37
37
  ```
38
38
 
@@ -139,7 +139,7 @@ $layouts: (
139
139
  @include layout-init($layouts);
140
140
 
141
141
  ```
142
- The root properties of the map $layouts represent the different layout contexts. Layout contexts may be layout variations depending on breakpoints or layout settings specific for e.g. a certain template. There are some important settings that will be defined by default if you don’t set them yourself. The `default` layout will be set up by—you guessed it—default with the properties `susy`—containing Susy’s default settings—and `base`—setting a `base__font-size` and `base__line-height` value. To implement your custom layouts, you have to create your settings map like shown above overriding the defaults and adding additional layout specifications.
142
+ The root properties of the map $layouts represent the different layout contexts. Layout contexts may be layout variations depending on breakpoints or layout settings specific for e.g. a certain template. There are some important settings that will be defined by default if you don’t set them yourself. The `default` layout will be set up by—you guessed it—default with the properties `susy`—containing Susy’s default settings—and `base`—setting a `base__font-size` and `base__line-height` value. To implement your custom layouts, you have to create your settings map like shown above overriding the defaults and adding additional layout specifications.
143
143
 
144
144
  #### Using layout contexts
145
145
  The `default` layout context is the most basic. It will be used everywhere where no other layout context is set (by using the `layout-use` mixin). All other layout contexts extend the `default` context and thus override its settings. If you want to extend a specific context, you can define it using the `extends` property within a layout context’s definition map. In the example above the layout context `L` extends `M`. That means the settings and values you will be working with in the layout context `L` are the result from first merging `M` into `default` and then `L` into the first merge’s result. So within the context of `L` the value of `base__font-size` will be 18px. This behaviour allows you create a sophisticated system of layout settings through controlled inheritance of settings and values.
@@ -224,7 +224,7 @@ $my-component: (
224
224
 
225
225
  // Use styles
226
226
  .my-component {
227
-
227
+
228
228
  &__label {
229
229
  // Retrieve settings from current layout context
230
230
  $label__font-size: layout-get(my-component, label__font-size);
@@ -264,7 +264,7 @@ $layouts: (
264
264
  ...
265
265
  ),
266
266
  breakpoint: (
267
- (
267
+ (
268
268
  min-width: 480px,
269
269
  max-width: 800px,
270
270
  min-height: 650px
@@ -308,7 +308,7 @@ As you can see, it's possible to define a single, simple breakpoint through addi
308
308
  }
309
309
  }
310
310
  ```
311
- That’s it. Easy, isn’t it?
311
+ That’s it. Easy, isn’t it?
312
312
 
313
313
  ## More handy helpers
314
314
  Layout Tools for Susy come with some more handy helpers.
@@ -343,7 +343,7 @@ body {
343
343
  }
344
344
 
345
345
  .page {
346
-
346
+
347
347
  &__header {
348
348
  // retrieve font sizes from layout context
349
349
  $header__font-size: layout-get(page, header__font-size);
@@ -387,7 +387,7 @@ body {
387
387
  }
388
388
  }
389
389
  }
390
- }
390
+ }
391
391
  }
392
392
  ```
393
393
  In the example above the ```type-context``` mixin is used to set new local font sizes and line heights as ```em``` values. In contrast to ```type-base``` the base values ```$base__font-size``` and ```$base__line-height``` won’t be altered within the mixins scope. Multiple type contexts can be embedded into each other and the mixin will take track of the relative font sizes and line heights and the necessary calculations.
@@ -429,4 +429,4 @@ background-image: url(const(BG_IMG_PATH) + 'hero_bg.jpg');
429
429
 
430
430
  ### Tips and tricks
431
431
 
432
- ### Contribute
432
+ ### Contribute
@@ -12,6 +12,6 @@ else
12
12
  end
13
13
 
14
14
  module LayoutTools
15
- VERSION = "0.1.7"
16
- DATE = "2016-01-21"
17
- end
15
+ VERSION = "0.2.0"
16
+ DATE = "2017-06-14"
17
+ end
@@ -7,12 +7,25 @@
7
7
  @import 'functions/map-set',
8
8
  'functions/map-merge-r',
9
9
  'functions/list-implode',
10
+ 'functions/list-remove-nth',
10
11
  'placeholders/clearfix';
11
12
 
12
13
  // constants
13
14
  @import 'mixins/const',
14
15
  'functions/const';
15
16
 
17
+ // Cache
18
+ @import 'functions/cache-set',
19
+ 'functions/cache-get',
20
+ 'mixins/cache-set',
21
+ 'functions/cache-push',
22
+ 'mixins/cache-push',
23
+ 'functions/cache-unshift',
24
+ 'mixins/cache-unshift',
25
+ 'functions/cache-nth',
26
+ 'functions/cache-pop',
27
+ 'functions/cache-shift';
28
+
16
29
  // Unit calculations
17
30
  @import 'functions/px-to-em',
18
31
  'functions/px-to-pc',
@@ -1,6 +1,7 @@
1
1
  /**
2
2
  * Set up layout-relevant globals
3
3
  */
4
+ $CACHE: () !global;
4
5
  $LAYOUT: () !global;
5
6
  $COLORS: () !global;
6
7
  $susy: () !global;
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Returns a value for a $key from $CACHE map
3
+ * @param {String} $key Key of the value to be retreived.
4
+ * @return {Misc} Value or false if there’s no value or $key.
5
+ */
6
+ @function cache-get($key) {
7
+ @return map-get($CACHE, $key);
8
+ }
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Returns the nth value from a list at $key from $CACHE map
3
+ * @param {String} $key Key of the list the value is to be retreived from.
4
+ * @param {Integer} $index Index of the value to be retreived.
5
+ * @return {Misc} Value or false if there’s no value at $index.
6
+ */
7
+ @function cache-nth($key, $index: 1) {
8
+ $list: cache-get($key);
9
+ @if (type-of($list) != list) {
10
+ @return false;
11
+ }
12
+ @return nth($list, $index);
13
+ }
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Removes last value from a list at $key on $CACHE map and returns it
3
+ * @param {String} $key Key of the list on $CACHE map.
4
+ * @return {Misc} Removed value.
5
+ */
6
+ @function cache-pop($key) {
7
+ $list: cache-get($key);
8
+ @if (type-of($list) != list) {
9
+ @return false;
10
+ }
11
+ $index: length($list);
12
+ $value: nth($list, $index);
13
+ $new: list-remove-nth($list, $index);
14
+ $CACHE: cache-set($key, $new) !global;
15
+ @return $value;
16
+ }
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Pushs a value to a list in $CACHE map.
3
+ * @param {Map} $map Map the value will be set in.
4
+ * @param {String} $key Key the value will be set for.
5
+ * @param {Misc} $value Value to be pushed.
6
+ * @return {map} Merged map
7
+ */
8
+ @function cache-push($key, $value) {
9
+ $list: cache-get($key);
10
+ @if (type-of($list) != list) {
11
+ @return false;
12
+ }
13
+ $new: ( $key: join($list, ( $value ), comma) );
14
+ @return map-merge($CACHE, $new);
15
+ }
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Sets a value in $CACHE map.
3
+ * @param {Map} $map Map the value will be set in.
4
+ * @param {String} $key Key the value will be set for.
5
+ * @param {Misc} $value Value to be set.
6
+ */
7
+ @function cache-set($key, $value) {
8
+ $new: ( $key: $value );
9
+ @return map-merge($CACHE, $new);
10
+ }
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Removes first value from a list at $key on $CACHE map and returns it
3
+ * @param {String} $key Key of the list on $CACHE map.
4
+ * @return {Misc} Removed value.
5
+ */
6
+ @function cache-shift($key) {
7
+ $list: cache-get($key);
8
+ @if (type-of($list) != list) {
9
+ @return false;
10
+ }
11
+ $index: 1;
12
+ $value: nth($list, $index);
13
+ $new: list-remove-nth($list, $index);
14
+ $CACHE: cache-set($key, $new) !global;
15
+ @return $value;
16
+ }
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Prepends a value to a list in $CACHE map.
3
+ * @param {Map} $map Map the value will be set in.
4
+ * @param {String} $key Key of the list the value will be prepended to.
5
+ * @param {Misc} $value Value to be prepended.
6
+ * @return {map} Merged map
7
+ */
8
+ @function cache-unshift($key, $value) {
9
+ $list: cache-get($key);
10
+ @if (type-of($list) != list) {
11
+ @return false;
12
+ }
13
+ $new: ( $key: join(( $value ), $list, comma) );
14
+ @return map-merge($CACHE, $new);
15
+ }
@@ -5,14 +5,14 @@
5
5
  * @param {Boolean} $recursive: false Optionally implode items of type list.
6
6
  * @return {String} Imploded list as string.
7
7
  */
8
- @function list-implode($list, $separator: '', $recursive: false) {
9
- $result: "";
8
+ @function list-implode($list, $separator: '') {
9
+ $result: null;
10
10
  @for $i from 1 through length($list) {
11
11
  $e: nth($list, $i);
12
- @if (type-of($e) == list and $recursive) {
13
- $e: list-implode($e, $separator, $recursive);
12
+ @if (type-of($e) == list) {
13
+ $e: list-implode($e, $separator);
14
14
  }
15
- $result: if($i != length($list), $result + "#{$e}#{$separator}", $result + "#{$e}");
15
+ $result: if($i != length($list), $result#{$e}#{$separator}, $result#{$e});
16
16
  }
17
- @return unquote('') + $result;
18
- }
17
+ @return $result;
18
+ }
@@ -0,0 +1,34 @@
1
+ /**
2
+ * Removes nth value from a list
3
+ * @param {List} $list List the value is to be removed from.
4
+ * @param {Integer} $index Index of the value to be removed.
5
+ * @return {List|Boolean} New list with value removed or false, if operation failed.
6
+ */
7
+ @function list-remove-nth($list, $index) {
8
+ $result: null;
9
+
10
+ @if type-of($index) != number {
11
+ @warn "$index: #{quote($index)} is not a number for `remove-nth`.";
12
+ }
13
+
14
+ @else if $index == 0 {
15
+ @warn "List index 0 must be a non-zero integer for `remove-nth`.";
16
+ }
17
+
18
+ @else if abs($index) > length($list) {
19
+ @warn "List index is #{$index} but list is only #{length($list)} item long for `remove-nth`.";
20
+ }
21
+
22
+ @else {
23
+ $result: ();
24
+ $index: if($index < 0, length($list) + $index + 1, $index);
25
+
26
+ @for $i from 1 through length($list) {
27
+ @if $i != $index {
28
+ $result: append($result, nth($list, $i));
29
+ }
30
+ }
31
+ }
32
+
33
+ @return $result;
34
+ }
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Pushs a value to a list on $CACHE map for $key
3
+ * @param {String} $key Key of the list to which the value is to be pushed.
4
+ * @param {misc} $vakue Value to be pushed.
5
+ */
6
+ @mixin cache-push($key, $value) {
7
+ $CACHE: cache-push($key, $value) !global;
8
+ }
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Sets a value on $CACHE map for $key
3
+ * @param {String} $key Key for which the value is to be set.
4
+ * @param {misc} $vakue Value to be set for $key.
5
+ */
6
+ @mixin cache-set($key, $value) {
7
+ $CACHE: cache-set($key, $value) !global;
8
+ }
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Prepends a value to a list on $CACHE map for $key
3
+ * @param {String} $key Key of the list to which the value is to be prepended.
4
+ * @param {misc} $vakue Value to be prepended.
5
+ */
6
+ @mixin cache-unshift($key, $value) {
7
+ $CACHE: cache-unshift($key, $value) !global;
8
+ }
@@ -5,6 +5,12 @@
5
5
  @mixin layout-init($user-layouts) {
6
6
  @if(type-of($user-layouts) == map) {
7
7
  $LAYOUT: layout-extend($user-layouts) !global;
8
+ @include cache-set(base__font-size, ());
9
+ @include cache-set(base__line-height, ());
10
+ @include cache-set(local__font-size, ());
11
+ @include cache-set(local__line-height, ());
12
+ @include cache-set(layout, ());
13
+ @include cache-set(susy, ());
8
14
  $base__font-size: layout-get(base, base__font-size) !global;
9
15
  $base__line-height: layout-get(base, base__line-height) !global;
10
16
  $local__font-size: $base__font-size !global;
@@ -13,22 +13,19 @@
13
13
  $layout-key: nth($layout-key, 1);
14
14
  }
15
15
  // temporarily store layout settings of parent context
16
- $LAYOUT--parent: $LAYOUT;
17
- $susy--parent: $susy;
16
+ @include cache-push(layout, $LAYOUT);
17
+ @include cache-push(susy, $susy);
18
18
  // set new settings globally
19
19
  $LAYOUT: layout-build($layout-key) !global;
20
20
  $susy: layout-get(susy) !global;
21
21
  // set typographic context
22
22
  $base: map-get($LAYOUT, base);
23
- $base__font-size--parent: $base__font-size;
24
- $base__line-height--parent: $base__line-height;
23
+ @include cache-push(base__font-size, $base__font-size);
24
+ @include cache-push(base__line-height, $base__line-height);
25
+
25
26
  $base__font-size: map-get($base, base__font-size) !global;
26
27
  $base__line-height: map-get($base, base__line-height) !global;
27
- // $local__font-size--parent: $local__font-size;
28
- // $local__line-height--parent: $local__line-height;
29
- // $local__font-size: map-get($base, local__font-size) !global;
30
- // $local__line-height: map-get($base, local__line-height) !global;
31
-
28
+
32
29
  // build media query
33
30
  @if ($layout-key == default) {
34
31
  @content;
@@ -85,10 +82,8 @@
85
82
  }
86
83
  }
87
84
  // restore parent layout settings
88
- $LAYOUT: $LAYOUT--parent !global;
89
- $susy: $susy--parent !global;
90
- $base__font-size: $base__font-size--parent !global;
91
- $base__line-height: $base__line-height--parent !global;
92
- // $local__font-size: $local__font-size--parent !global;
93
- // $local__line-height: $local__line-height--parent !global;
85
+ $LAYOUT: cache-pop(layout) !global;
86
+ $susy: cache-pop(susy) !global;
87
+ $base__font-size: cache-pop(base__font-size) !global;
88
+ $base__line-height: cache-pop(base__line-height) !global;
94
89
  }
@@ -1,18 +1,19 @@
1
1
  /**
2
2
  * Sets a base value and creates new absolute typographic context based on rem values.
3
- * @param {px value} $font-size Font size value, default is global $base__font-size.
4
- * @param {px value|Boolean} $line-height: 1.25*$font-size Line height value, default is global $base__font-size
3
+ * @param {px value} $new-font-size Font size value, default is global $base__font-size.
4
+ * @param {px value|Boolean} $new-line-height: 1.25*$new-font-size Line height value, default is global $base__font-size
5
5
  * @param {Booelan} $set-styles: true Pass false to just switch type context without settings styles.
6
6
  */
7
- @mixin type-base($font-size: $base__font-size, $line-height: $base__line-height, $set-styles: true) {
7
+ @mixin type-base($new-font-size: $base__font-size, $new-line-height: $base__line-height, $set-styles: true) {
8
8
  // store current type settings temporarily
9
- $base__font-size--parent: $base__font-size;
10
- $base__line-height--parent: $base__line-height;
11
- $local__font-size--parent: if($local__font-size, $local__font-size, $base__font-size);
12
- $local__line-height--parent: if($local__line-height, $local__line-height, $base__line-height);
9
+ @include cache-push(base__font-size, $base__font-size);
10
+ @include cache-push(base__line-height, $base__line-height);
11
+ @include cache-push(local__font-size, if($local__font-size, $local__font-size, $base__font-size));
12
+ @include cache-push(local__line-height, if($local__line-height, $local__line-height, $base__line-height));
13
+
13
14
  // set new type values
14
- $base__font-size: $font-size !global;
15
- $base__line-height: $line-height !global;
15
+ $base__font-size: $new-font-size !global;
16
+ $base__line-height: $new-line-height !global;
16
17
  $local__font-size: $base__font-size !global;
17
18
  $local__line-height: $base__line-height !global;
18
19
  //set styles
@@ -24,8 +25,8 @@
24
25
  // include content
25
26
  @content;
26
27
  // restore parent type context
27
- $base__font-size: $base__font-size--parent !global;
28
- $base__line-height: $base__line-height--parent !global;
29
- $local__font-size: $local__font-size--parent !global;
30
- $local__line-height: $local__line-height--parent !global;
28
+ $base__font-size: cache-pop(base__font-size) !global;
29
+ $base__line-height: cache-pop(base__line-height) !global;
30
+ $local__font-size: cache-pop(local__font-size) !global;
31
+ $local__line-height: cache-pop(local__line-height) !global;
31
32
  }
@@ -1,24 +1,31 @@
1
1
  /**
2
2
  * Changes the local type context without touching type base.
3
- * @param {px value} $font-size Font size value.
4
- * @param {px value|Boolean} $line-height: 1.25*$font-size Line height value, defaults to 1.25 times font size value.
5
- * @param {Boolean} $set-styles: true Pass false to just switch type context without setting styles.
3
+ * @param {px value} $new-font-size Font size value.
4
+ * @param {px value|Boolean} $new-line-height: 1.25*$new-font-size Line height value, defaults to 1.25 times font size value.
5
+ * @param {Boolean} $set-styles: true Pass false to just switch type context without setting styles.
6
6
  */
7
- @mixin type-context($font-size, $line-height: 1.25 * $font-size, $set-styles: true) {
7
+ @mixin type-context($new-font-size, $new-line-height: 1.25 * $new-font-size, $set-styles: true) {
8
+ $outer__font-size: $local__font-size;
9
+ $outer__line-height: $local__line-height;
10
+ $list: cache-get(local__font-size);
11
+ @if (length($list) <= 1) {
12
+ $outer__font-size: $base__font-size;
13
+ $outer__line-height: $base__line-height;
14
+ }
8
15
  // store context
9
- $local__font-size--parent: $local__font-size;
10
- $local__line-height--parent: $local__line-height;
11
- // override context
12
- $local__font-size: $font-size !global;
13
- $local__line-height: $line-height !global;
16
+ @include cache-push(local__font-size, $local__font-size);
17
+ @include cache-push(local__line-height, $local__line-height);
14
18
  // set styles
15
- @if($set-styles) {
16
- font-size: px-to-em($font-size, $local__font-size--parent);
17
- line-height: px-to-em($line-height, $local__font-size);
19
+ @if ($set-styles) {
20
+ font-size: px-to-em($new-font-size, $outer__font-size);
21
+ line-height: px-to-em($new-line-height, $new-font-size);
18
22
  }
23
+ // override context
24
+ $local__font-size: $new-font-size !global;
25
+ $local__line-height: $new-line-height !global;
19
26
  // include content
20
27
  @content;
21
28
  // restore previous context
22
- $local__font-size: $local__font-size--parent !global;
23
- $local__line-height: $local__line-height--parent !global;
29
+ $local__font-size: cache-pop(local__font-size) !global;
30
+ $local__line-height: cache-pop(local__line-height) !global;
24
31
  }
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: layout-tools-for-susy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.7
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Oliver Wehn
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-01-21 00:00:00.000000000 Z
11
+ date: 2017-06-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sass
@@ -52,6 +52,13 @@ files:
52
52
  - stylesheets/config/_constants.scss
53
53
  - stylesheets/config/_globals.scss
54
54
  - stylesheets/config/_layouts.scss
55
+ - stylesheets/functions/_cache-get.scss
56
+ - stylesheets/functions/_cache-nth.scss
57
+ - stylesheets/functions/_cache-pop.scss
58
+ - stylesheets/functions/_cache-push.scss
59
+ - stylesheets/functions/_cache-set.scss
60
+ - stylesheets/functions/_cache-shift.scss
61
+ - stylesheets/functions/_cache-unshift.scss
55
62
  - stylesheets/functions/_color-get.scss
56
63
  - stylesheets/functions/_color-set.scss
57
64
  - stylesheets/functions/_const.scss
@@ -60,11 +67,15 @@ files:
60
67
  - stylesheets/functions/_layout-get.scss
61
68
  - stylesheets/functions/_list-implode.scss
62
69
  - stylesheets/functions/_list-px-to-em.scss
70
+ - stylesheets/functions/_list-remove-nth.scss
63
71
  - stylesheets/functions/_map-merge-r.scss
64
72
  - stylesheets/functions/_map-set.scss
65
73
  - stylesheets/functions/_px-to-em.scss
66
74
  - stylesheets/functions/_px-to-pc.scss
67
75
  - stylesheets/functions/_px-to-rem.scss
76
+ - stylesheets/mixins/_cache-push.scss
77
+ - stylesheets/mixins/_cache-set.scss
78
+ - stylesheets/mixins/_cache-unshift.scss
68
79
  - stylesheets/mixins/_color-set.scss
69
80
  - stylesheets/mixins/_const.scss
70
81
  - stylesheets/mixins/_layout-extend.scss
@@ -94,7 +105,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
94
105
  version: 1.3.6
95
106
  requirements: []
96
107
  rubyforge_project: layout-tools-for-susy
97
- rubygems_version: 2.0.14
108
+ rubygems_version: 2.0.14.1
98
109
  signing_key:
99
110
  specification_version: 4
100
111
  summary: Handy mixins and functions to handle layout settings for multiple breakpoints.