xass 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (6) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile.lock +7 -7
  3. data/README.md +37 -38
  4. data/lib/xass.rb +26 -32
  5. data/xass.gemspec +2 -2
  6. metadata +6 -6
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 376b30a8930cfe354ce8093ef63e87b2c925e6a8
4
- data.tar.gz: 45047749d602f718e572d6136b2603cc2b1d0ac2
3
+ metadata.gz: b92f761f31b78611e6fb903d0405ea97624e899f
4
+ data.tar.gz: d33d71d2a47b26f5c07efa014a4c83902ead0538
5
5
  SHA512:
6
- metadata.gz: 553d01e5b16b3b6d921695ad5eea1b1ebc8a2db1b4419b56ce6428d4ac07c33bf459947da68a750e6c7e2da3b85b8b9bdcced3e950058d6ac60a9c4cdcb6b05b
7
- data.tar.gz: 667687cb31f8a0277695a03ced263a636e531713cd0a36425392892a1e29b837191867cf98f7ff5a3d2845cb3eeb9d5a8b6a3fde0ce0c9daa007e07282bbfa93
6
+ metadata.gz: a90d64d429b02e361cc3c94556c52f8502f3df55726f6e21d2b2681f51114fb59a51d1b4f6675c103cb079378bc9a14f86695fc4ac04553c98daf7801943d519
7
+ data.tar.gz: 7047ae1e555ff7e838d4d849c71ab55bb58e769e32085426d612534e6e3bb6842bf794cedf4ee60b089165b702d907cb1c08ce7fd0ef42d4046ee50a121dbbce
data/Gemfile.lock CHANGED
@@ -1,11 +1,11 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- xass (0.1.9)
4
+ xass (0.3.0)
5
5
  activesupport (~> 4.0)
6
6
  csspool
7
7
  nokogiri
8
- sass
8
+ sass (= 3.4.7)
9
9
 
10
10
  GEM
11
11
  remote: https://rubygems.org/
@@ -38,7 +38,7 @@ GEM
38
38
  tzinfo (~> 1.1)
39
39
  arel (5.0.1.20140414130214)
40
40
  builder (3.2.2)
41
- csspool (4.0.1)
41
+ csspool (4.0.2)
42
42
  diff-lcs (1.2.5)
43
43
  erubis (2.7.0)
44
44
  haml (4.0.5)
@@ -49,11 +49,11 @@ GEM
49
49
  mail (2.6.1)
50
50
  mime-types (>= 1.16, < 3)
51
51
  mime-types (2.3)
52
- mini_portile (0.6.0)
52
+ mini_portile (0.6.1)
53
53
  minitest (5.4.1)
54
54
  multi_json (1.10.1)
55
- nokogiri (1.6.3.1)
56
- mini_portile (= 0.6.0)
55
+ nokogiri (1.6.4.1)
56
+ mini_portile (~> 0.6.0)
57
57
  rack (1.5.2)
58
58
  rack-test (0.6.2)
59
59
  rack (>= 1.0)
@@ -85,7 +85,7 @@ GEM
85
85
  rspec-mocks (3.1.0)
86
86
  rspec-support (~> 3.1.0)
87
87
  rspec-support (3.1.0)
88
- sass (3.4.3)
88
+ sass (3.4.7)
89
89
  sprockets (2.12.2)
90
90
  hike (~> 1.2)
91
91
  multi_json (~> 1.0)
data/README.md CHANGED
@@ -2,6 +2,10 @@
2
2
 
3
3
  Xass extends Rails with namespacing CSS classes in Sass.
4
4
 
5
+ ##SUPPORT
6
+
7
+ Currently supported sass version is 3.2.19
8
+
5
9
  ##INSTALLATION
6
10
 
7
11
  We suppose you use Rails with sass-rails.
@@ -14,7 +18,7 @@ gem 'xass'
14
18
 
15
19
  ##USAGE
16
20
 
17
- ###Example 1
21
+ ###Namespacing by directory tree
18
22
 
19
23
  ```sass
20
24
  // /app/assets/stylesheets/application.sass
@@ -29,7 +33,7 @@ gem 'xass'
29
33
  width: 100px
30
34
  ```
31
35
 
32
- This emits the following css.
36
+ This emits the following css (notice that there are three underscores before `hogehoge`.)
33
37
 
34
38
  ```css
35
39
  .hoge__piyo__fuga___hogehoge {
@@ -37,13 +41,14 @@ This emits the following css.
37
41
  }
38
42
  ```
39
43
 
40
- In view, use helpers to apply the style.
44
+ In view, use helpers or `ns` prefixed class names to apply the style.
41
45
 
