ruby2html 1.2.0 → 1.3.1

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: 8e43d3eb304652b48e727067ce4361d654936cc0258589efd82adf55136a687d
4
- data.tar.gz: 25900c6ed9f1a441f3f5a2b6d457e13caa5bfca3db99a7573daa89af92351544
3
+ metadata.gz: 379258f81cef17450f4024d02db4dd0ddd3e2bf82b6e49c80d7c56d2bd935425
4
+ data.tar.gz: 7f0f351fa20e636e8f0fe1abbe26e964428bccafee8e42d7d4a54aa374ce44cc
5
5
  SHA512:
6
- metadata.gz: 214487bc59cf8ebc35698f7c16ffca8add3d59dfb52142ef1273e5c1dc67d8351fad286f1b417bfd6e9913ae3c06be8e3bba06c81b9670a5a5561cb47e1ba683
7
- data.tar.gz: 430e623e958a739a33cdfd16d9d0039ff3354f1461cfe8d7db0a2418ce6fbff4a0352e37a67227e36058088c9c26fac0ffd2aaad50c3842a1ea71a536133610f
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(self) do
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.erb`
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
- html do
176
- link_to 'Home', root_path, class: 'btn btn-primary', 'data-turbo': false
177
- end
178
- %>
179
- </div>
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(self) do
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(self) do
220
+ html do
223
221
  h1 class: 'my-class', id: 'second-component-title', 'data-controller': 'second' do
224
222
  'second component'
225
223
  end
@@ -6,4 +6,6 @@ div do
6
6
  h2 'A subheading'
7
7
  end
8
8
 
9
+ another_div
10
+
9
11
  p @item
@@ -4,4 +4,12 @@ class FirstComponent < ApplicationComponent
4
4
  def initialize
5
5
  @item = 'Hello, World!'
6
6
  end
7
+
8
+ def another_div
9
+ div class: 'another' do
10
+ h2 'Another subheading from component'
11
+ end
12
+
13
+ h1 'Yet Another heading from component'
14
+ end
7
15
  end
@@ -3,7 +3,25 @@
3
3
  module Ruby2html
4
4
  module ComponentHelper
5
5
  def html(&block)
6
- Ruby2html::Render.new(self, &block).render.html_safe
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
- Ruby2html::Render.new(self) do
14
+ begin
15
+ previous_renderer = Thread.current[:__ruby2html_renderer__]
16
+ renderer = Ruby2html::Render.new(self) do
15
17
  #{source}
16
- end.render
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
@@ -6,14 +6,14 @@ require 'stringio'
6
6
  module Ruby2html
7
7
  class Render
8
8
  HTML5_TAGS = %w[
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
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Ruby2html
4
- VERSION = '1.2.0'
4
+ VERSION = '1.3.1'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby2html
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - sebi