ruby2html 1.2.0 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +13 -15
- data/app/components/first_component.html.rb +2 -0
- data/app/components/first_component.rb +8 -0
- data/lib/gem/ruby2html/component_helper.rb +19 -1
- data/lib/gem/ruby2html/railtie.rb +9 -2
- data/lib/gem/ruby2html/render.rb +12 -8
- data/lib/gem/ruby2html/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 006b9857270b4ad9ebc613ca84e1e00327285e4e52f371417a42d2823e6b3099
|
4
|
+
data.tar.gz: f78b3b0d8929174dde445502d0c90051ff6ac95a8b37f7e05e7722ff91d96aaf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: aa9a480274cbe132f1053010d218b5f1e3e56be27dd224fc0d41867ea85e2d0afb763b121fb8179f2426d4bcbb5f17a0c70b0c361aff7b722afada0ea7b7a046
|
7
|
+
data.tar.gz: 49c3f7a01bfd9cc058ce68a672b8e2c159a41895a7af6b2352a8d150b192e1da445ea124640807d0d291da8cc53b528e25f9a960bf1e21f0103db7e48463abf0
|
data/README.md
CHANGED
@@ -138,7 +138,7 @@ class GreetingComponent < ApplicationComponent
|
|
138
138
|
end
|
139
139
|
|
140
140
|
def call
|
141
|
-
html
|
141
|
+
html do
|
142
142
|
h1 class: 'greeting', 'data-user': @name do
|
143
143
|
"Hello, #{@name}! 👋"
|
144
144
|
end
|
@@ -164,19 +164,17 @@ class FarewellComponent < ApplicationComponent
|
|
164
164
|
end
|
165
165
|
```
|
166
166
|
|
167
|
-
File: `app/components/farewell_component.html.
|
168
|
-
|
169
|
-
```erb
|
170
|
-
<div class="farewell">
|
171
|
-
<h2>Goodbye, <%= @name %>! 👋</h2>
|
172
|
-
<p>We hope you enjoyed using Ruby2html!</p>
|
167
|
+
File: `app/components/farewell_component.html.rb`
|
173
168
|
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
169
|
+
```rb
|
170
|
+
div class: 'farewell' do
|
171
|
+
h1 class: 'farewell-message' do
|
172
|
+
"Goodbye, #{@name}! 👋"
|
173
|
+
end
|
174
|
+
p class: 'farewell-text' do
|
175
|
+
'We hope to see you again soon!'
|
176
|
+
end
|
177
|
+
end
|
180
178
|
```
|
181
179
|
|
182
180
|
This flexibility allows you to:
|
@@ -197,7 +195,7 @@ class FirstComponent < ApplicationComponent
|
|
197
195
|
end
|
198
196
|
|
199
197
|
def call
|
200
|
-
html
|
198
|
+
html do
|
201
199
|
h1 id: 'first-component-title' do
|
202
200
|
'first component'
|
203
201
|
end
|
@@ -219,7 +217,7 @@ File: `app/components/second_component.rb`
|
|
219
217
|
|
220
218
|
class SecondComponent < ApplicationComponent
|
221
219
|
def call
|
222
|
-
html
|
220
|
+
html do
|
223
221
|
h1 class: 'my-class', id: 'second-component-title', 'data-controller': 'second' do
|
224
222
|
'second component'
|
225
223
|
end
|
@@ -3,7 +3,25 @@
|
|
3
3
|
module Ruby2html
|
4
4
|
module ComponentHelper
|
5
5
|
def html(&block)
|
6
|
-
|
6
|
+
previous_renderer = __ruby2html_renderer__
|
7
|
+
Ruby2html::Render.new(self, &block).yield_self do |component_renderer|
|
8
|
+
Thread.current[:__ruby2html_renderer__] = component_renderer
|
9
|
+
component_renderer.render.html_safe
|
10
|
+
end
|
11
|
+
ensure
|
12
|
+
Thread.current[:__ruby2html_renderer__] = previous_renderer
|
13
|
+
end
|
14
|
+
|
15
|
+
def method_missing(method, *args, &block)
|
16
|
+
if __ruby2html_renderer__.respond_to?(method)
|
17
|
+
__ruby2html_renderer__.send(method, *args, &block)
|
18
|
+
else
|
19
|
+
super
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def __ruby2html_renderer__
|
24
|
+
Thread.current[:__ruby2html_renderer__]
|
7
25
|
end
|
8
26
|
end
|
9
27
|
end
|
@@ -11,9 +11,16 @@ module Ruby2html
|
|
11
11
|
|
12
12
|
def call(_template, source)
|
13
13
|
<<-RUBY
|
14
|
-
|
14
|
+
begin
|
15
|
+
previous_renderer = Thread.current[:__ruby2html_renderer__]
|
16
|
+
renderer = Ruby2html::Render.new(self) do
|
15
17
|
#{source}
|
16
|
-
end
|
18
|
+
end
|
19
|
+
Thread.current[:__ruby2html_renderer__] = renderer
|
20
|
+
renderer.render
|
21
|
+
ensure
|
22
|
+
Thread.current[:__ruby2html_renderer__] = previous_renderer
|
23
|
+
end
|
17
24
|
RUBY
|
18
25
|
end
|
19
26
|
end
|
data/lib/gem/ruby2html/render.rb
CHANGED
@@ -6,14 +6,14 @@ require 'stringio'
|
|
6
6
|
module Ruby2html
|
7
7
|
class Render
|
8
8
|
HTML5_TAGS = %w[
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
9
|
+
a abbr address area article aside audio b base bdi bdo blockquote body br button canvas caption
|
10
|
+
cite code col colgroup data datalist dd del details dfn dialog div dl dt em embed fieldset
|
11
|
+
figcaption figure footer form h1 h2 h3 h4 h5 h6 head header hr html i iframe img input ins
|
12
|
+
kbd label legend li link main map mark meta meter nav noscript object ol optgroup option
|
13
|
+
output p param picture pre progress q rp rt ruby s samp script section select small source
|
14
|
+
span strong style sub summary sup table tbody td template textarea tfoot th thead time title
|
15
|
+
tr track u ul var video wbr
|
16
|
+
].freeze
|
17
17
|
|
18
18
|
VOID_ELEMENTS = %w[area base br col embed hr img input link meta param source track wbr].freeze
|
19
19
|
|
@@ -49,6 +49,10 @@ module Ruby2html
|
|
49
49
|
end
|
50
50
|
end
|
51
51
|
|
52
|
+
def respond_to?(method_name, include_private = false)
|
53
|
+
HTML5_TAGS.include?(method_name) || super
|
54
|
+
end
|
55
|
+
|
52
56
|
def html!(name, *args, **options, &block)
|
53
57
|
content = args.first.is_a?(String) ? args.shift : nil
|
54
58
|
attributes = options
|