rux 1.0.3 → 1.1.1

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
  SHA256:
3
- metadata.gz: 6a29eb709f4897a46f267f53bc09b7e5379385564b46e063e27801dfaf75b6df
4
- data.tar.gz: 7873d289f9601f029c3283b28a01f56955b2c88e7eb423ddabb388d42bf02ee1
3
+ metadata.gz: 2bce30eb18d21630d6f5734554e7f81d24443cad2b97134127a606c2f9f0c341
4
+ data.tar.gz: 8925dcc3f10f9a21f03951c27218f17c9e6dc491a8b3c08864d5cd06650ccf07
5
5
  SHA512:
6
- metadata.gz: 20072b74e6c7ecb9c78af907c72ede1b132e28ea6a6d2fe1edbc0675aa8453cedd88de58f397d09d43841c601dd4fd65ff7144e6aaa73bb882ab3de564c897e4
7
- data.tar.gz: 19b14226872597dfa750b34debe1c39ea681da99eb4c099c065eb2ea0ff1736666070d82f4ec9e5db489b06fbbec5ea25c648396934e0a47eec7c82233a9ae5a
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.
@@ -12,6 +12,10 @@ module Rux
12
12
  def accept(visitor)
13
13
  visitor.visit_tag(self)
14
14
  end
15
+
16
+ def component?
17
+ name.start_with?(/[A-Z]/)
18
+ end
15
19
  end
16
20
  end
17
21
  end
@@ -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.name.start_with?(/[A-Z]/)
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.gsub(/\s/, ' ').squeeze(' ')
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
@@ -1,7 +1,7 @@
1
1
  module Rux
2
2
  module Utils
3
- def attr_to_hash_elem(key, value)
4
- key = key.gsub('-', '_')
3
+ def attr_to_hash_elem(key, value, slugify: true)
4
+ key = key.gsub('-', '_') if slugify
5
5
 
6
6
  if key =~ /\A[\w\d]+\z/
7
7
  "#{key}: #{value}"
data/lib/rux/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Rux
2
- VERSION = '1.0.3'
2
+ VERSION = '1.1.1'
3
3
  end
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
- Rux.create_buffer.tap { |_rux_buf_|
140
- _rux_buf_ << " "
141
- _rux_buf_ << 5.times.map {
142
- render(Inner.new) {
143
- Rux.create_buffer.tap { |_rux_buf_|
144
- _rux_buf_ << "What a "
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
- _rux_buf_ << " "
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
- Rux.create_buffer.tap { |_rux_buf_|
167
- _rux_buf_ << " "
168
- _rux_buf_ << 5.times.map {
169
- Rux.tag("p") {
170
- Rux.create_buffer.tap { |_rux_buf_|
171
- _rux_buf_ << "What a "
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
- _rux_buf_ << " "
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
- Rux.create_buffer.tap { |_rux_buf_|
202
- _rux_buf_ << " "
203
- _rux_buf_ << 5.times.map {
204
- Rux.tag("div") {
205
- Rux.create_buffer.tap { |_rux_buf_|
206
- _rux_buf_ << "So "
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
- _rux_buf_ << " "
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> <p>Welcome!</p><p>Welcome!</p><p>Welcome!</p> </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> <p>Welcome!</p><p>Welcome!</p><p>Welcome!</p> </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
- end
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.0.3
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: 2021-06-13 00:00:00.000000000 Z
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.1.4
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.