rux 1.0.2 → 1.1.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 65ad08596c2e77c802c6f7cb2a458ac8d293d5c80a35c98c8a2eb85a5749b365
4
- data.tar.gz: cb6487c91a9b21e328f491f5f23b8703a8b4b20a35ddcfa029a19e56bc835dca
3
+ metadata.gz: f8b60a8c9f9753af9e86862c0f907f726d5c853e2e7c96613d681ea36f6859ac
4
+ data.tar.gz: 4ed1a4772678e181f7fa67ccdd4814e726a2731145e0c8a419261c2b40ad4f36
5
5
  SHA512:
6
- metadata.gz: 4bc663ef90eec4c6a8abcfe997f259ccea9d211e898813280f534e4b8b5853a4bbbf3f8358164f4472f9329594a4a8b24e986d7b2fd621ecf74d92ebe09ea3e7
7
- data.tar.gz: 944d83744f268a221cda2c414e7dd16df13efe37110a99c0d553ff2237be99f17aef37ae88d6653cdff43f0abe56e64cac48614bd5dd7f187e154cfe3cc0cead
6
+ metadata.gz: f70d67e41488c9dc648d4f05692813fe7b00ee86fc3ce34511ab75ad27de888578558775cb075f29b32df3876d0fbc7dfad78be43bdda5c198c52be8a05e5707
7
+ data.tar.gz: c43ab2dbbeeb1ae8ec17b68cb2b24df38e167787b85004bc6085669fb5963180e7f41712f4b41a5697190e851494e575927a21ed01b3800705b721f399eb76fa
data/CHANGELOG.md CHANGED
@@ -1,3 +1,10 @@
1
+ # 1.1.0
2
+ * Remove newlines between elements. (@aalin, #3)
3
+
4
+ ## 1.0.3
5
+ * Use modern AST format.
6
+ * Switch back to unparser v0.6.
7
+
1
8
  ## 1.0.2
2
9
  * Fix bug causing `ArgumentError`s under Ruby 3.0.
3
10
  - Related: https://github.com/mbj/unparser/issues/254
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.2'
2
+ VERSION = '1.1.0'
3
3
  end
data/lib/rux.rb CHANGED
@@ -71,3 +71,15 @@ module Rux
71
71
  self.tag_builder = self.default_tag_builder
72
72
  self.buffer = self.default_buffer
73
73
  end
74
+
75
+ # unfortunately these have to be set globally :(
76
+ Parser::Builders::Default.tap do |builder|
77
+ builder.emit_lambda = true
78
+ builder.emit_procarg0 = true
79
+ builder.emit_encoding = true
80
+ builder.emit_index = true
81
+ builder.emit_arg_inside_procarg0 = true
82
+ builder.emit_forward_arg = true
83
+ builder.emit_kwargs = true
84
+ builder.emit_match_pattern = true
85
+ end
data/rux.gemspec CHANGED
@@ -11,7 +11,7 @@ Gem::Specification.new do |s|
11
11
  s.platform = Gem::Platform::RUBY
12
12
 
13
13
  s.add_dependency 'parser', '~> 3.0'
14
- s.add_dependency 'unparser', '<= 0.5.5'
14
+ s.add_dependency 'unparser', '~> 0.6'
15
15
 
16
16
  s.require_path = 'lib'
17
17
  s.executables << 'ruxc'
data/spec/parser_spec.rb CHANGED
@@ -87,7 +87,7 @@ describe Rux::Parser do
87
87
 
88
88
  it 'handles ruby code with curly braces in attributes' do
89
89
  expect(compile('<Hello foo={[1, 2, 3].map { |n| n * 2 }} />')).to eq(<<~RUBY.strip)
90
- render(Hello.new(foo: [1, 2, 3].map { |n,|
90
+ render(Hello.new(foo: [1, 2, 3].map { |n|
91
91
  n * 2
92
92
  }))
93
93
  RUBY
@@ -104,7 +104,7 @@ describe Rux::Parser do
104
104
  it 'handles tag bodies containing ruby code with curly braces' do
105
105
  expect(compile('<Hello>{[1, 2, 3].map { |n| n * 2 }.join(", ")}</Hello>')).to eq(<<~RUBY.strip)
106
106
  render(Hello.new) {
107
- [1, 2, 3].map { |n,|
107
+ [1, 2, 3].map { |n|
108
108
  n * 2
109
109
  }.join(", ")
110
110
  }
@@ -114,7 +114,7 @@ describe Rux::Parser do
114
114
  it 'handles tag bodies with intermixed text and ruby code' do
115
115
  expect(compile('<Hello>abc {foo} def {bar} baz</Hello>')).to eq(<<~RUBY.strip)
116
116
  render(Hello.new) {
117
- Rux.create_buffer.tap { |_rux_buf_,|
117
+ Rux.create_buffer.tap { |_rux_buf_|
118
118
  _rux_buf_ << "abc "
119
119
  _rux_buf_ << foo
120
120
  _rux_buf_ << " def "
@@ -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
@@ -245,7 +233,7 @@ describe Rux::Parser do
245
233
  it 'emits handles spaces between adjacent ruby code snippets' do
246
234
  expect(compile("<Hello>{first} {second}</Hello>")).to eq(<<~RUBY.strip)
247
235
  render(Hello.new) {
248
- Rux.create_buffer.tap { |_rux_buf_,|
236
+ Rux.create_buffer.tap { |_rux_buf_|
249
237
  _rux_buf_ << first
250
238
  _rux_buf_ << " "
251
239
  _rux_buf_ << second
@@ -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.2
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-12 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
@@ -28,16 +28,16 @@ dependencies:
28
28
  name: unparser
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - "<="
31
+ - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: 0.5.5
33
+ version: '0.6'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - "<="
38
+ - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: 0.5.5
40
+ version: '0.6'
41
41
  description: A jsx-inspired way to write view components.
42
42
  email:
43
43
  - camertron@gmail.com
@@ -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.2.3
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.