ruby2html 1.2.0 → 1.3.1
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/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: 379258f81cef17450f4024d02db4dd0ddd3e2bf82b6e49c80d7c56d2bd935425
|
4
|
+
data.tar.gz: 7f0f351fa20e636e8f0fe1abbe26e964428bccafee8e42d7d4a54aa374ce44cc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0744010717f690632ea0c5fd8042cae5fc84eb31d00b65ec3f153a0cce6e2f523750ff23ec6b46d028bc215844137f3a4b35ce0a1370250a3f9f275527e058e6
|
7
|
+
data.tar.gz: dd934691897d726bed26a73bfecf61d515a780ee7ba45471a2efdaf0848156b6afa918e9d45ef9f9dd8231cb032bd9f4cef040befafd3abe888c228526321ef6
|
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, **options, &block)
|
16
|
+
if __ruby2html_renderer__.respond_to?(method)
|
17
|
+
__ruby2html_renderer__.send(method, *args, **options, &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
|