42
46
  ```haml
43
47
  -# /app/views/someview.html.haml
44
48
 
45
49
  = namespace :hoge, :piyo, :fuga do
46
- %div{ class: ns(:hogehoge) }
50
+ .ns-hogehoge
51
+ -# or %div{ class: ns(:hogehoge) }
47
52
  ```
48
53
 
49
54
  This emits
@@ -60,21 +65,25 @@ As matter of course, `namespace` can be nested as follows.
60
65
  = namespace :hoge do
61
66
  = namespace :piyo do
62
67
  = namespace :fuga do
63
- %div{ class: ns(:hogehoge) }
68
+ .ns-hogehoge
64
69
  ```
65
70
 
66
- ###Example 2
71
+ If you don't want to dig namespaces, you can specify namespaces directly in `ns` prefixed class name.
67
72
 
68
- You can use `root` class for convenience.
73
+ ```haml
74
+ = namespace :hoge do
75
+ .ns-piyo--fuga--hogehoge
76
+ ```
77
+
78
+ ###Special class name `root`
79
+
80
+ You can use `root` class for specify a root class name.
69
81
 
70
82
  ```sass
71
83
  // /app/assets/stylesheets/main/hoge/piyo/fuga.sass
72
84
 
73
85
  .root
74
86
  width: 10px
75
-
76
- .hogehoge
77
- width: 100px
78
87
  ```
79
88
 
80
89
  This emits
@@ -83,10 +92,6 @@ This emits
83
92
  .hoge__piyo__fuga {
84
93
  width: 10px;
85
94
  }
86
-
87
- .hoge__piyo__fuga___hogehoge {
88
- width: 100px;
89
- }
90
95
  ```
91
96
 
92
97
  And,
@@ -95,16 +100,14 @@ And,
95
100
  -# /app/views/someview.html.haml
96
101
 
97
102
  = namespace :hoge, :piyo, :fuga do
98
- %div{ class: ns_root }
99
- %div{ class: ns(:hogehoge) }
103
+ .nsr
104
+ -# or %div{ class: nsr }
100
105
  ```
101
106
 
102
107
  This emits
103
108
 
104
109
  ```html
105
- <div class="hoge__piyo__fuga">
106
- <div class="hoge__piyo__fuga___hogehoge"></div>
107
- </div>
110
+ <div class="hoge__piyo__fuga"></div>
108
111
  ```
109
112
 
110
113
  Abbreviately, you can write this as follows.
@@ -112,11 +115,10 @@ Abbreviately, you can write this as follows.
112
115
  ```haml
113
116
  -# /app/views/someview.html.haml
114
117
 
115
- = namespace_with_root :hoge, :piyo, :fuga do
116
- %div{ class: ns(:hogehoge) }
118
+ = namespace_with_root :hoge, :piyo, :fuga
117
119
  ```
118
120
 
119
- ###Example 3
121
+ ###Disable namespacing
120
122
 
121
123
  You can use `_` prefix to disable namespacing.
122
124
 
@@ -129,12 +131,6 @@ You can use `_` prefix to disable namespacing.
129
131
  ```sass
130
132
  // /app/assets/stylesheets/main/hoge/piyo/fuga.sass
131
133
 
132
- .root
133
- width: 10px
134
-
135
- .hogehoge
136
- width: 100px
137
-
138
134
  ._current
139
135
  background-color: black
140
136
  ```
@@ -142,20 +138,12 @@ You can use `_` prefix to disable namespacing.
142
138
  This emits the following css.
143
139
 
144
140
  ```css
145
- .hoge__piyo__fuga {
146
- width: 10px;
147
- }
148
-
149
- .hoge__piyo__fuga___hogehoge {
150
- width: 100px;
151
- }
152
-
153
141
  .current {
154
142
  background-color: black;
155
143
  }
156
144
  ```
157
145
 
158
- ###Example 4
146
+ ###Reset current namespace
159
147
 
160
148
  In partial, you may want to reset current namespace. `namespace!` and `namespace_with_root!` do this.
161
149
 
@@ -167,7 +155,7 @@ In partial, you may want to reset current namespace. `namespace!` and `namespace
167
155
  ```
168
156
 
169
157
  ```haml
170
- -# /app/views/partial.html.haml
158
+ -# /app/views/_partial.html.haml
171
159
 
172
160
  = namespace_with_root! :foo do
173
161
  foo
@@ -182,3 +170,14 @@ This emits
182
170
  </div>
183
171
  </div>
