ruby2html 1.3.3 → 1.5.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/.rubocop.yml +3 -0
- data/README.md +13 -6
- data/app/views/home/index.html.erb +6 -3
- data/app/views/home/rb_files.html.rb +6 -1
- data/app/views/layouts/application.html.erb +0 -1
- data/config/environments/development.rb +2 -0
- data/config/routes.rb +1 -0
- data/lib/gem/ruby2html/html_beautifier_middleware.rb +26 -0
- data/lib/gem/ruby2html/railtie.rb +1 -1
- data/lib/gem/ruby2html/render.rb +11 -10
- data/lib/gem/ruby2html/version.rb +1 -1
- metadata +18 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b2bea9aba310afffa16b447b62ff3de51cfa14357520b687b048e58af727e766
|
4
|
+
data.tar.gz: f139b135af3c215ec2709b1b30fd8f8a7cd7dc941709dfcd5f5d1ef1d21fe63d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ef60077fcf16bf1e046368280d9a96222c412cbc1f8369350293cdf2149ff6d7cc3f1184c5a6c2acecf93ce2b10406f45bcb6000e70cfa3ba9fc2987e7d64e30
|
7
|
+
data.tar.gz: a71ef6f89836cf773cb4c7de7f9c01ec13081ba1a13cc35a569d2ef90436403ce7b4811862883c16b5002f137a993d88bc5144ee0b1e9f7204683324e0707235
|
data/.rubocop.yml
CHANGED
data/README.md
CHANGED
@@ -34,12 +34,12 @@ div class: 'container' do
|
|
34
34
|
h1 'Welcome to Ruby2html! 🎉', class: 'main-title', 'data-controller': 'welcome'
|
35
35
|
link_to 'Home Sweet Home 🏠', root_path, class: 'btn btn-primary', 'data-turbo': false
|
36
36
|
|
37
|
-
@
|
38
|
-
h2 class: 'item-title', id: "
|
39
|
-
|
37
|
+
@products.each do |product|
|
38
|
+
h2 class: 'item-title', id: "product-#{product[:id]}" do
|
39
|
+
product.title
|
40
40
|
end
|
41
41
|
p class: 'item-description' do
|
42
|
-
|
42
|
+
product.description
|
43
43
|
end
|
44
44
|
end
|
45
45
|
end
|
@@ -49,6 +49,13 @@ plain '<div>Inline html</div>'.html_safe
|
|
49
49
|
render partial: 'shared/navbar'
|
50
50
|
```
|
51
51
|
|
52
|
+
### (Optional) Nicely Format the HTML for source inspection
|
53
|
+
|
54
|
+
File: `config/environments/development.rb` or `config/environments/test.rb`
|
55
|
+
```ruby
|
56
|
+
config.middleware.use Ruby2html::HtmlBeautifierMiddleware
|
57
|
+
```
|
58
|
+
|
52
59
|
#### Or use your current .erb views
|
53
60
|
|
54
61
|
### In your ApplicationController
|
@@ -77,10 +84,10 @@ Replace your ERB with beautiful Ruby code:
|
|
77
84
|
|
78
85
|
@items.each do |item|
|
79
86
|
h2 class: 'item-title', id: "item-#{item[:id]}" do
|
80
|
-
item
|
87
|
+
item.title
|
81
88
|
end
|
82
89
|
p class: 'item-description' do
|
83
|
-
item
|
90
|
+
item.description
|
84
91
|
end
|
85
92
|
end
|
86
93
|
|
@@ -14,10 +14,13 @@
|
|
14
14
|
h1 "ok"
|
15
15
|
h1 "ok"
|
16
16
|
div do
|
17
|
-
link_to 'home', root_path
|
17
|
+
link_to 'home 1', root_path
|
18
|
+
end
|
19
|
+
link_to 'home 2', root_path
|
20
|
+
|
21
|
+
div do
|
22
|
+
link_to 'home 3', root_path
|
18
23
|
end
|
19
|
-
link_to 'home', root_path
|
20
|
-
link_to 'home', root_path
|
21
24
|
|
22
25
|
render partial: 'shared/navbar'
|
23
26
|
|
@@ -2,10 +2,15 @@
|
|
2
2
|
|
3
3
|
h1 'RbFiles'
|
4
4
|
h1 'ok'
|
5
|
-
h1 '
|
5
|
+
h1 'okddwadwa'
|
6
6
|
|
7
7
|
div @value
|
8
8
|
|
9
|
+
form_with url: '/test' do |f|
|
10
|
+
f.text_field :name, placeholder: 'Name'
|
11
|
+
f.submit 'Submit'
|
12
|
+
end
|
13
|
+
|
9
14
|
link_to 'Home', root_url
|
10
15
|
render partial: 'shared/navbar'
|
11
16
|
render partial: 'shared/footer'
|
data/config/routes.rb
CHANGED
@@ -0,0 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'htmlbeautifier'
|
4
|
+
|
5
|
+
module Ruby2html
|
6
|
+
class HtmlBeautifierMiddleware
|
7
|
+
def initialize(app)
|
8
|
+
@app = app
|
9
|
+
end
|
10
|
+
|
11
|
+
def call(env)
|
12
|
+
status, headers, body = @app.call(env)
|
13
|
+
|
14
|
+
if headers['Content-Type']&.include?('text/html')
|
15
|
+
new_body = []
|
16
|
+
body.each do |chunk|
|
17
|
+
new_body << HtmlBeautifier.beautify(chunk)
|
18
|
+
end
|
19
|
+
headers['Content-Length'] = new_body.map(&:bytesize).sum.to_s
|
20
|
+
body = new_body
|
21
|
+
end
|
22
|
+
|
23
|
+
[status, headers, body]
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -17,7 +17,7 @@ module Ruby2html
|
|
17
17
|
#{source}
|
18
18
|
end
|
19
19
|
Thread.current[:__ruby2html_renderer__] = renderer
|
20
|
-
renderer.
|
20
|
+
renderer.__render_from_rails(#{template.identifier.inspect})
|
21
21
|
ensure
|
22
22
|
Thread.current[:__ruby2html_renderer__] = previous_renderer
|
23
23
|
end
|
data/lib/gem/ruby2html/render.rb
CHANGED
@@ -17,9 +17,10 @@ module Ruby2html
|
|
17
17
|
|
18
18
|
VOID_ELEMENTS = %w[area base br col embed hr img input link meta param source track wbr].freeze
|
19
19
|
|
20
|
-
COMMON_RAILS_METHOD_HELPERS = %w[
|
20
|
+
COMMON_RAILS_METHOD_HELPERS = %w[link_to image_tag form_with button_to].freeze
|
21
21
|
|
22
22
|
attr_reader :output
|
23
|
+
attr_accessor :current_output
|
23
24
|
|
24
25
|
def initialize(context, &root)
|
25
26
|
@context = context
|
@@ -28,14 +29,14 @@ module Ruby2html
|
|
28
29
|
@current_output = @output
|
29
30
|
end
|
30
31
|
|
31
|
-
def
|
32
|
+
def __render_from_rails(template_path)
|
32
33
|
result = render
|
33
34
|
return result unless annotate_rendered_view_with_filenames?
|
34
35
|
|
35
36
|
template_path = template_path.sub("#{Rails.root}/", '')
|
36
37
|
|
37
38
|
"<!-- BEGIN #{template_path} -->#{result}<!-- END #{template_path} -->".html_safe
|
38
|
-
end
|
39
|
+
end if defined?(ActionView)
|
39
40
|
|
40
41
|
def render(*args, **options, &block)
|
41
42
|
set_instance_variables
|
@@ -45,9 +46,8 @@ module Ruby2html
|
|
45
46
|
end
|
46
47
|
instance_exec(&@root)
|
47
48
|
result = @output.string
|
48
|
-
|
49
|
-
|
50
|
-
end
|
49
|
+
|
50
|
+
result = ActiveSupport::SafeBuffer.new(result) if defined?(ActiveSupport)
|
51
51
|
|
52
52
|
result
|
53
53
|
end
|
@@ -62,7 +62,7 @@ module Ruby2html
|
|
62
62
|
HTML5_TAGS.include?(method_name) || super
|
63
63
|
end
|
64
64
|
|
65
|
-
def html!(name, *args, **options
|
65
|
+
def html!(name, *args, **options)
|
66
66
|
content = args.first.is_a?(String) ? args.shift : nil
|
67
67
|
attributes = options
|
68
68
|
|
@@ -121,8 +121,9 @@ module Ruby2html
|
|
121
121
|
end
|
122
122
|
|
123
123
|
COMMON_RAILS_METHOD_HELPERS.each do |method|
|
124
|
-
define_method(method) do |*args, &block|
|
125
|
-
|
124
|
+
define_method(method) do |*args, **options, &block|
|
125
|
+
constant = "Ruby2html::RailsComponents::#{method.to_s.camelize}".constantize
|
126
|
+
constant.new(self, @context, method, *args, **options).render(&block)
|
126
127
|
end
|
127
128
|
end if defined?(ActionView)
|
128
129
|
|
@@ -130,7 +131,7 @@ module Ruby2html
|
|
130
131
|
return '' if attributes.empty?
|
131
132
|
|
132
133
|
result = StringIO.new
|
133
|
-
attributes.each do |k, v|
|
134
|
+
attributes.compact.each do |k, v|
|
134
135
|
result << ' '
|
135
136
|
result << k.to_s
|
136
137
|
result << '="'
|
metadata
CHANGED
@@ -1,15 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby2html
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.5.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-
|
12
|
-
dependencies:
|
11
|
+
date: 2024-08-12 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: htmlbeautifier
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.4'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.4'
|
13
27
|
description: Ruby2HTML empowers developers to write view logic in pure Ruby, seamlessly
|
14
28
|
converting it into clean, well-formatted HTML. Enhance your templating workflow,
|
15
29
|
improve readability, and leverage the full power of Ruby in your views. Features
|
@@ -82,6 +96,7 @@ files:
|
|
82
96
|
- lib/assets/.keep
|
83
97
|
- lib/gem/ruby2html.rb
|
84
98
|
- lib/gem/ruby2html/component_helper.rb
|
99
|
+
- lib/gem/ruby2html/html_beautifier_middleware.rb
|
85
100
|
- lib/gem/ruby2html/rails_helper.rb
|
86
101
|
- lib/gem/ruby2html/railtie.rb
|
87
102
|
- lib/gem/ruby2html/render.rb
|