ruby2html 1.3.2 → 1.4.0

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: 948558903cc3a21baf43c8d7a8133d8cf630476d9030a10b38646ce5e92535f7
4
- data.tar.gz: 769e3aad923a153b0aabf4392492bd44d0f231e784f5b5fffa9129329537b590
3
+ metadata.gz: e39b469662602b3df3e2444c58474a8c412a90d3556de30c5d404e41f4358eb8
4
+ data.tar.gz: dbd03a556e2deebf9d795065de00768259c21dc76d9d248a1a6799c80faa5434
5
5
  SHA512:
6
- metadata.gz: 77a22c5c896f3cfae2986a279a8946478ff39bd94e68faddb32ee897156d6cc9bbd6c4024fbce7463cd2f37b78905e6fd4e9c4410267589d743b33141f5de9ad
7
- data.tar.gz: 7561cabe35deeae6ff40d0b2b692d9fc153b34145ea95920b2e1c9c63895f71d45b473506646bfe8f456905c34c9dbacf35e4547033b05a60d9d69fdfc285cef
6
+ metadata.gz: edc9f77f24cdcc0cedd73f42750989abf6edf4df55ff40114d2543b2e895fa338caadbe9cea0e99f46a4b2f8c32ef42997e543a7e309ed8781181240e12d05e9
7
+ data.tar.gz: dbc116c78d40ce02a5ce228993e8803ad3afd64d43aabc543a1aa4ec407c4fa93b5d1192d9268f832b6a86bbe313e5df2faa878f0e1ec951a1741c0d3dd8f792
data/README.md CHANGED
@@ -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
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
@@ -6,6 +6,10 @@ class FirstComponent < ApplicationComponent
6
6
  end
7
7
 
8
8
  def another_div
9
+ div do
10
+ "Item value: #{@item}"
11
+ end
12
+
9
13
  div class: 'another' do
10
14
  h2 'Another subheading from component'
11
15
  end
@@ -1,3 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  h1 'Third component'
4
+ div do
5
+ "Item value: #{@item}"
6
+ end
@@ -2,9 +2,12 @@
2
2
 
3
3
  h1 'RbFiles'
4
4
  h1 'ok'
5
- h1 'ok'
5
+ h1 'okddwadwa'
6
6
 
7
7
  div @value
8
8
 
9
9
  link_to 'Home', root_url
10
10
  render partial: 'shared/navbar'
11
+ render partial: 'shared/footer'
12
+
13
+ div @value
@@ -0,0 +1,3 @@
1
+ # frozen_string_literal: true
2
+
3
+ h1 'footer'
@@ -80,4 +80,6 @@ Rails.application.configure do
80
80
 
81
81
  # Apply autocorrection by RuboCop to files generated by `bin/rails generate`.
82
82
  # config.generators.apply_rubocop_autocorrect_after_generate!
83
+
84
+ config.middleware.use Ruby2html::HtmlBeautifierMiddleware
83
85
  end
@@ -9,7 +9,7 @@ module Ruby2html
9
9
  new.call(template, source)
10
10
  end
11
11
 
12
- def call(_template, source)
12
+ def call(template, source)
13
13
  <<-RUBY
14
14
  begin
15
15
  previous_renderer = Thread.current[:__ruby2html_renderer__]
@@ -17,7 +17,7 @@ module Ruby2html
17
17
  #{source}
18
18
  end
19
19
  Thread.current[:__ruby2html_renderer__] = renderer
20
- renderer.render
20
+ renderer.render_from_rails(#{template.identifier.inspect})
21
21
  ensure
22
22
  Thread.current[:__ruby2html_renderer__] = previous_renderer
23
23
  end
@@ -28,6 +28,15 @@ module Ruby2html
28
28
  @current_output = @output
29
29
  end
30
30
 
31
+ def render_from_rails(template_path)
32
+ result = render
33
+ return result unless annotate_rendered_view_with_filenames?
34
+
35
+ template_path = template_path.sub("#{Rails.root}/", '')
36
+
37
+ "<!-- BEGIN #{template_path} -->#{result}<!-- END #{template_path} -->".html_safe
38
+ end
39
+
31
40
  def render(*args, **options, &block)
32
41
  set_instance_variables
33
42
 
@@ -135,6 +144,11 @@ module Ruby2html
135
144
  CGI.escapeHTML(text.to_s)
136
145
  end
137
146
 
147
+ def annotate_rendered_view_with_filenames?
148
+ return @annotate_rendered_view_with_filenames if defined?(@annotate_rendered_view_with_filenames)
149
+ @annotate_rendered_view_with_filenames = Rails.application.config.action_view.annotate_rendered_view_with_filenames
150
+ end
151
+
138
152
  def set_instance_variables
139
153
  @context.instance_variables.each do |name|
140
154
  instance_variable_set(name, @context.instance_variable_get(name))
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Ruby2html
4
- VERSION = '1.3.2'
4
+ VERSION = '1.4.0'
5
5
  end
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.3.2
4
+ version: 1.4.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-09 00:00:00.000000000 Z
12
- dependencies: []
11
+ date: 2024-08-10 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
@@ -56,6 +70,7 @@ files:
56
70
  - app/views/layouts/mailer.text.erb
57
71
  - app/views/pwa/manifest.json.erb
58
72
  - app/views/pwa/service-worker.js
73
+ - app/views/shared/_footer.html.rb
59
74
  - app/views/shared/_navbar.html.erb
60
75
  - config.ru
61
76
  - config/application.rb