sassy-namespaces 0.1 → 0.1.1

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f0bdb5ce796b20f153bb162ea5ed7ceb66d0b6dd
4
- data.tar.gz: 1430c1505c5843be12216c336237831eacd812fe
3
+ metadata.gz: 2769b569ed18c8110272fd03140e32b5e902fba1
4
+ data.tar.gz: 68e75d1b46cb7cf79fc494197e9e86d87d68043b
5
5
  SHA512:
6
- metadata.gz: 83fc0385c77870ea40e837395e08a92ee0c5d48f602ac48d0035ac46b1350d4c852d0b23292fed59d38fa6d6d06a6e864b08971736c9e1d087a0165c138dc71f
7
- data.tar.gz: 895e57d52677c65180cef5f54a9595a3a58f18d015ef5b94bc1a8b923cd37f604c9b5be59349fe262fe7cae392a18d3860ba70e71a878607fe0e2d9917c3e0b6
6
+ metadata.gz: aae3d39c3b2604fef1328e96a98073949a10f76f813fb0d022d7b6106b1ad52492fde07a0060ac62f2836248fd454794d38aa4621de5229fd9a7536b40cf860b
7
+ data.tar.gz: e2dac496bc5263370bdad64dd5034dbffd52b8b124b5270260ff787ae80e4e25f606f1a2aa8aeae94b1f980d6db89592c52043813e6009ca68951fd904651ba2
data/README.md CHANGED
@@ -1,32 +1,39 @@
1
1
  Sassy Namespaces
2
2
  ================
3
3
 
4
- Sass 3.3 brought us maps, which are great for organizing related values into groups, but the syntax is a bit tedious. Sassy Namespaces offers pattern for creating and accessing namespaces using Sass maps.
4
+ Sass 3.3 brought us maps, which are great for grouping related values, but the syntax is a bit tedious. Sassy Namespaces offers a pattern for creating and accessing namespaces using Sass maps.
5
5
 
6
6
  Yes, it's essentially a wrapper around the excellent [Sassy Maps](https://github.com/Team-Sass/Sassy-Maps) extension.
7
7
 
8
8
  The problem
9
9
  -----------
10
10
 
11
- In vanilla Sass, even single-level namespaces are a bit of hassle:
11
+ In vanilla Sass, even single-level namespaces are a bit of a chore:
12
12
 
13
13
  ```scss
14
+ // Create "color" namespace
14
15
  $color: ();
16
+ // Add key-value pair
15
17
  $color: $map-merge($color, (primary: red));
16
18
 
17
- foo {
18
- bar: map-get($color, primary); // bar: red
19
+ output {
20
+ foo: map-get($color, primary); // foo: red
19
21
  }
20
22
  ```
21
23
 
22
- You could define functions/mixins to streamline the process:
24
+ A partial solution is to define wrapper functions/mixins that abstract away the ugliness:
23
25
 
24
26
  ```scss
27
+ // Create "color" namespace
25
28
  $color: ();
26
29
 
30
+ @function color-set($key, $value) {
31
+ @return $map-merge($color, ($key: $value));
32
+ }
33
+
27
34
  // Setter
28
- @mixin set-color($key, $value) {
29
- $color: $map-merge($color, ($key: $value));
35
+ @mixin color-set($key, $value) {
36
+ $color: color-set($key, $value);
30
37
  }
31
38
 
32
39
  // Getter
@@ -34,43 +41,47 @@ $color: ();
34
41
  @return map-get($color, $key);
35
42
  }
36
43
 
37
- @include set-color(primary, red);
38
- foo {
39
- bar: color(primary); // bar: red
44
+ // Add key-value pair
45
+ @include color-set(primary, red);
46
+ output {
47
+ foo: color(primary); // foo: red
40
48
  }
41
49
  ```
42
50
 
43
51
  But this quickly gets tiresome, especially once you try to create namespaces with more than one level of hierarchy.
44
52
 
45
- Sass namespaces, minus the headaches
53
+ Namespaces, minus the headaches
46
54
  ------------------------------------
47
55
 
48
- Here's how you do it with Sassy Namespaces:
56
+ With Sassy Namespaces, maps are created and used internally. You don't ever have to deal with them directly. Easy as:
49
57
 
50
58
  ```scss
51
- @include create-namespace(color);
59
+ // Create a "color" namespace
60
+ @include namespace-create(color); // (This step can be skipped)
61
+ // Add key-value pair
52
62
  @include namespace-set(color, primary, red);
53
- foo {
54
- bar: namespace-get(color, primary); // bar: red;
63
+ ouput {
64
+ foo: namespace-get(color, primary); // foo: red;
55
65
  }
56
66
  ```
57
67
 
58
- Maps are created and used internally, but you don't ever have to deal with them.
68
+ It's possible streamline to this even further. `namespace-set()` will create a namespace if it doesn't exist, so we can skip `namespace-create()`.
59
69
 
60
- It's still a good idea to create convenience functions/mixins. Pretty straightfoward:
70
+ Also, instead of calling `namespace-set()` and `namespace-get()`, we can replace both with the wrapper function/mixin `namespace()`, which will either get or set as is appropriate. This comes in handy when creating wrapper functions/mixins:
61
71
 
62
72
  ```scss
63
- @mixin set-color($args...) {
64
- @include namespace-set(color, $args...);
73
+ // Alias color() to namespace(color)
74
+ @mixin color($args...) {
75
+ $color: namespace(color, $args...);
65
76
  }
66
77
 
67
78
  @function color($args...) {
68
- @return namespace-get(color, $args...);
79
+ @return namespace(color, $args...);
69
80
  }
70
81
 
71
- @include set-color(primary, red);
72
- foo {
73
- bar: color(primary); // bar: red
82
+ @include color(primary, red);
83
+ output {
84
+ foo: color(primary); // foo: red
74
85
  }
75
86
  ```
