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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2bce30eb18d21630d6f5734554e7f81d24443cad2b97134127a606c2f9f0c341
4
- data.tar.gz: 8925dcc3f10f9a21f03951c27218f17c9e6dc491a8b3c08864d5cd06650ccf07
3
+ metadata.gz: 74fe5ea5efe72399854ca97874db7ae0f9aa59abcc9201fc31725991881148b5
4
+ data.tar.gz: 5a07947618af42f689f84784ed6a4ce095ef4693cd6e6187008cd4a5cf774b4c
5
5
  SHA512:
6
- metadata.gz: fa4a8295e55aa4bc1be19afbba78f61633ed384752f85f3f19e61e1b5c8566e8ccb26a354bf679c95e671082eefdbb7b66fc7edefbaf57c8527bf66eb2b3d03a
7
- data.tar.gz: 4ae2860e39d8ea6ec56b1c4679b4ffd4418a5fa83ba1b30ac71137938e9f66267aecdbd2ef65d4f141108df5f5a99a305b2e051bfdcc513172c7f48f0859eb96
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 rux 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:
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.to_s.gsub('-', '_')}=\"#{CGI.escape_html(v.to_s)}\""
16
+ result << "#{k}=\"#{CGI.escape_html(v.to_s)}\""
17
17
  end
18
18
  end
19
19
  end
data/lib/rux/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Rux
2
- VERSION = '1.1.1'
2
+ VERSION = '1.1.2'
3
3
  end
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.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-28 00:00:00.000000000 Z
11
+ date: 2023-05-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: parser