rux 1.0.1 → 1.0.2
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 +4 -0
- data/README.md +3 -1
- data/lib/rux/default_visitor.rb +1 -1
- data/lib/rux/version.rb +1 -1
- data/rux.gemspec +1 -1
- data/spec/parser_spec.rb +13 -13
- data/spec/render_spec.rb +8 -0
- data/spec/spec_helper.rb +14 -1
- metadata +7 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 65ad08596c2e77c802c6f7cb2a458ac8d293d5c80a35c98c8a2eb85a5749b365
|
4
|
+
data.tar.gz: cb6487c91a9b21e328f491f5f23b8703a8b4b20a35ddcfa029a19e56bc835dca
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4bc663ef90eec4c6a8abcfe997f259ccea9d211e898813280f534e4b8b5853a4bbbf3f8358164f4472f9329594a4a8b24e986d7b2fd621ecf74d92ebe09ea3e7
|
7
|
+
data.tar.gz: 944d83744f268a221cda2c414e7dd16df13efe37110a99c0d553ff2237be99f17aef37ae88d6653cdff43f0abe56e64cac48614bd5dd7f187e154cfe3cc0cead
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -1,4 +1,6 @@
|
|
1
|
-
## rux
|
1
|
+
## rux
|
2
|
+
|
3
|
+

|
2
4
|
|
3
5
|
Rux is a JSX-inspired way to write HTML tags in your Ruby code. It can be used to render view components in Rails via the [rux-rails gem](https://github.com/camertron/rux-rails). This repo however contains only the rux parser itself.
|
4
6
|
|
data/lib/rux/default_visitor.rb
CHANGED
data/lib/rux/version.rb
CHANGED
data/rux.gemspec
CHANGED
data/spec/parser_spec.rb
CHANGED
@@ -29,67 +29,67 @@ describe Rux::Parser do
|
|
29
29
|
|
30
30
|
it 'handles single-quoted rux attributes' do
|
31
31
|
expect(compile("<Hello foo='bar' />")).to eq(
|
32
|
-
'render(Hello.new(
|
32
|
+
'render(Hello.new(foo: "bar"))'
|
33
33
|
)
|
34
34
|
|
35
35
|
expect(compile("<Hello foo='bar'></Hello>")).to eq(
|
36
|
-
'render(Hello.new(
|
36
|
+
'render(Hello.new(foo: "bar"))'
|
37
37
|
)
|
38
38
|
end
|
39
39
|
|
40
40
|
it 'handles double-quoted rux attributes' do
|
41
41
|
expect(compile('<Hello foo="bar" />')).to eq(
|
42
|
-
'render(Hello.new(
|
42
|
+
'render(Hello.new(foo: "bar"))'
|
43
43
|
)
|
44
44
|
|
45
45
|
expect(compile('<Hello foo="bar"></Hello>')).to eq(
|
46
|
-
'render(Hello.new(
|
46
|
+
'render(Hello.new(foo: "bar"))'
|
47
47
|
)
|
48
48
|
end
|
49
49
|
|
50
50
|
it 'handles non-uniform spacing between attributes' do
|
51
51
|
expect(compile('<Hello foo="bar" baz= "boo" bix ="bit" />')).to eq(
|
52
|
-
'render(Hello.new(
|
52
|
+
'render(Hello.new(foo: "bar", baz: "boo", bix: "bit"))'
|
53
53
|
)
|
54
54
|
end
|
55
55
|
|
56
56
|
it 'handles boolean attributes' do
|
57
57
|
expect(compile('<Hello disabled />')).to eq(
|
58
|
-
'render(Hello.new(
|
58
|
+
'render(Hello.new(disabled: "true"))'
|
59
59
|
)
|
60
60
|
|
61
61
|
expect(compile('<Hello disabled/>')).to eq(
|
62
|
-
'render(Hello.new(
|
62
|
+
'render(Hello.new(disabled: "true"))'
|
63
63
|
)
|
64
64
|
|
65
65
|
expect(compile('<Hello disabled></Hello>')).to eq(
|
66
|
-
'render(Hello.new(
|
66
|
+
'render(Hello.new(disabled: "true"))'
|
67
67
|
)
|
68
68
|
end
|
69
69
|
|
70
70
|
it 'converts dashes to underscores in attribute keys' do
|
71
71
|
expect(compile('<Hello foo-bar="baz" />')).to eq(
|
72
|
-
'render(Hello.new(
|
72
|
+
'render(Hello.new(foo_bar: "baz"))'
|
73
73
|
)
|
74
74
|
end
|
75
75
|
|
76
76
|
it 'handles simple ruby statements in attributes' do
|
77
77
|
expect(compile('<Hello foo={true} />')).to eq(
|
78
|
-
'render(Hello.new(
|
78
|
+
'render(Hello.new(foo: true))'
|
79
79
|
)
|
80
80
|
end
|
81
81
|
|
82
82
|
it 'handles ruby hashes in attributes' do
|
83
83
|
expect(compile('<Hello foo={{ foo: "bar", baz: "boo" }} />')).to eq(
|
84
|
-
'render(Hello.new(
|
84
|
+
'render(Hello.new(foo: { foo: "bar", baz: "boo" }))'
|
85
85
|
)
|
86
86
|
end
|
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(
|
90
|
+
render(Hello.new(foo: [1, 2, 3].map { |n,|
|
91
91
|
n * 2
|
92
|
-
}
|
92
|
+
}))
|
93
93
|
RUBY
|
94
94
|
end
|
95
95
|
|
data/spec/render_spec.rb
CHANGED
@@ -29,4 +29,12 @@ describe Rux do
|
|
29
29
|
|
30
30
|
expect(result).to eq("<div> <p>Welcome!</p><p>Welcome!</p><p>Welcome!</p> </div>")
|
31
31
|
end
|
32
|
+
|
33
|
+
it 'correctly handles keyword arguments (ruby 3)' do
|
34
|
+
result = render(<<~RUBY)
|
35
|
+
<ArgsComponent a="a" b="b" />
|
36
|
+
RUBY
|
37
|
+
|
38
|
+
expect(result).to eq("<p>a and b</p>")
|
39
|
+
end
|
32
40
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -8,7 +8,7 @@ module ViewComponent
|
|
8
8
|
attr_accessor :content
|
9
9
|
|
10
10
|
def render(component, &block)
|
11
|
-
component.content = block.call
|
11
|
+
component.content = block.call if block
|
12
12
|
component.call
|
13
13
|
end
|
14
14
|
end
|
@@ -20,5 +20,18 @@ class TestComponent < ViewComponent::Base
|
|
20
20
|
end
|
21
21
|
end
|
22
22
|
|
23
|
+
class ArgsComponent < ViewComponent::Base
|
24
|
+
attr_reader :a, :b
|
25
|
+
|
26
|
+
def initialize(a:, b:)
|
27
|
+
@a = a
|
28
|
+
@b = b
|
29
|
+
end
|
30
|
+
|
31
|
+
def call
|
32
|
+
"<p>#{a} and #{b}</p>"
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
23
36
|
RSpec.configure do |config|
|
24
37
|
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.
|
4
|
+
version: 1.0.2
|
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-
|
11
|
+
date: 2021-06-12 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:
|
33
|
+
version: 0.5.5
|
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:
|
40
|
+
version: 0.5.5
|
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.
|
100
|
+
rubygems_version: 3.2.3
|
101
101
|
signing_key:
|
102
102
|
specification_version: 4
|
103
103
|
summary: A jsx-inspired way to write view components.
|