ruby2html 1.0.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.
Files changed (74) hide show
  1. checksums.yaml +7 -0
  2. data/.dockerignore +48 -0
  3. data/.rspec +2 -0
  4. data/.rubocop.yml +13 -0
  5. data/.ruby-version +1 -0
  6. data/Dockerfile +71 -0
  7. data/README.md +264 -0
  8. data/Rakefile +8 -0
  9. data/app/assets/config/manifest.js +2 -0
  10. data/app/assets/images/.keep +0 -0
  11. data/app/assets/stylesheets/application.css +15 -0
  12. data/app/channels/application_cable/channel.rb +6 -0
  13. data/app/channels/application_cable/connection.rb +6 -0
  14. data/app/components/application_component.rb +5 -0
  15. data/app/components/first_component.html.erb +9 -0
  16. data/app/components/first_component.rb +7 -0
  17. data/app/components/second_component.rb +12 -0
  18. data/app/controllers/application_controller.rb +7 -0
  19. data/app/controllers/concerns/.keep +0 -0
  20. data/app/controllers/home_controller.rb +12 -0
  21. data/app/helpers/application_helper.rb +4 -0
  22. data/app/jobs/application_job.rb +9 -0
  23. data/app/mailers/application_mailer.rb +6 -0
  24. data/app/models/application_record.rb +5 -0
  25. data/app/models/concerns/.keep +0 -0
  26. data/app/views/home/index.html.erb +36 -0
  27. data/app/views/layouts/application.html.erb +22 -0
  28. data/app/views/layouts/mailer.html.erb +13 -0
  29. data/app/views/layouts/mailer.text.erb +1 -0
  30. data/app/views/pwa/manifest.json.erb +22 -0
  31. data/app/views/pwa/service-worker.js +26 -0
  32. data/app/views/shared/_navbar.html.erb +1 -0
  33. data/config/application.rb +45 -0
  34. data/config/boot.rb +6 -0
  35. data/config/cable.yml +10 -0
  36. data/config/credentials.yml.enc +1 -0
  37. data/config/database.yml +32 -0
  38. data/config/environment.rb +7 -0
  39. data/config/environments/development.rb +83 -0
  40. data/config/environments/production.rb +104 -0
  41. data/config/environments/test.rb +69 -0
  42. data/config/initializers/assets.rb +14 -0
  43. data/config/initializers/content_security_policy.rb +27 -0
  44. data/config/initializers/filter_parameter_logging.rb +10 -0
  45. data/config/initializers/inflections.rb +18 -0
  46. data/config/initializers/permissions_policy.rb +15 -0
  47. data/config/locales/en.yml +31 -0
  48. data/config/puma.rb +56 -0
  49. data/config/routes.rb +17 -0
  50. data/config/storage.yml +34 -0
  51. data/config.ru +8 -0
  52. data/db/seeds.rb +11 -0
  53. data/lefthook.yml +8 -0
  54. data/lib/assets/.keep +0 -0
  55. data/lib/gem/ruby2html/component_helper.rb +9 -0
  56. data/lib/gem/ruby2html/rails_helper.rb +13 -0
  57. data/lib/gem/ruby2html/render.rb +134 -0
  58. data/lib/gem/ruby2html/version.rb +5 -0
  59. data/lib/gem/ruby2html.rb +9 -0
  60. data/lib/tasks/.keep +0 -0
  61. data/log/.keep +0 -0
  62. data/public/404.html +67 -0
  63. data/public/406-unsupported-browser.html +66 -0
  64. data/public/422.html +67 -0
  65. data/public/500.html +66 -0
  66. data/public/icon.png +0 -0
  67. data/public/icon.svg +3 -0
  68. data/public/robots.txt +1 -0
  69. data/storage/.keep +0 -0
  70. data/tmp/.keep +0 -0
  71. data/tmp/pids/.keep +0 -0
  72. data/tmp/storage/.keep +0 -0
  73. data/vendor/.keep +0 -0
  74. metadata +120 -0
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Ruby2html
4
+ module ComponentHelper
5
+ def html(context, &block)
6
+ Ruby2html::Render.new(context, &block).render.html_safe
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Ruby2html
4
+ module RailsHelper
5
+ def html(context, &block)
6
+ Ruby2html::Render.new(context, &block).render.html_safe
7
+ end
8
+
9
+ def self.included(base)
10
+ base.helper_method :html
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,134 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'cgi'
4
+ require 'stringio'
5
+
6
+ module Ruby2html
7
+ class Render
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
17
+
18
+ VOID_ELEMENTS = %w[area base br col embed hr img input link meta param source track wbr].freeze
19
+
20
+ COMMON_RAILS_METHOD_HELPERS = %w[content_tag link_to image_tag form_tag form_for form_with form_with_model button_to].freeze
21
+
22
+ attr_reader :output
23
+
24
+ def initialize(context, &root)
25
+ @context = context
26
+ @root = root
27
+ @output = StringIO.new
28
+ @current_output = @output
29
+ end
30
+
31
+ def render(*args, **options, &block)
32
+ set_instance_variables
33
+
34
+ if !args.empty? || !options.empty? || block_given?
35
+ return plain @context.render(*args, **options, &block)
36
+ end
37
+ instance_exec(&@root)
38
+ @output.string
39
+ end
40
+
41
+ HTML5_TAGS.each do |tag|
42
+ define_method(tag) do |*args, &block|
43
+ html!(tag, *args, &block)
44
+ end
45
+ end
46
+
47
+ def html!(name, *args, &block)
48
+ attributes = args.first.is_a?(Hash) ? args.shift : {}
49
+ content = args.first.to_s
50
+ tag_content = StringIO.new
51
+ tag_content << '<'
52
+ tag_content << name
53
+ tag_content << attributes_to_s(attributes)
54
+
55
+ if VOID_ELEMENTS.include?(name)
56
+ tag_content << ' />'
57
+ else
58
+ tag_content << '>'
59
+
60
+ if block_given?
61
+ prev_output = @current_output
62
+ nested_content = StringIO.new
63
+ @current_output = nested_content
64
+ instance_exec(&block)
65
+ @current_output = prev_output
66
+ tag_content << nested_content.string
67
+ else
68
+ tag_content << escape_html(content)
69
+ end
70
+
71
+ tag_content << '</'
72
+ tag_content << name
73
+ tag_content << '>'
74
+ end
75
+
76
+ @current_output << tag_content.string
77
+ end
78
+
79
+ def plain(text)
80
+ if defined?(ActiveSupport) && (text.is_a?(ActiveSupport::SafeBuffer) || text.html_safe?)
81
+ @current_output << text
82
+ else
83
+ @current_output << escape_html(text.to_s)
84
+ end
85
+ end
86
+
87
+ def component(component_output)
88
+ @current_output << component_output
89
+ end
90
+
91
+ private
92
+ def method_missing(method_name, *args, &block)
93
+ if @context.respond_to?(method_name)
94
+ @context.send(method_name, *args, &block)
95
+ else
96
+ super
97
+ end
98
+ end
99
+
100
+ def respond_to_missing?(method_name, include_private = false)
101
+ @context.respond_to?(method_name) || super
102
+ end
103
+
104
+ COMMON_RAILS_METHOD_HELPERS.each do |method|
105
+ define_method(method) do |*args, &block|
106
+ plain @context.send(method, *args, &block)
107
+ end
108
+ end
109
+
110
+ def attributes_to_s(attributes)
111
+ return '' if attributes.empty?
112
+
113
+ result = StringIO.new
114
+ attributes.each do |k, v|
115
+ result << ' '
116
+ result << k.to_s
117
+ result << '="'
118
+ result << escape_html(v)
119
+ result << '"'
120
+ end
121
+ result.string
122
+ end
123
+
124
+ def escape_html(text)
125
+ CGI.escapeHTML(text.to_s)
126
+ end
127
+
128
+ def set_instance_variables
129
+ @context.instance_variables.each do |name|
130
+ instance_variable_set(name, @context.instance_variable_get(name))
131
+ end
132
+ end
133
+ end
134
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Ruby2html
4
+ VERSION = '1.0.0'
5
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ Dir.glob(File.join(File.dirname(__FILE__), 'ruby2html', '**', '*.rb')).each do |file|
4
+ require file
5
+ end
6
+
7
+ module Ruby2html
8
+ class Error < StandardError; end
9
+ end
data/lib/tasks/.keep ADDED
File without changes
data/log/.keep ADDED
File without changes
data/public/404.html ADDED
@@ -0,0 +1,67 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>The page you were looking for doesn't exist (404)</title>
5
+ <meta name="viewport" content="width=device-width,initial-scale=1">
6
+ <style>
7
+ .rails-default-error-page {
8
+ background-color: #EFEFEF;
9
+ color: #2E2F30;
10
+ text-align: center;
11
+ font-family: arial, sans-serif;
12
+ margin: 0;
13
+ }
14
+
15
+ .rails-default-error-page div.dialog {
16
+ width: 95%;
17
+ max-width: 33em;
18
+ margin: 4em auto 0;
19
+ }
20
+
21
+ .rails-default-error-page div.dialog > div {
22
+ border: 1px solid #CCC;
23
+ border-right-color: #999;
24
+ border-left-color: #999;
25
+ border-bottom-color: #BBB;
26
+ border-top: #B00100 solid 4px;
27
+ border-top-left-radius: 9px;
28
+ border-top-right-radius: 9px;
29
+ background-color: white;
30
+ padding: 7px 12% 0;
31
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
32
+ }
33
+
34
+ .rails-default-error-page h1 {
35
+ font-size: 100%;
36
+ color: #730E15;
37
+ line-height: 1.5em;
38
+ }
39
+
40
+ .rails-default-error-page div.dialog > p {
41
+ margin: 0 0 1em;
42
+ padding: 1em;
43
+ background-color: #F7F7F7;
44
+ border: 1px solid #CCC;
45
+ border-right-color: #999;
46
+ border-left-color: #999;
47
+ border-bottom-color: #999;
48
+ border-bottom-left-radius: 4px;
49
+ border-bottom-right-radius: 4px;
50
+ border-top-color: #DADADA;
51
+ color: #666;
52
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
53
+ }
54
+ </style>
55
+ </head>
56
+
57
+ <body class="rails-default-error-page">
58
+ <!-- This file lives in public/404.html -->
59
+ <div class="dialog">
60
+ <div>
61
+ <h1>The page you were looking for doesn't exist.</h1>
62
+ <p>You may have mistyped the address or the page may have moved.</p>
63
+ </div>
64
+ <p>If you are the application owner check the logs for more information.</p>
65
+ </div>
66
+ </body>
67
+ </html>
@@ -0,0 +1,66 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>Your browser is not supported (406)</title>
5
+ <meta name="viewport" content="width=device-width,initial-scale=1">
6
+ <style>
7
+ .rails-default-error-page {
8
+ background-color: #EFEFEF;
9
+ color: #2E2F30;
10
+ text-align: center;
11
+ font-family: arial, sans-serif;
12
+ margin: 0;
13
+ }
14
+
15
+ .rails-default-error-page div.dialog {
16
+ width: 95%;
17
+ max-width: 33em;
18
+ margin: 4em auto 0;
19
+ }
20
+
21
+ .rails-default-error-page div.dialog > div {
22
+ border: 1px solid #CCC;
23
+ border-right-color: #999;
24
+ border-left-color: #999;
25
+ border-bottom-color: #BBB;
26
+ border-top: #B00100 solid 4px;
27
+ border-top-left-radius: 9px;
28
+ border-top-right-radius: 9px;
29
+ background-color: white;
30
+ padding: 7px 12% 0;
31
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
32
+ }
33
+
34
+ .rails-default-error-page h1 {
35
+ font-size: 100%;
36
+ color: #730E15;
37
+ line-height: 1.5em;
38
+ }
39
+
40
+ .rails-default-error-page div.dialog > p {
41
+ margin: 0 0 1em;
42
+ padding: 1em;
43
+ background-color: #F7F7F7;
44
+ border: 1px solid #CCC;
45
+ border-right-color: #999;
46
+ border-left-color: #999;
47
+ border-bottom-color: #999;
48
+ border-bottom-left-radius: 4px;
49
+ border-bottom-right-radius: 4px;
50
+ border-top-color: #DADADA;
51
+ color: #666;
52
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
53
+ }
54
+ </style>
55
+ </head>
56
+
57
+ <body class="rails-default-error-page">
58
+ <!-- This file lives in public/406-unsupported-browser.html -->
59
+ <div class="dialog">
60
+ <div>
61
+ <h1>Your browser is not supported.</h1>
62
+ <p>Please upgrade your browser to continue.</p>
63
+ </div>
64
+ </div>
65
+ </body>
66
+ </html>
data/public/422.html ADDED
@@ -0,0 +1,67 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>The change you wanted was rejected (422)</title>
5
+ <meta name="viewport" content="width=device-width,initial-scale=1">
6
+ <style>
7
+ .rails-default-error-page {
8
+ background-color: #EFEFEF;
9
+ color: #2E2F30;
10
+ text-align: center;
11
+ font-family: arial, sans-serif;
12
+ margin: 0;
13
+ }
14
+
15
+ .rails-default-error-page div.dialog {
16
+ width: 95%;
17
+ max-width: 33em;
18
+ margin: 4em auto 0;
19
+ }
20
+
21
+ .rails-default-error-page div.dialog > div {
22
+ border: 1px solid #CCC;
23
+ border-right-color: #999;
24
+ border-left-color: #999;
25
+ border-bottom-color: #BBB;
26
+ border-top: #B00100 solid 4px;
27
+ border-top-left-radius: 9px;
28
+ border-top-right-radius: 9px;
29
+ background-color: white;
30
+ padding: 7px 12% 0;
31
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
32
+ }
33
+
34
+ .rails-default-error-page h1 {
35
+ font-size: 100%;
36
+ color: #730E15;
37
+ line-height: 1.5em;
38
+ }
39
+
40
+ .rails-default-error-page div.dialog > p {
41
+ margin: 0 0 1em;
42
+ padding: 1em;
43
+ background-color: #F7F7F7;
44
+ border: 1px solid #CCC;
45
+ border-right-color: #999;
46
+ border-left-color: #999;
47
+ border-bottom-color: #999;
48
+ border-bottom-left-radius: 4px;
49
+ border-bottom-right-radius: 4px;
50
+ border-top-color: #DADADA;
51
+ color: #666;
52
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
53
+ }
54
+ </style>
55
+ </head>
56
+
57
+ <body class="rails-default-error-page">
58
+ <!-- This file lives in public/422.html -->
59
+ <div class="dialog">
60
+ <div>
61
+ <h1>The change you wanted was rejected.</h1>
62
+ <p>Maybe you tried to change something you didn't have access to.</p>
63
+ </div>
64
+ <p>If you are the application owner check the logs for more information.</p>
65
+ </div>
66
+ </body>
67
+ </html>
data/public/500.html ADDED
@@ -0,0 +1,66 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>We're sorry, but something went wrong (500)</title>
5
+ <meta name="viewport" content="width=device-width,initial-scale=1">
6
+ <style>
7
+ .rails-default-error-page {
8
+ background-color: #EFEFEF;
9
+ color: #2E2F30;
10
+ text-align: center;
11
+ font-family: arial, sans-serif;
12
+ margin: 0;
13
+ }
14
+
15
+ .rails-default-error-page div.dialog {
16
+ width: 95%;
17
+ max-width: 33em;
18
+ margin: 4em auto 0;
19
+ }
20
+
21
+ .rails-default-error-page div.dialog > div {
22
+ border: 1px solid #CCC;
23
+ border-right-color: #999;
24
+ border-left-color: #999;
25
+ border-bottom-color: #BBB;
26
+ border-top: #B00100 solid 4px;
27
+ border-top-left-radius: 9px;
28
+ border-top-right-radius: 9px;
29
+ background-color: white;
30
+ padding: 7px 12% 0;
31
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
32
+ }
33
+
34
+ .rails-default-error-page h1 {
35
+ font-size: 100%;
36
+ color: #730E15;
37
+ line-height: 1.5em;
38
+ }
39
+
40
+ .rails-default-error-page div.dialog > p {
41
+ margin: 0 0 1em;
42
+ padding: 1em;
43
+ background-color: #F7F7F7;
44
+ border: 1px solid #CCC;
45
+ border-right-color: #999;
46
+ border-left-color: #999;
47
+ border-bottom-color: #999;
48
+ border-bottom-left-radius: 4px;
49
+ border-bottom-right-radius: 4px;
50
+ border-top-color: #DADADA;
51
+ color: #666;
52
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
53
+ }
54
+ </style>
55
+ </head>
56
+
57
+ <body class="rails-default-error-page">
58
+ <!-- This file lives in public/500.html -->
59
+ <div class="dialog">
60
+ <div>
61
+ <h1>We're sorry, but something went wrong.</h1>
62
+ </div>
63
+ <p>If you are the application owner check the logs for more information.</p>
64
+ </div>
65
+ </body>
66
+ </html>
data/public/icon.png ADDED
Binary file
data/public/icon.svg ADDED
@@ -0,0 +1,3 @@
1
+ <svg width="100" height="100" xmlns="http://www.w3.org/2000/svg">
2
+ <rect width="100%" height="100%" fill="red"/>
3
+ </svg>
data/public/robots.txt ADDED
@@ -0,0 +1 @@
1
+ # See https://www.robotstxt.org/robotstxt.html for documentation on how to use the robots.txt file
data/storage/.keep ADDED
File without changes
data/tmp/.keep ADDED
File without changes
data/tmp/pids/.keep ADDED
File without changes
data/tmp/storage/.keep ADDED
File without changes
data/vendor/.keep ADDED
File without changes
metadata ADDED
@@ -0,0 +1,120 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ruby2html
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - sebi
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2024-08-08 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Ruby2HTML empowers developers to write view logic in pure Ruby, seamlessly
14
+ converting it into clean, well-formatted HTML. Enhance your templating workflow,
15
+ improve readability, and leverage the full power of Ruby in your views. Features
16
+ include Rails integration, custom component support, and automatic HTML beautification.
17
+ email:
18
+ - gore.sebyx@yahoo.com
19
+ executables: []
20
+ extensions: []
21
+ extra_rdoc_files: []
22
+ files:
23
+ - ".dockerignore"
24
+ - ".rspec"
25
+ - ".rubocop.yml"
26
+ - ".ruby-version"
27
+ - Dockerfile
28
+ - README.md
29
+ - Rakefile
30
+ - app/assets/config/manifest.js
31
+ - app/assets/images/.keep
32
+ - app/assets/stylesheets/application.css
33
+ - app/channels/application_cable/channel.rb
34
+ - app/channels/application_cable/connection.rb
35
+ - app/components/application_component.rb
36
+ - app/components/first_component.html.erb
37
+ - app/components/first_component.rb
38
+ - app/components/second_component.rb
39
+ - app/controllers/application_controller.rb
40
+ - app/controllers/concerns/.keep
41
+ - app/controllers/home_controller.rb
42
+ - app/helpers/application_helper.rb
43
+ - app/jobs/application_job.rb
44
+ - app/mailers/application_mailer.rb
45
+ - app/models/application_record.rb
46
+ - app/models/concerns/.keep
47
+ - app/views/home/index.html.erb
48
+ - app/views/layouts/application.html.erb
49
+ - app/views/layouts/mailer.html.erb
50
+ - app/views/layouts/mailer.text.erb
51
+ - app/views/pwa/manifest.json.erb
52
+ - app/views/pwa/service-worker.js
53
+ - app/views/shared/_navbar.html.erb
54
+ - config.ru
55
+ - config/application.rb
56
+ - config/boot.rb
57
+ - config/cable.yml
58
+ - config/credentials.yml.enc
59
+ - config/database.yml
60
+ - config/environment.rb
61
+ - config/environments/development.rb
62
+ - config/environments/production.rb
63
+ - config/environments/test.rb
64
+ - config/initializers/assets.rb
65
+ - config/initializers/content_security_policy.rb
66
+ - config/initializers/filter_parameter_logging.rb
67
+ - config/initializers/inflections.rb
68
+ - config/initializers/permissions_policy.rb
69
+ - config/locales/en.yml
70
+ - config/puma.rb
71
+ - config/routes.rb
72
+ - config/storage.yml
73
+ - db/seeds.rb
74
+ - lefthook.yml
75
+ - lib/assets/.keep
76
+ - lib/gem/ruby2html.rb
77
+ - lib/gem/ruby2html/component_helper.rb
78
+ - lib/gem/ruby2html/rails_helper.rb
79
+ - lib/gem/ruby2html/render.rb
80
+ - lib/gem/ruby2html/version.rb
81
+ - lib/tasks/.keep
82
+ - log/.keep
83
+ - public/404.html
84
+ - public/406-unsupported-browser.html
85
+ - public/422.html
86
+ - public/500.html
87
+ - public/icon.png
88
+ - public/icon.svg
89
+ - public/robots.txt
90
+ - storage/.keep
91
+ - tmp/.keep
92
+ - tmp/pids/.keep
93
+ - tmp/storage/.keep
94
+ - vendor/.keep
95
+ homepage: https://github.com/sebyx07/ruby2html
96
+ licenses:
97
+ - MIT
98
+ metadata:
99
+ homepage_uri: https://github.com/sebyx07/ruby2html
100
+ source_code_uri: https://github.com/sebyx07/ruby2html
101
+ post_install_message:
102
+ rdoc_options: []
103
+ require_paths:
104
+ - lib/gem
105
+ required_ruby_version: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - ">="
108
+ - !ruby/object:Gem::Version
109
+ version: 3.0.0
110
+ required_rubygems_version: !ruby/object:Gem::Requirement
111
+ requirements:
112
+ - - ">="
113
+ - !ruby/object:Gem::Version
114
+ version: '0'
115
+ requirements: []
116
+ rubygems_version: 3.5.11
117
+ signing_key:
118
+ specification_version: 4
119
+ summary: Transform Ruby code into beautiful, structured HTML
120
+ test_files: []