rux 1.0.3 → 1.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 +4 -4
- data/CHANGELOG.md +7 -0
- data/lib/rux/ast/tag_node.rb +4 -0
- data/lib/rux/default_visitor.rb +2 -2
- data/lib/rux/parser.rb +4 -1
- data/lib/rux/utils.rb +2 -2
- data/lib/rux/version.rb +1 -1
- data/spec/parser_spec.rb +68 -33
- data/spec/render_spec.rb +29 -3
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2bce30eb18d21630d6f5734554e7f81d24443cad2b97134127a606c2f9f0c341
|
4
|
+
data.tar.gz: 8925dcc3f10f9a21f03951c27218f17c9e6dc491a8b3c08864d5cd06650ccf07
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fa4a8295e55aa4bc1be19afbba78f61633ed384752f85f3f19e61e1b5c8566e8ccb26a354bf679c95e671082eefdbb7b66fc7edefbaf57c8527bf66eb2b3d03a
|
7
|
+
data.tar.gz: 4ae2860e39d8ea6ec56b1c4679b4ffd4418a5fa83ba1b30ac71137938e9f66267aecdbd2ef65d4f141108df5f5a99a305b2e051bfdcc513172c7f48f0859eb96
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,10 @@
|
|
1
|
+
# 1.1.1
|
2
|
+
* Don't slugify HTML attributes.
|
3
|
+
- Previously rux would emit `<div data-foo="bar">` as `<div data_foo="bar">` because it treated HTML attributes as if they were being passed as Ruby arguments, which don't allow dashes. If these arguments are passed to a component initializer, then they must be slugified, but HTML attributes shouldn't be affected.
|
4
|
+
|
5
|
+
# 1.1.0
|
6
|
+
* Remove newlines between elements. (@aalin, #3)
|
7
|
+
|
1
8
|
## 1.0.3
|
2
9
|
* Use modern AST format.
|
3
10
|
* Switch back to unparser v0.6.
|
data/lib/rux/ast/tag_node.rb
CHANGED
data/lib/rux/default_visitor.rb
CHANGED
@@ -22,10 +22,10 @@ module Rux
|
|
22
22
|
|
23
23
|
at = node.attrs.each_with_object([]) do |(k, v), ret|
|
24
24
|
next if k == 'as'
|
25
|
-
ret << Utils.attr_to_hash_elem(k, visit(v))
|
25
|
+
ret << Utils.attr_to_hash_elem(k, visit(v), slugify: node.component?)
|
26
26
|
end
|
27
27
|
|
28
|
-
if node.
|
28
|
+
if node.component?
|
29
29
|
result << "render(#{node.name}.new"
|
30
30
|
|
31
31
|
unless node.attrs.empty?
|
data/lib/rux/parser.rb
CHANGED
@@ -188,7 +188,10 @@ module Rux
|
|
188
188
|
end
|
189
189
|
|
190
190
|
def squeeze_lit(lit)
|
191
|
-
lit
|
191
|
+
lit
|
192
|
+
.sub(/\A\s+/) { |s| s.match?(/[\r\n]/) ? "" : s }
|
193
|
+
.sub(/\s+\z/) { |s| s.match?(/[\r\n]/) ? "" : s }
|
194
|
+
.gsub(/\s+/, " ")
|
192
195
|
end
|
193
196
|
|
194
197
|
def literal_ruby_code
|
data/lib/rux/utils.rb
CHANGED
data/lib/rux/version.rb
CHANGED
data/spec/parser_spec.rb
CHANGED
@@ -136,18 +136,14 @@ describe Rux::Parser do
|
|
136
136
|
|
137
137
|
expect(compile(rux_code)).to eq(<<~RUBY.strip)
|
138
138
|
render(Outer.new) {
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
_rux_buf_ << @thing
|
146
|
-
}.to_s
|
147
|
-
}
|
139
|
+
5.times.map {
|
140
|
+
render(Inner.new) {
|
141
|
+
Rux.create_buffer.tap { |_rux_buf_|
|
142
|
+
_rux_buf_ << "What a "
|
143
|
+
_rux_buf_ << @thing
|
144
|
+
}.to_s
|
148
145
|
}
|
149
|
-
|
150
|
-
}.to_s
|
146
|
+
}
|
151
147
|
}
|
152
148
|
RUBY
|
153
149
|
end
|
@@ -163,18 +159,14 @@ describe Rux::Parser do
|
|
163
159
|
|
164
160
|
expect(compile(rux_code)).to eq(<<~RUBY.strip)
|
165
161
|
Rux.tag("div") {
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
_rux_buf_ << @thing
|
173
|
-
}.to_s
|
174
|
-
}
|
162
|
+
5.times.map {
|
163
|
+
Rux.tag("p") {
|
164
|
+
Rux.create_buffer.tap { |_rux_buf_|
|
165
|
+
_rux_buf_ << "What a "
|
166
|
+
_rux_buf_ << @thing
|
167
|
+
}.to_s
|
175
168
|
}
|
176
|
-
|
177
|
-
}.to_s
|
169
|
+
}
|
178
170
|
}
|
179
171
|
RUBY
|
180
172
|
end
|
@@ -198,18 +190,14 @@ describe Rux::Parser do
|
|
198
190
|
|
199
191
|
expect(compile(rux_code)).to eq(<<~RUBY.strip)
|
200
192
|
render(Outer.new) {
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
_rux_buf_ << @cool
|
208
|
-
}.to_s
|
209
|
-
}
|
193
|
+
5.times.map {
|
194
|
+
Rux.tag("div") {
|
195
|
+
Rux.create_buffer.tap { |_rux_buf_|
|
196
|
+
_rux_buf_ << "So "
|
197
|
+
_rux_buf_ << @cool
|
198
|
+
}.to_s
|
210
199
|
}
|
211
|
-
|
212
|
-
}.to_s
|
200
|
+
}
|
213
201
|
}
|
214
202
|
RUBY
|
215
203
|
end
|
@@ -253,4 +241,51 @@ describe Rux::Parser do
|
|
253
241
|
}
|
254
242
|
RUBY
|
255
243
|
end
|
244
|
+
|
245
|
+
it 'does not emit spaces for newlines or indentation' do
|
246
|
+
code = <<~RUX
|
247
|
+
<Hello>
|
248
|
+
<Hola>{first} {second}</Hola>
|
249
|
+
<Hola>{first} {second}</Hola>
|
250
|
+
</Hello>
|
251
|
+
RUX
|
252
|
+
expect(compile(code)).to eq(<<~RUBY.strip)
|
253
|
+
render(Hello.new) {
|
254
|
+
Rux.create_buffer.tap { |_rux_buf_|
|
255
|
+
_rux_buf_ << render(Hola.new) {
|
256
|
+
Rux.create_buffer.tap { |_rux_buf_|
|
257
|
+
_rux_buf_ << first
|
258
|
+
_rux_buf_ << " "
|
259
|
+
_rux_buf_ << second
|
260
|
+
}.to_s
|
261
|
+
}
|
262
|
+
_rux_buf_ << render(Hola.new) {
|
263
|
+
Rux.create_buffer.tap { |_rux_buf_|
|
264
|
+
_rux_buf_ << first
|
265
|
+
_rux_buf_ << " "
|
266
|
+
_rux_buf_ << second
|
267
|
+
}.to_s
|
268
|
+
}
|
269
|
+
}.to_s
|
270
|
+
}
|
271
|
+
RUBY
|
272
|
+
end
|
273
|
+
|
274
|
+
it 'slugifies ruby arguments' do
|
275
|
+
code = <<~RUX
|
276
|
+
<Hello data-foo="bar" />
|
277
|
+
RUX
|
278
|
+
expect(compile(code)).to eq(<<~RUBY.strip)
|
279
|
+
render(Hello.new(data_foo: "bar"))
|
280
|
+
RUBY
|
281
|
+
end
|
282
|
+
|
283
|
+
it 'does not slugify HTML attributes' do
|
284
|
+
code = <<~RUX
|
285
|
+
<div data-foo="bar" />
|
286
|
+
RUX
|
287
|
+
expect(compile(code)).to eq(<<~RUBY.strip)
|
288
|
+
Rux.tag("div", { :"data-foo" => "bar" })
|
289
|
+
RUBY
|
290
|
+
end
|
256
291
|
end
|
data/spec/render_spec.rb
CHANGED
@@ -15,7 +15,7 @@ describe Rux do
|
|
15
15
|
</div>
|
16
16
|
RUBY
|
17
17
|
|
18
|
-
expect(result).to eq("<div
|
18
|
+
expect(result).to eq("<div><p>Welcome!</p><p>Welcome!</p><p>Welcome!</p></div>")
|
19
19
|
end
|
20
20
|
|
21
21
|
it 'handles rux tags inside ruby code' do
|
@@ -27,7 +27,7 @@ describe Rux do
|
|
27
27
|
</div>
|
28
28
|
RUBY
|
29
29
|
|
30
|
-
expect(result).to eq("<div
|
30
|
+
expect(result).to eq("<div><p>Welcome!</p><p>Welcome!</p><p>Welcome!</p></div>")
|
31
31
|
end
|
32
32
|
|
33
33
|
it 'correctly handles keyword arguments (ruby 3)' do
|
@@ -37,4 +37,30 @@ describe Rux do
|
|
37
37
|
|
38
38
|
expect(result).to eq("<p>a and b</p>")
|
39
39
|
end
|
40
|
-
|
40
|
+
|
41
|
+
it 'removes whitespace between elements and text' do
|
42
|
+
result = render(<<~RUBY)
|
43
|
+
<div>
|
44
|
+
<p>Hello World</p>
|
45
|
+
|
46
|
+
<p>
|
47
|
+
Hello World
|
48
|
+
</p>
|
49
|
+
|
50
|
+
<p>
|
51
|
+
Hello
|
52
|
+
World
|
53
|
+
</p>
|
54
|
+
|
55
|
+
<p>
|
56
|
+
|
57
|
+
Hello World
|
58
|
+
</p>
|
59
|
+
</div>
|
60
|
+
RUBY
|
61
|
+
|
62
|
+
expect(result).to eq(
|
63
|
+
"<div><p>Hello World</p><p>Hello World</p><p>Hello World</p><p>Hello World</p></div>"
|
64
|
+
)
|
65
|
+
end
|
66
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rux
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Cameron Dutro
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-05-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: parser
|
@@ -97,7 +97,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
97
97
|
- !ruby/object:Gem::Version
|
98
98
|
version: '0'
|
99
99
|
requirements: []
|
100
|
-
rubygems_version: 3.
|
100
|
+
rubygems_version: 3.4.5
|
101
101
|
signing_key:
|
102
102
|
specification_version: 4
|
103
103
|
summary: A jsx-inspired way to write view components.
|