sassy-namespaces 0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: f0bdb5ce796b20f153bb162ea5ed7ceb66d0b6dd
4
+ data.tar.gz: 1430c1505c5843be12216c336237831eacd812fe
5
+ SHA512:
6
+ metadata.gz: 83fc0385c77870ea40e837395e08a92ee0c5d48f602ac48d0035ac46b1350d4c852d0b23292fed59d38fa6d6d06a6e864b08971736c9e1d087a0165c138dc71f
7
+ data.tar.gz: 895e57d52677c65180cef5f54a9595a3a58f18d015ef5b94bc1a8b923cd37f604c9b5be59349fe262fe7cae392a18d3860ba70e71a878607fe0e2d9917c3e0b6
data/README.md ADDED
@@ -0,0 +1,122 @@
1
+ Sassy Namespaces
2
+ ================
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.
5
+
6
+ Yes, it's essentially a wrapper around the excellent [Sassy Maps](https://github.com/Team-Sass/Sassy-Maps) extension.
7
+
8
+ The problem
9
+ -----------
10
+
11
+ In vanilla Sass, even single-level namespaces are a bit of hassle:
12
+
13
+ ```scss
14
+ $color: ();
15
+ $color: $map-merge($color, (primary: red));
16
+
17
+ foo {
18
+ bar: map-get($color, primary); // bar: red
19
+ }
20
+ ```
21
+
22
+ You could define functions/mixins to streamline the process:
23
+
24
+ ```scss
25
+ $color: ();
26
+
27
+ // Setter
28
+ @mixin set-color($key, $value) {
29
+ $color: $map-merge($color, ($key: $value));
30
+ }
31
+
32
+ // Getter
33
+ @function color($key) {
34
+ @return map-get($color, $key);
35
+ }
36
+
37
+ @include set-color(primary, red);
38
+ foo {
39
+ bar: color(primary); // bar: red
40
+ }
41
+ ```
42
+
43
+ But this quickly gets tiresome, especially once you try to create namespaces with more than one level of hierarchy.
44
+
45
+ Sass namespaces, minus the headaches
46
+ ------------------------------------
47
+
48
+ Here's how you do it with Sassy Namespaces:
49
+
50
+ ```scss
51
+ @include create-namespace(color);
52
+ @include namespace-set(color, primary, red);
53
+ foo {
54
+ bar: namespace-get(color, primary); // bar: red;
55
+ }
56
+ ```
57
+
58
+ Maps are created and used internally, but you don't ever have to deal with them.
59
+
60
+ It's still a good idea to create convenience functions/mixins. Pretty straightfoward:
61
+
62
+ ```scss
63
+ @mixin set-color($args...) {
64
+ @include namespace-set(color, $args...);
65
+ }
66
+
67
+ @function color($args...) {
68
+ @return namespace-get(color, $args...);
69
+ }
70
+
71
+ @include set-color(primary, red);
72
+ foo {
73
+ bar: color(primary); // bar: red
74
+ }
75
+ ```
76
+
77
+
78
+ If you want to set multiple values at once, without calling `namespace-set()` over and over, you can pass a map of keys and values (instead of a single key and a single value):
79
+
80
+ ```scss
81
+ $map: (primary: red, secondary: green)
82
+
83
+ @include namespace-set(color, $map);
84
+ foo {
85
+ bar: namespace-get(color, primary); // bar: red
86
+ baz: namespace-get(color, secondary); // baz: green
87
+ }
88
+ ```
89
+
90
+ And, since Sassy Namespaces uses Sassy Maps internally, hierarchical namespaces are free:
91
+
92
+ ```scss
93
+ @include namespace-set(color, text link hover, green);
94
+ foo {
95
+ bar: namespace-get(color, text link hover); // bar: green
96
+ }
97
+ ```
98
+
99
+ At any time, you can return the underlying namespace map:
100
+
101
+ ```scss
102
+ @include namespace-set(color, primary, red);
103
+ $namespace-1: namespace(color);
104
+
105
+ @include namespace-set(color, secondary, green);
106
+ $namespace-2: namespace(color);
107
+
108
+ /*
109
+ $namespace-1: (
110
+ color: (
111
+ primary: red
112
+ )
113
+ )
114
+
115
+ $namespace-2: (
116
+ color: (
117
+ primary: red,
118
+ secondary: green
119
+ )
120
+ )
121
+ */
122
+ ```
@@ -0,0 +1,10 @@
1
+ require 'compass'
2
+ require 'sassy-maps'
3
+
4
+ extension_path = File.expand_path(File.join(File.dirname(__FILE__), ".."))
5
+ Compass::Frameworks.register('SassyNamespaces', :path => extension_path)
6
+
7
+ module SassyNamespaces
8
+ VERSION = "0.1"
9
+ DATE = "2014-03-17"
10
+ end
@@ -0,0 +1,53 @@
1
+ @import "sassy-maps";
2
+
3
+ $__sassy-namespaces: ();
4
+
5
+ @mixin create-namespace($name) {
6
+ $__sassy-namespaces: map-set($__sassy-namespaces, $name, ());
7
+ }
8
+
9
+ @function namespace-set($name, $args...) {
10
+ $length: length($args);
11
+ $namespace: map-get($__sassy-namespaces, $name);
12
+
13
+ @if length($args) == 1 {
14
+ @if type-of(nth($args, 1)) == map {
15
+ $namespace: map-merge($namespace, nth($args, 1));
16
+ } @else {
17
+ @warn "Must pass either a map or 2 or more values."
18
+ }
19
+ }
20
+ @else {
21
+ $keys: nth($args, 1);
22
+
23
+ @if length($keys) == 1 {
24
+ $namespace: map-set($namespace, $args...);
25
+ } @else {
26
+ $namespace: map-set-deep($namespace, $args...);
27
+ }
28
+ }
29
+
30
+ $__sassy-namespaces: map-merge($__sassy-namespaces, ($name: $namespace));
31
+ @return $namespace;
32
+ }
33
+
34
+ @function namespace-get($name, $args...) {
35
+ $length: length($args);
36
+ $namespace: map-get($__sassy-namespaces, $name);
37
+
38
+ @if $length > 0 {
39
+ $keys: nth($args, 1);
40
+
41
+ @if length($keys) == 1 {
42
+ @return map-get($namespace, $args...);
43
+ } @else {
44
+ @return map-get-deep($namespace, $args...);
45
+ }
46
+ } @else {
47
+ @return $namespace;
48
+ }
49
+ }
50
+
51
+ @mixin namespace-set($name, $args...) {
52
+ $namespace: namespace-set($name, $args...);
53
+ }
metadata ADDED
@@ -0,0 +1,88 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sassy-namespaces
3
+ version: !ruby/object:Gem::Version
4
+ version: '0.1'
5
+ platform: ruby
6
+ authors:
7
+ - Andrew Clark
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-03-17 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: sass
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '3.3'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '3.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: compass
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0.12'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0.12'
41
+ - !ruby/object:Gem::Dependency
42
+ name: sassy-maps
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: 0.3.2
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: 0.3.2
55
+ description: Namespaces in Sass, minus the headaches.
56
+ email:
57
+ - acdlite@me.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - README.md
63
+ - lib/sassy-namespaces.rb
64
+ - stylesheets/_sassy-maps.scss
65
+ homepage:
66
+ licenses: []
67
+ metadata: {}
68
+ post_install_message:
69
+ rdoc_options: []
70
+ require_paths:
71
+ - lib
72
+ required_ruby_version: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ required_rubygems_version: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - ">="
80
+ - !ruby/object:Gem::Version
81
+ version: 1.3.6
82
+ requirements: []
83
+ rubyforge_project: sassy-namespaces
84
+ rubygems_version: 2.2.2
85
+ signing_key:
86
+ specification_version: 4
87
+ summary: Syntactic sugar for using maps as namespaces.
88
+ test_files: []