rux 1.0.3 → 1.1.0

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: f8b60a8c9f9753af9e86862c0f907f726d5c853e2e7c96613d681ea36f6859ac
4
+ data.tar.gz: 4ed1a4772678e181f7fa67ccdd4814e726a2731145e0c8a419261c2b40ad4f36
5
5
  SHA512:
6
- metadata.gz: 20072b74e6c7ecb9c78af907c72ede1b132e28ea6a6d2fe1edbc0675aa8453cedd88de58f397d09d43841c601dd4fd65ff7144e6aaa73bb882ab3de564c897e4
7
- data.tar.gz: 19b14226872597dfa750b34debe1c39ea681da99eb4c099c065eb2ea0ff1736666070d82f4ec9e5db489b06fbbec5ea25c648396934e0a47eec7c82233a9ae5a
6
+ metadata.gz: f70d67e41488c9dc648d4f05692813fe7b00ee86fc3ce34511ab75ad27de888578558775cb075f29b32df3876d0fbc7dfad78be43bdda5c198c52be8a05e5707
7
+ data.tar.gz: c43ab2dbbeeb1ae8ec17b68cb2b24df38e167787b85004bc6085669fb5963180e7f41712f4b41a5697190e851494e575927a21ed01b3800705b721f399eb76fa
data/CHANGELOG.md CHANGED
@@ -1,3 +1,6 @@
1
+ # 1.1.0
2
+ * Remove newlines between elements. (@aalin, #3)
3
+
1
4
  ## 1.0.3
2
5
  * Use modern AST format.
3
6
  * Switch back to unparser v0.6.
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/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Rux
2
- VERSION = '1.0.3'
2
+ VERSION = '1.1.0'
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,33 @@ 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
256
273
  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.0
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: 2022-12-17 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.2.22
101
101
  signing_key:
102
102
  specification_version: 4
103
103
  summary: A jsx-inspired way to write view components.