184
172
  ```
173
+
174
+ ###Abbreviations
175
+
176
+ The following aliases are available.
177
+
178
+ ```ruby
179
+ alias :dns :namespace
180
+ alias :dns! :namespace!
181
+ alias :dnsr :namespace_with_root
182
+ alias :dnsr! :namespace_with_root!
183
+ ```
data/lib/xass.rb CHANGED
@@ -3,43 +3,37 @@ require_relative 'initialize'
3
3
  module Sass::Tree
4
4
  class Visitors::Perform
5
5
  def visit_mixin(node)
6
- include_loop = true
7
- handle_include_loop!(node) if @stack.any? {|e| e[:name] == node.name}
8
- include_loop = false
6
+ @environment.stack.with_mixin(node.filename, node.line, node.name) do
7
+ mixin = @environment.mixin(node.name)
8
+ raise Sass::SyntaxError.new("Undefined mixin '#{node.name}'.") unless mixin
9
9
 
10
- @stack.push(:filename => node.filename, :line => node.line, :name => node.name)
11
- raise Sass::SyntaxError.new("Undefined mixin '#{node.name}'.") unless mixin = @environment.mixin(node.name)
12
-
13
- if node.children.any? && !mixin.has_content
14
- raise Sass::SyntaxError.new(%Q{Mixin "#{node.name}" does not accept a content block.})
15
- end
10
+ if node.children.any? && !mixin.has_content
11
+ raise Sass::SyntaxError.new(%Q{Mixin "#{node.name}" does not accept a content block.})
12
+ end
16
13
 
17
- args = node.args.map {|a| a.perform(@environment)}
18
- keywords = Sass::Util.map_hash(node.keywords) {|k, v| [k, v.perform(@environment)]}
19
- splat = node.splat.perform(@environment) if node.splat
20
-
21
- self.class.perform_arguments(mixin, args, keywords, splat) do |env|
22
- env.caller = Sass::Environment.new(@environment)
23
- env.content = node.children if node.has_children
24
-
25
- trace_node = Sass::Tree::TraceNode.from_node(node.name, node)
26
- with_environment(env) {
27
- trace_node.children = mixin.tree.map {|c|
28
- d = c.deep_copy
29
- xass_recursive_set_filename(d, node.filename)
30
- visit(d)
31
- }.flatten
32
- }
33
- trace_node
14
+ args = node.args.map {|a| a.perform(@environment)}
15
+ keywords = Sass::Util.map_vals(node.keywords) {|v| v.perform(@environment)}
16
+ splat = self.class.perform_splat(node.splat, keywords, node.kwarg_splat, @environment)
17
+
18
+ self.class.perform_arguments(mixin, args, splat, @environment) do |env|
19
+ env.caller = Sass::Environment.new(@environment)
20
+ env.content = [node.children, @environment] if node.has_children
21
+
22
+ trace_node = Sass::Tree::TraceNode.from_node(node.name, node)
23
+ with_environment(env) {
24
+ trace_node.children = mixin.tree.map { |c|
25
+ d = c.deep_copy
26
+ xass_recursive_set_filename(d, node.filename)
27
+ visit(c)
28
+ }.flatten
29
+ }
30
+ trace_node
31
+ end
34
32
  end
35
33
  rescue Sass::SyntaxError => e
36
- unless include_loop
37
- e.modify_backtrace(:mixin => node.name, :line => node.line)
38
- e.add_backtrace(:line => node.line)
39
- end
34
+ e.modify_backtrace(:mixin => node.name, :line => node.line)
35
+ e.add_backtrace(:line => node.line)
40
36
  raise e
41
- ensure
42
- @stack.pop unless include_loop
43
37
  end
44
38
 
45
39
  private
data/xass.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'xass'
3
- s.version = '0.2.0'
3
+ s.version = '0.3.0'
4
4
  s.authors = ['Tetsuri Moriya']
5
5
  s.email = ['tetsuri.moriya@gmail.com']
6
6
  s.summary = 'Sass namespace extension'
@@ -12,7 +12,7 @@ Gem::Specification.new do |s|
12
12
  s.add_development_dependency 'rails', '>= 0'
13
13
  s.add_development_dependency 'haml', '>= 0'
14
14
  s.add_runtime_dependency 'activesupport', '~> 4.0'
15
- s.add_runtime_dependency 'sass', '>= 0'
15
+ s.add_runtime_dependency 'sass', '= 3.4.7'
16
16
  s.add_runtime_dependency 'csspool', '>= 0'
17
17
  s.add_runtime_dependency 'nokogiri', '>= 0'
18
18
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: xass
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tetsuri Moriya
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-09-12 00:00:00.000000000 Z
11
+ date: 2014-11-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -70,16 +70,16 @@ dependencies:
70
70
  name: sass
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - ">="
73
+ - - '='
74
74
  - !ruby/object:Gem::Version
75
- version: '0'
75
+ version: 3.4.7
76
76
  type: :runtime
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - ">="
80
+ - - '='
81
81
  - !ruby/object:Gem::Version
82
- version: '0'
82
+ version: 3.4.7
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: csspool
85
85
  requirement: !ruby/object:Gem::Requirement