ruby2html 1.1.0 → 1.2.0
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 +17 -17
- data/app/components/first_component.html.rb +9 -0
- data/app/components/second_component.rb +1 -1
- data/app/components/third_component/third_component.html.rb +3 -0
- data/app/components/third_component.rb +7 -0
- data/app/views/benchmark/ruby_2html.html.rb +33 -0
- data/app/views/home/index.html.erb +1 -0
- data/app/views/home/rb_files.html.rb +10 -0
- data/lib/gem/ruby2html/component_helper.rb +2 -2
- data/lib/gem/ruby2html/railtie.rb +31 -0
- data/lib/gem/ruby2html/render.rb +6 -1
- data/lib/gem/ruby2html/version.rb +1 -1
- metadata +8 -4
- data/app/components/first_component.html.erb +0 -9
- data/app/views/benchmark/ruby_2html.html.erb +0 -35
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8e43d3eb304652b48e727067ce4361d654936cc0258589efd82adf55136a687d
|
4
|
+
data.tar.gz: 25900c6ed9f1a441f3f5a2b6d457e13caa5bfca3db99a7573daa89af92351544
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 214487bc59cf8ebc35698f7c16ffca8add3d59dfb52142ef1273e5c1dc67d8351fad286f1b417bfd6e9913ae3c06be8e3bba06c81b9670a5a5561cb47e1ba683
|
7
|
+
data.tar.gz: 430e623e958a739a33cdfd16d9d0039ff3354f1461cfe8d7db0a2418ce6fbff4a0352e37a67227e36058088c9c26fac0ffd2aaad50c3842a1ea71a536133610f
|
data/README.md
CHANGED
@@ -25,18 +25,6 @@ Or install it yourself as:
|
|
25
25
|
|
26
26
|
## 🎨 Usage
|
27
27
|
|
28
|
-
### In your ApplicationController
|
29
|
-
|
30
|
-
File: `app/controllers/application_controller.rb`
|
31
|
-
|
32
|
-
```ruby
|
33
|
-
# frozen_string_literal: true
|
34
|
-
|
35
|
-
class ApplicationController < ActionController::Base
|
36
|
-
include Ruby2html::RailsHelper
|
37
|
-
end
|
38
|
-
```
|
39
|
-
|
40
28
|
### In your views
|
41
29
|
|
42
30
|
File: `app/views/your_view.html.rb`
|
@@ -63,6 +51,18 @@ render partial: 'shared/navbar'
|
|
63
51
|
|
64
52
|
#### Or use your current .erb views
|
65
53
|
|
54
|
+
### In your ApplicationController
|
55
|
+
|
56
|
+
File: `app/controllers/application_controller.rb`
|
57
|
+
|
58
|
+
```ruby
|
59
|
+
# frozen_string_literal: true
|
60
|
+
|
61
|
+
class ApplicationController < ActionController::Base
|
62
|
+
include Ruby2html::RailsHelper
|
63
|
+
end
|
64
|
+
```
|
65
|
+
|
66
66
|
File: `app/views/your_view.html.erb`
|
67
67
|
|
68
68
|
Replace your ERB with beautiful Ruby code:
|
@@ -97,18 +97,18 @@ Replace your ERB with beautiful Ruby code:
|
|
97
97
|
ruby 3.3.3 (2024-06-12 revision f1c7b6f435) +YJIT [x86_64-linux]
|
98
98
|
Warming up --------------------------------------
|
99
99
|
GET /benchmark/html (ERB)
|
100
|
-
|
100
|
+
2.000 i/100ms
|
101
101
|
GET /benchmark/ruby (Ruby2html)
|
102
102
|
1.000 i/100ms
|
103
103
|
Calculating -------------------------------------
|
104
104
|
GET /benchmark/html (ERB)
|
105
|
-
20.
|
105
|
+
20.989 (±19.1%) i/s - 102.000 in 5.077353s
|
106
106
|
GET /benchmark/ruby (Ruby2html)
|
107
|
-
|
107
|
+
20.438 (±19.6%) i/s - 97.000 in 5.010249s
|
108
108
|
|
109
109
|
Comparison:
|
110
|
-
GET /benchmark/html (ERB):
|
111
|
-
GET /benchmark/ruby (Ruby2html):
|
110
|
+
GET /benchmark/html (ERB): 21.0 i/s
|
111
|
+
GET /benchmark/ruby (Ruby2html): 20.4 i/s - same-ish: difference falls within error
|
112
112
|
```
|
113
113
|
|
114
114
|
### With ViewComponents
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
h1 'Benchmark: Ruby2html'
|
4
|
+
|
5
|
+
h2 'User Statistics'
|
6
|
+
ul do
|
7
|
+
li { plain "Total Users: #{@complex_data[:stats][:total_users]}" }
|
8
|
+
li { plain "Average Orders per User: #{@complex_data[:stats][:average_orders_per_user]}" }
|
9
|
+
li { plain "Most Expensive Item: #{@complex_data[:stats][:most_expensive_item]}" }
|
10
|
+
li { plain "Most Popular Country: #{@complex_data[:stats][:most_popular_country]}" }
|
11
|
+
end
|
12
|
+
|
13
|
+
h2 'User List'
|
14
|
+
@complex_data[:users].each do |user|
|
15
|
+
div class: 'user-card' do
|
16
|
+
h3 user[:name]
|
17
|
+
p { plain "Email: #{user[:email]}" }
|
18
|
+
p { plain "Address: #{user[:address][:street]}, #{user[:address][:city]}, #{user[:address][:country]}" }
|
19
|
+
|
20
|
+
h4 'Orders'
|
21
|
+
user[:orders].each do |order|
|
22
|
+
div class: 'order' do
|
23
|
+
p { plain "Order ID: #{order[:id]}" }
|
24
|
+
p { plain "Total: $#{order[:total]}" }
|
25
|
+
ul do
|
26
|
+
order[:items].each do |item|
|
27
|
+
li { plain "#{item[:name]} - $#{item[:price]} (Quantity: #{item[:quantity]})" }
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Ruby2html
|
4
|
+
class TemplateHandler
|
5
|
+
class_attribute :default_format
|
6
|
+
self.default_format = :html
|
7
|
+
|
8
|
+
def self.call(template, source)
|
9
|
+
new.call(template, source)
|
10
|
+
end
|
11
|
+
|
12
|
+
def call(_template, source)
|
13
|
+
<<-RUBY
|
14
|
+
Ruby2html::Render.new(self) do
|
15
|
+
#{source}
|
16
|
+
end.render
|
17
|
+
RUBY
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
class Railtie < Rails::Railtie
|
22
|
+
initializer 'ruby2html.initializer' do
|
23
|
+
Rails.autoloaders.main.ignore(
|
24
|
+
Rails.root.join('app/views/**/*.html.rb'),
|
25
|
+
Rails.root.join('app/components/**/*.html.rb')
|
26
|
+
)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
ActionView::Template.register_template_handler :rb, Ruby2html::TemplateHandler if defined? ActionView::Template
|
data/lib/gem/ruby2html/render.rb
CHANGED
@@ -35,7 +35,12 @@ module Ruby2html
|
|
35
35
|
return plain @context.render(*args, **options, &block)
|
36
36
|
end
|
37
37
|
instance_exec(&@root)
|
38
|
-
@output.string
|
38
|
+
result = @output.string
|
39
|
+
if defined?(ActiveSupport)
|
40
|
+
result = ActiveSupport::SafeBuffer.new(result)
|
41
|
+
end
|
42
|
+
|
43
|
+
result
|
39
44
|
end
|
40
45
|
|
41
46
|
HTML5_TAGS.each do |tag|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby2html
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- sebi
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-08-
|
11
|
+
date: 2024-08-09 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Ruby2HTML empowers developers to write view logic in pure Ruby, seamlessly
|
14
14
|
converting it into clean, well-formatted HTML. Enhance your templating workflow,
|
@@ -33,9 +33,11 @@ files:
|
|
33
33
|
- app/channels/application_cable/channel.rb
|
34
34
|
- app/channels/application_cable/connection.rb
|
35
35
|
- app/components/application_component.rb
|
36
|
-
- app/components/first_component.html.
|
36
|
+
- app/components/first_component.html.rb
|
37
37
|
- app/components/first_component.rb
|
38
38
|
- app/components/second_component.rb
|
39
|
+
- app/components/third_component.rb
|
40
|
+
- app/components/third_component/third_component.html.rb
|
39
41
|
- app/controllers/application_controller.rb
|
40
42
|
- app/controllers/benchmark_controller.rb
|
41
43
|
- app/controllers/concerns/.keep
|
@@ -46,8 +48,9 @@ files:
|
|
46
48
|
- app/models/application_record.rb
|
47
49
|
- app/models/concerns/.keep
|
48
50
|
- app/views/benchmark/normal_html.html.erb
|
49
|
-
- app/views/benchmark/ruby_2html.html.
|
51
|
+
- app/views/benchmark/ruby_2html.html.rb
|
50
52
|
- app/views/home/index.html.erb
|
53
|
+
- app/views/home/rb_files.html.rb
|
51
54
|
- app/views/layouts/application.html.erb
|
52
55
|
- app/views/layouts/mailer.html.erb
|
53
56
|
- app/views/layouts/mailer.text.erb
|
@@ -79,6 +82,7 @@ files:
|
|
79
82
|
- lib/gem/ruby2html.rb
|
80
83
|
- lib/gem/ruby2html/component_helper.rb
|
81
84
|
- lib/gem/ruby2html/rails_helper.rb
|
85
|
+
- lib/gem/ruby2html/railtie.rb
|
82
86
|
- lib/gem/ruby2html/render.rb
|
83
87
|
- lib/gem/ruby2html/version.rb
|
84
88
|
- lib/tasks/.keep
|
@@ -1,35 +0,0 @@
|
|
1
|
-
<%=
|
2
|
-
html(self) do
|
3
|
-
h1 'Benchmark: Ruby2html'
|
4
|
-
|
5
|
-
h2 'User Statistics'
|
6
|
-
ul do
|
7
|
-
li { plain "Total Users: #{@complex_data[:stats][:total_users]}" }
|
8
|
-
li { plain "Average Orders per User: #{@complex_data[:stats][:average_orders_per_user]}" }
|
9
|
-
li { plain "Most Expensive Item: #{@complex_data[:stats][:most_expensive_item]}" }
|
10
|
-
li { plain "Most Popular Country: #{@complex_data[:stats][:most_popular_country]}" }
|
11
|
-
end
|
12
|
-
|
13
|
-
h2 'User List'
|
14
|
-
@complex_data[:users].each do |user|
|
15
|
-
div class: 'user-card' do
|
16
|
-
h3 user[:name]
|
17
|
-
p { plain "Email: #{user[:email]}" }
|
18
|
-
p { plain "Address: #{user[:address][:street]}, #{user[:address][:city]}, #{user[:address][:country]}" }
|
19
|
-
|
20
|
-
h4 'Orders'
|
21
|
-
user[:orders].each do |order|
|
22
|
-
div class: 'order' do
|
23
|
-
p { plain "Order ID: #{order[:id]}" }
|
24
|
-
p { plain "Total: $#{order[:total]}" }
|
25
|
-
ul do
|
26
|
-
order[:items].each do |item|
|
27
|
-
li { plain "#{item[:name]} - $#{item[:price]} (Quantity: #{item[:quantity]})" }
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
35
|
-
%>
|