rux 1.1.1 → 1.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +3 -0
- data/README.md +3 -1
- data/lib/rux/default_tag_builder.rb +1 -1
- data/lib/rux/version.rb +1 -1
- data/spec/render_spec.rb +20 -0
- data/spec/spec_helper.rb +10 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 74fe5ea5efe72399854ca97874db7ae0f9aa59abcc9201fc31725991881148b5
|
4
|
+
data.tar.gz: 5a07947618af42f689f84784ed6a4ce095ef4693cd6e6187008cd4a5cf774b4c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fe10394671a5d56275289a84013f85ae13bf84c6690febf2906ed63d54005c13aee9417db3285855a75e3fc85484b51b84daa596223cd16844ecd4fbe008d728
|
7
|
+
data.tar.gz: 368880ab3405473e61114d846ec3aa54ced6490a070abd358857fcba21b373b8dcfad5eeb8a4b1100b6429a97c24e642b2c4e60bb33384baa3b9da2194d251ab
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,6 @@
|
|
1
|
+
# 1.1.2
|
2
|
+
* Don't slugify HTML attributes in the tag builder either.
|
3
|
+
|
1
4
|
# 1.1.1
|
2
5
|
* Don't slugify HTML attributes.
|
3
6
|
- 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.
|
data/README.md
CHANGED
@@ -170,7 +170,7 @@ end
|
|
170
170
|
|
171
171
|
In other words, positional arguments are not allowed. This is because there's no such thing as a positional HTML attribute - all HTML attributes are key/value pairs. So, in order to match up with HTML, rux components are written with keyword arguments.
|
172
172
|
|
173
|
-
Note also that the rux parser will replace dashes with underscores in
|
173
|
+
Note also that the rux parser will replace dashes with underscores in component tag attributes to adhere to both HTML and Ruby syntax conventions, since HTML attributes use dashes while Ruby keyword arguments use underscores. For example, here's how to write a rux tag for `MyComponent` above:
|
174
174
|
|
175
175
|
```ruby
|
176
176
|
<MyComponent first-name="Homer" last-name="Simpson" />
|
@@ -178,6 +178,8 @@ Note also that the rux parser will replace dashes with underscores in rux tag at
|
|
178
178
|
|
179
179
|
Notice that the rux attribute "first-name" is passed to `MyComponent#initialize` as "first_name".
|
180
180
|
|
181
|
+
Attributes on regular tags, i.e. non-component tags like `<div>` and `<span>`, are not modified. In other words, `<div data-foo="foo">` does _not_ become `<div data_foo="foo">` because that would be very annoying.
|
182
|
+
|
181
183
|
## How it Works
|
182
184
|
|
183
185
|
Translating rux code (Ruby + HTML tags) into Ruby code happens in three phases: lexing, parsing, and emitting. The lexer phase is implemented as a wrapper around the lexer from the [Parser gem](https://github.com/whitequark/parser) that looks for specific patterns in the token stream. When it finds an opening HTML tag, it hands off lexing to the rux lexer. When the tag ends, the lexer continues emitting Ruby tokens, and so on.
|
@@ -13,7 +13,7 @@ module Rux
|
|
13
13
|
''.tap do |result|
|
14
14
|
attributes.each_pair.with_index do |(k, v), idx|
|
15
15
|
result << ' ' unless idx == 0
|
16
|
-
result << "#{k
|
16
|
+
result << "#{k}=\"#{CGI.escape_html(v.to_s)}\""
|
17
17
|
end
|
18
18
|
end
|
19
19
|
end
|
data/lib/rux/version.rb
CHANGED
data/spec/render_spec.rb
CHANGED
@@ -63,4 +63,24 @@ describe Rux do
|
|
63
63
|
"<div><p>Hello World</p><p>Hello World</p><p>Hello World</p><p>Hello World</p></div>"
|
64
64
|
)
|
65
65
|
end
|
66
|
+
|
67
|
+
it 'slugifies ruby arguments' do
|
68
|
+
result = render(<<~RUBY)
|
69
|
+
<DataComponent data-foo="foo" />
|
70
|
+
RUBY
|
71
|
+
|
72
|
+
expect(result).to eq(
|
73
|
+
"<div data-foo=\"foo\"></div>"
|
74
|
+
)
|
75
|
+
end
|
76
|
+
|
77
|
+
it 'does not slugify HTML attributes' do
|
78
|
+
result = render(<<~RUBY)
|
79
|
+
<div data-foo="bar"></div>
|
80
|
+
RUBY
|
81
|
+
|
82
|
+
expect(result).to eq(
|
83
|
+
"<div data-foo=\"bar\"></div>"
|
84
|
+
)
|
85
|
+
end
|
66
86
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -33,5 +33,15 @@ class ArgsComponent < ViewComponent::Base
|
|
33
33
|
end
|
34
34
|
end
|
35
35
|
|
36
|
+
class DataComponent < ViewComponent::Base
|
37
|
+
def initialize(data_foo:)
|
38
|
+
@data_foo = data_foo
|
39
|
+
end
|
40
|
+
|
41
|
+
def call
|
42
|
+
"<div data-foo=\"#{@data_foo}\"></div>"
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
36
46
|
RSpec.configure do |config|
|
37
47
|
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.1.
|
4
|
+
version: 1.1.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: 2023-05-
|
11
|
+
date: 2023-05-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: parser
|