76
87
 
@@ -81,18 +92,18 @@ If you want to set multiple values at once, without calling `namespace-set()` ov
81
92
  $map: (primary: red, secondary: green)
82
93
 
83
94
  @include namespace-set(color, $map);
84
- foo {
85
- bar: namespace-get(color, primary); // bar: red
86
- baz: namespace-get(color, secondary); // baz: green
95
+ output {
96
+ foo: namespace-get(color, primary); // foo: red
97
+ bar: namespace-get(color, secondary); // bar: green
87
98
  }
88
99
  ```
89
100
 
90
- And, since Sassy Namespaces uses Sassy Maps internally, hierarchical namespaces are free:
101
+ And, since Sassy Namespaces uses Sassy Maps internally, hierarchical namespaces are easy, too:
91
102
 
92
103
  ```scss
93
104
  @include namespace-set(color, text link hover, green);
94
- foo {
95
- bar: namespace-get(color, text link hover); // bar: green
105
+ output {
106
+ foo: namespace-get(color, text link hover); // foo: green
96
107
  }
97
108
  ```
98
109
 
@@ -100,23 +111,19 @@ At any time, you can return the underlying namespace map:
100
111
 
101
112
  ```scss
102
113
  @include namespace-set(color, primary, red);
103
- $namespace-1: namespace(color);
114
+ $namespace-1: namespace-get(color);
104
115
 
105
116
  @include namespace-set(color, secondary, green);
106
- $namespace-2: namespace(color);
117
+ $namespace-2: namespace-get(color);
107
118
 
108
119
  /*
109
120
  $namespace-1: (
110
- color: (
111
- primary: red
112
- )
121
+ primary: red
113
122
  )
114
123
 
115
124
  $namespace-2: (
116
- color: (
117
- primary: red,
118
- secondary: green
119
- )
125
+ primary: red,
126
+ secondary: green
120
127
  )
121
128
  */
122
129
  ```
@@ -5,6 +5,6 @@ extension_path = File.expand_path(File.join(File.dirname(__FILE__), ".."))
5
5
  Compass::Frameworks.register('SassyNamespaces', :path => extension_path)
6
6
 
7
7
  module SassyNamespaces
8
- VERSION = "0.1"
8
+ VERSION = "0.1.1"
9
9
  DATE = "2014-03-17"
10
10
  end
@@ -1,20 +1,19 @@
1
1
  @import "sassy-maps";
2
2
 
3
+ // Private map that holds the namespaces
3
4
  $__sassy-namespaces: ();
4
5
 
5
- @mixin create-namespace($name) {
6
- $__sassy-namespaces: map-set($__sassy-namespaces, $name, ());
7
- }
8
-
6
+ // Add a key-value pair to an existing namespace, or to a new one if it doesn't already exist
7
+ // Returns the updated namespace map
9
8
  @function namespace-set($name, $args...) {
10
9
  $length: length($args);
11
- $namespace: map-get($__sassy-namespaces, $name);
10
+ $namespace: map-get($__sassy-namespaces, $name) or ($name: ());
12
11
 
13
12
  @if length($args) == 1 {
14
13
  @if type-of(nth($args, 1)) == map {
15
14
  $namespace: map-merge($namespace, nth($args, 1));
16
15
  } @else {
17
- @warn "Must pass either a map or 2 or more values."
16
+ @warn "Must pass either a map or a key and a value.";
18
17
  }
19
18
  }
20
19
  @else {
@@ -31,10 +30,17 @@ $__sassy-namespaces: ();
31
30
  @return $namespace;
32
31
  }
33
32
 
33
+
34
+ // Return value for key of a namespace
35
+ // Returns null if key or namespace doesn't exist
34
36
  @function namespace-get($name, $args...) {
35
37
  $length: length($args);
36
38
  $namespace: map-get($__sassy-namespaces, $name);
37
39
 
40
+ @if not $namespace {
41
+ @return null;
42
+ }
43
+
38
44
  @if $length > 0 {
39
45
  $keys: nth($args, 1);
40
46
 
@@ -48,6 +54,22 @@ $__sassy-namespaces: ();
48
54
  }
49
55
  }
50
56
 
51
- @mixin namespace-set($name, $args...) {
57
+ @function namespace($args...) {
58
+ @return namespace-get($args...) or namespace-set($args...);
59
+ }
60
+
61
+ @mixin namespace-get($args...) {
52
62
  $namespace: namespace-set($name, $args...);
63
+ }
64
+
65
+ @mixin namespace-get($args...) {
66
+ $namespace: namespace-get($name, $args...);
67
+ }
68
+
69
+ @mixin namespace($name, $args...) {
70
+ $namespace: namespace($name, $args...);
71
+ }
72
+
73
+ @mixin namespace-create($name, $args...) {
74
+ @include namespace-set($name, $args...);
53
75
  }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sassy-namespaces
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.1'
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Clark
@@ -61,8 +61,8 @@ extra_rdoc_files: []
61
61
  files:
62
62
  - README.md
63
63
  - lib/sassy-namespaces.rb
64
- - stylesheets/_sassy-maps.scss
65
- homepage:
64
+ - stylesheets/_sassy-stylesheets.scss
65
+ homepage: https://github.com/acdlite/sassy-namespaces
66
66
  licenses: []
67
67
  metadata: {}
68
68
  post_install_message: