webamm_to_rails 7.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 (193) hide show
  1. checksums.yaml +7 -0
  2. data/README.md +3 -0
  3. data/lib/webamm_to_rails/features/definitions.rb +19 -0
  4. data/lib/webamm_to_rails/features/devise_onlineable/definition.rb +44 -0
  5. data/lib/webamm_to_rails/features/devise_onlineable/definitions/connection/presenter.rb +29 -0
  6. data/lib/webamm_to_rails/features/devise_onlineable/definitions/connection/template.erb +17 -0
  7. data/lib/webamm_to_rails/features/devise_onlineable/templates/app/channels/online_channel.rb.erb +13 -0
  8. data/lib/webamm_to_rails/features/devise_onlineable/templates/app/javascript/channels/consumer.js.erb +6 -0
  9. data/lib/webamm_to_rails/features/devise_onlineable/templates/app/javascript/channels/index.js.erb +5 -0
  10. data/lib/webamm_to_rails/features/devise_onlineable/templates/app/javascript/channels/online_channel.js.erb +48 -0
  11. data/lib/webamm_to_rails/features/devise_onlineable/templates/app/models/concerns/devise_onlineable.rb.erb +39 -0
  12. data/lib/webamm_to_rails/rails_boilerplate/builder.rb +318 -0
  13. data/lib/webamm_to_rails/rails_boilerplate/templates/Dockerfile.erb +83 -0
  14. data/lib/webamm_to_rails/rails_boilerplate/templates/Procfile.dev.erb +3 -0
  15. data/lib/webamm_to_rails/rails_boilerplate/templates/README.md.erb +24 -0
  16. data/lib/webamm_to_rails/rails_boilerplate/templates/Rakefile.erb +6 -0
  17. data/lib/webamm_to_rails/rails_boilerplate/templates/app/assets/config/manifest.js.erb +2 -0
  18. data/lib/webamm_to_rails/rails_boilerplate/templates/app/assets/stylesheets/application.tailwind.css.erb +3 -0
  19. data/lib/webamm_to_rails/rails_boilerplate/templates/app/channels/application_cable/channel.rb.erb +4 -0
  20. data/lib/webamm_to_rails/rails_boilerplate/templates/app/channels/application_cable/connection.rb.erb +4 -0
  21. data/lib/webamm_to_rails/rails_boilerplate/templates/app/helpers/application_helper.rb.erb +2 -0
  22. data/lib/webamm_to_rails/rails_boilerplate/templates/app/javascript/application.js.erb +3 -0
  23. data/lib/webamm_to_rails/rails_boilerplate/templates/app/javascript/controllers/application.js.erb +9 -0
  24. data/lib/webamm_to_rails/rails_boilerplate/templates/app/javascript/controllers/hello_controller.js.erb +7 -0
  25. data/lib/webamm_to_rails/rails_boilerplate/templates/app/javascript/controllers/index.js.erb +8 -0
  26. data/lib/webamm_to_rails/rails_boilerplate/templates/app/jobs/application_job.rb.erb +7 -0
  27. data/lib/webamm_to_rails/rails_boilerplate/templates/app/mailers/application_mailer.rb.erb +4 -0
  28. data/lib/webamm_to_rails/rails_boilerplate/templates/app/models/application_record.rb.erb +3 -0
  29. data/lib/webamm_to_rails/rails_boilerplate/templates/app/views/layouts/application.html.erb +44 -0
  30. data/lib/webamm_to_rails/rails_boilerplate/templates/app/views/layouts/mailer.html.erb +13 -0
  31. data/lib/webamm_to_rails/rails_boilerplate/templates/app/views/layouts/mailer.text.erb +1 -0
  32. data/lib/webamm_to_rails/rails_boilerplate/templates/app/views/pwa/manifest.json.erb +22 -0
  33. data/lib/webamm_to_rails/rails_boilerplate/templates/app/views/pwa/service-worker.js.erb +26 -0
  34. data/lib/webamm_to_rails/rails_boilerplate/templates/bin/brakeman.erb +7 -0
  35. data/lib/webamm_to_rails/rails_boilerplate/templates/bin/bundle.erb +109 -0
  36. data/lib/webamm_to_rails/rails_boilerplate/templates/bin/dev.erb +11 -0
  37. data/lib/webamm_to_rails/rails_boilerplate/templates/bin/docker-entrypoint.erb +13 -0
  38. data/lib/webamm_to_rails/rails_boilerplate/templates/bin/rails.erb +4 -0
  39. data/lib/webamm_to_rails/rails_boilerplate/templates/bin/rake.erb +4 -0
  40. data/lib/webamm_to_rails/rails_boilerplate/templates/bin/rubocop.erb +8 -0
  41. data/lib/webamm_to_rails/rails_boilerplate/templates/bin/setup.erb +40 -0
  42. data/lib/webamm_to_rails/rails_boilerplate/templates/config/application.rb.erb +42 -0
  43. data/lib/webamm_to_rails/rails_boilerplate/templates/config/boot.rb.erb +4 -0
  44. data/lib/webamm_to_rails/rails_boilerplate/templates/config/cable.yml.erb +11 -0
  45. data/lib/webamm_to_rails/rails_boilerplate/templates/config/credentials.yml.enc.erb +1 -0
  46. data/lib/webamm_to_rails/rails_boilerplate/templates/config/database.yml.erb +85 -0
  47. data/lib/webamm_to_rails/rails_boilerplate/templates/config/environment.rb.erb +5 -0
  48. data/lib/webamm_to_rails/rails_boilerplate/templates/config/environments/development.rb.erb +84 -0
  49. data/lib/webamm_to_rails/rails_boilerplate/templates/config/environments/production.rb.erb +102 -0
  50. data/lib/webamm_to_rails/rails_boilerplate/templates/config/environments/test.rb.erb +67 -0
  51. data/lib/webamm_to_rails/rails_boilerplate/templates/config/initializers/assets.rb.erb +12 -0
  52. data/lib/webamm_to_rails/rails_boilerplate/templates/config/initializers/content_security_policy.rb.erb +25 -0
  53. data/lib/webamm_to_rails/rails_boilerplate/templates/config/initializers/filter_parameter_logging.rb.erb +8 -0
  54. data/lib/webamm_to_rails/rails_boilerplate/templates/config/initializers/inflections.rb.erb +16 -0
  55. data/lib/webamm_to_rails/rails_boilerplate/templates/config/initializers/permissions_policy.rb.erb +13 -0
  56. data/lib/webamm_to_rails/rails_boilerplate/templates/config/locales/en.yml.erb +31 -0
  57. data/lib/webamm_to_rails/rails_boilerplate/templates/config/master.key.erb +1 -0
  58. data/lib/webamm_to_rails/rails_boilerplate/templates/config/puma.rb.erb +33 -0
  59. data/lib/webamm_to_rails/rails_boilerplate/templates/config/storage.yml.erb +34 -0
  60. data/lib/webamm_to_rails/rails_boilerplate/templates/config.ru.erb +6 -0
  61. data/lib/webamm_to_rails/rails_boilerplate/templates/db/seeds.rb.erb +9 -0
  62. data/lib/webamm_to_rails/rails_boilerplate/templates/dockerignore.erb +48 -0
  63. data/lib/webamm_to_rails/rails_boilerplate/templates/gitattributes.erb +9 -0
  64. data/lib/webamm_to_rails/rails_boilerplate/templates/github/dependabot.yml.erb +0 -0
  65. data/lib/webamm_to_rails/rails_boilerplate/templates/github/workflows/ci.yml.erb +38 -0
  66. data/lib/webamm_to_rails/rails_boilerplate/templates/gitignore.erb +40 -0
  67. data/lib/webamm_to_rails/rails_boilerplate/templates/node-version.erb +1 -0
  68. data/lib/webamm_to_rails/rails_boilerplate/templates/public/404.html.erb +67 -0
  69. data/lib/webamm_to_rails/rails_boilerplate/templates/public/406-unsupported-browser.html.erb +66 -0
  70. data/lib/webamm_to_rails/rails_boilerplate/templates/public/422.html.erb +67 -0
  71. data/lib/webamm_to_rails/rails_boilerplate/templates/public/500.html.erb +66 -0
  72. data/lib/webamm_to_rails/rails_boilerplate/templates/public/icon.png.erb +0 -0
  73. data/lib/webamm_to_rails/rails_boilerplate/templates/public/icon.svg.erb +3 -0
  74. data/lib/webamm_to_rails/rails_boilerplate/templates/public/robots.txt.erb +1 -0
  75. data/lib/webamm_to_rails/rails_boilerplate/templates/rubocop.yml.erb +8 -0
  76. data/lib/webamm_to_rails/rails_boilerplate/templates/ruby-version.erb +1 -0
  77. data/lib/webamm_to_rails/rails_boilerplate/templates/tailwind.config.js.erb +8 -0
  78. data/lib/webamm_to_rails/sources/controllers/actions/create_definition/presenter.rb +50 -0
  79. data/lib/webamm_to_rails/sources/controllers/actions/create_definition/template.erb +9 -0
  80. data/lib/webamm_to_rails/sources/controllers/actions/definition.rb +66 -0
  81. data/lib/webamm_to_rails/sources/controllers/actions/destroy_definition/presenter.rb +52 -0
  82. data/lib/webamm_to_rails/sources/controllers/actions/destroy_definition/template.erb +6 -0
  83. data/lib/webamm_to_rails/sources/controllers/actions/edit_definition/presenter.rb +40 -0
  84. data/lib/webamm_to_rails/sources/controllers/actions/edit_definition/template.erb +3 -0
  85. data/lib/webamm_to_rails/sources/controllers/actions/index_definition/presenter.rb +40 -0
  86. data/lib/webamm_to_rails/sources/controllers/actions/index_definition/template.erb +3 -0
  87. data/lib/webamm_to_rails/sources/controllers/actions/new_definition/presenter.rb +40 -0
  88. data/lib/webamm_to_rails/sources/controllers/actions/new_definition/template.erb +3 -0
  89. data/lib/webamm_to_rails/sources/controllers/actions/show_definition/presenter.rb +40 -0
  90. data/lib/webamm_to_rails/sources/controllers/actions/show_definition/template.erb +3 -0
  91. data/lib/webamm_to_rails/sources/controllers/actions/strong_parameters_definition/presenter.rb +50 -0
  92. data/lib/webamm_to_rails/sources/controllers/actions/strong_parameters_definition/template.erb +3 -0
  93. data/lib/webamm_to_rails/sources/controllers/actions/update_definition/presenter.rb +54 -0
  94. data/lib/webamm_to_rails/sources/controllers/actions/update_definition/template.erb +9 -0
  95. data/lib/webamm_to_rails/sources/controllers/application_controller/authentication/devise_groups/presenter.rb +49 -0
  96. data/lib/webamm_to_rails/sources/controllers/application_controller/authentication/devise_groups_definition/presenter.rb +30 -0
  97. data/lib/webamm_to_rails/sources/controllers/application_controller/definition.rb +36 -0
  98. data/lib/webamm_to_rails/sources/controllers/application_controller/template.erb +5 -0
  99. data/lib/webamm_to_rails/sources/controllers/class_definition/presenter.rb +17 -0
  100. data/lib/webamm_to_rails/sources/controllers/definition.rb +44 -0
  101. data/lib/webamm_to_rails/sources/controllers/filters/definition.rb +32 -0
  102. data/lib/webamm_to_rails/sources/controllers/filters/devise_definition/presenter.rb +55 -0
  103. data/lib/webamm_to_rails/sources/controllers/template.erb +17 -0
  104. data/lib/webamm_to_rails/sources/gemfile/default_set.rb +27 -0
  105. data/lib/webamm_to_rails/sources/gemfile/definition.rb +31 -0
  106. data/lib/webamm_to_rails/sources/gemfile/gem.rb +8 -0
  107. data/lib/webamm_to_rails/sources/gemfile/gem_definition/presenter.rb +22 -0
  108. data/lib/webamm_to_rails/sources/gemfile/project_set.rb +21 -0
  109. data/lib/webamm_to_rails/sources/gemfile/sets/authentication.rb +34 -0
  110. data/lib/webamm_to_rails/sources/gemfile/template.erb +17 -0
  111. data/lib/webamm_to_rails/sources/helpers/definitions.rb +21 -0
  112. data/lib/webamm_to_rails/sources/helpers/devise/presenter.rb +27 -0
  113. data/lib/webamm_to_rails/sources/helpers/devise/qr_code_helper/presenter.rb +19 -0
  114. data/lib/webamm_to_rails/sources/helpers/devise/qr_code_helper/template.erb +22 -0
  115. data/lib/webamm_to_rails/sources/initializers/definitions.rb +26 -0
  116. data/lib/webamm_to_rails/sources/initializers/devise_definition/presenter.rb +27 -0
  117. data/lib/webamm_to_rails/sources/initializers/devise_definition/template.erb +397 -0
  118. data/lib/webamm_to_rails/sources/migrations/active_storage_definition/presenter.rb +29 -0
  119. data/lib/webamm_to_rails/sources/migrations/active_storage_definition/template.erb +57 -0
  120. data/lib/webamm_to_rails/sources/migrations/associations.rb +49 -0
  121. data/lib/webamm_to_rails/sources/migrations/class_definition/presenter.rb +17 -0
  122. data/lib/webamm_to_rails/sources/migrations/column_definition/presenter.rb +38 -0
  123. data/lib/webamm_to_rails/sources/migrations/columns.rb +33 -0
  124. data/lib/webamm_to_rails/sources/migrations/definition.rb +52 -0
  125. data/lib/webamm_to_rails/sources/migrations/devise/definition.rb +278 -0
  126. data/lib/webamm_to_rails/sources/migrations/files_list.rb +98 -0
  127. data/lib/webamm_to_rails/sources/migrations/index_definition/presenter.rb +34 -0
  128. data/lib/webamm_to_rails/sources/migrations/indices.rb +33 -0
  129. data/lib/webamm_to_rails/sources/migrations/table_definition/presenter.rb +21 -0
  130. data/lib/webamm_to_rails/sources/migrations/template.erb +12 -0
  131. data/lib/webamm_to_rails/sources/migrations/uuid_definition/presenter.rb +29 -0
  132. data/lib/webamm_to_rails/sources/migrations/uuid_definition/template.erb +5 -0
  133. data/lib/webamm_to_rails/sources/models/association_definition/presenter.rb +49 -0
  134. data/lib/webamm_to_rails/sources/models/associations.rb +113 -0
  135. data/lib/webamm_to_rails/sources/models/attachment_definition/presenter.rb +21 -0
  136. data/lib/webamm_to_rails/sources/models/attachments.rb +25 -0
  137. data/lib/webamm_to_rails/sources/models/class_definition/presenter.rb +17 -0
  138. data/lib/webamm_to_rails/sources/models/concerns.rb +27 -0
  139. data/lib/webamm_to_rails/sources/models/definition.rb +57 -0
  140. data/lib/webamm_to_rails/sources/models/devise_definition/presenter.rb +49 -0
  141. data/lib/webamm_to_rails/sources/models/enum_definition/presenter.rb +19 -0
  142. data/lib/webamm_to_rails/sources/models/enums.rb +25 -0
  143. data/lib/webamm_to_rails/sources/models/template.erb +7 -0
  144. data/lib/webamm_to_rails/sources/package_json/definition.rb +27 -0
  145. data/lib/webamm_to_rails/sources/package_json/template.erb +21 -0
  146. data/lib/webamm_to_rails/sources/routes/authentication_definition/presenter.rb +21 -0
  147. data/lib/webamm_to_rails/sources/routes/definition.rb +38 -0
  148. data/lib/webamm_to_rails/sources/routes/resource_definition/presenter.rb +25 -0
  149. data/lib/webamm_to_rails/sources/routes/template.erb +14 -0
  150. data/lib/webamm_to_rails/sources/views/definition.rb +28 -0
  151. data/lib/webamm_to_rails/sources/views/devise/invitable/presenter.rb +31 -0
  152. data/lib/webamm_to_rails/sources/views/devise/invitable/templates/invitations/edit.html.erb +38 -0
  153. data/lib/webamm_to_rails/sources/views/devise/invitable/templates/invitations/new.html.erb +31 -0
  154. data/lib/webamm_to_rails/sources/views/devise/invitable/templates/mailer/invitation_instructions.html.erb +23 -0
  155. data/lib/webamm_to_rails/sources/views/devise/otp/presenter.rb +32 -0
  156. data/lib/webamm_to_rails/sources/views/devise/otp/templates/otp_credentials/refresh.html.erb +19 -0
  157. data/lib/webamm_to_rails/sources/views/devise/otp/templates/otp_credentials/show.html.erb +70 -0
  158. data/lib/webamm_to_rails/sources/views/devise/otp/templates/otp_tokens/_token_secret.html.erb +21 -0
  159. data/lib/webamm_to_rails/sources/views/devise/otp/templates/otp_tokens/_trusted_devices.html.erb +12 -0
  160. data/lib/webamm_to_rails/sources/views/devise/otp/templates/otp_tokens/edit.html.erb +48 -0
  161. data/lib/webamm_to_rails/sources/views/devise/otp/templates/otp_tokens/recovery.html.erb +21 -0
  162. data/lib/webamm_to_rails/sources/views/devise/otp/templates/otp_tokens/recovery_codes.html.erb +3 -0
  163. data/lib/webamm_to_rails/sources/views/devise/otp/templates/otp_tokens/show.html.erb +21 -0
  164. data/lib/webamm_to_rails/sources/views/devise/presenter.rb +37 -0
  165. data/lib/webamm_to_rails/sources/views/devise/standard/presenter.rb +39 -0
  166. data/lib/webamm_to_rails/sources/views/devise/standard/templates/confirmations/new.html.erb +31 -0
  167. data/lib/webamm_to_rails/sources/views/devise/standard/templates/mailer/confirmation_instructions.html.erb +17 -0
  168. data/lib/webamm_to_rails/sources/views/devise/standard/templates/mailer/email_changed.html.erb +7 -0
  169. data/lib/webamm_to_rails/sources/views/devise/standard/templates/mailer/password_change.html.erb +3 -0
  170. data/lib/webamm_to_rails/sources/views/devise/standard/templates/mailer/reset_password_instructions.html.erb +22 -0
  171. data/lib/webamm_to_rails/sources/views/devise/standard/templates/passwords/edit.html.erb +36 -0
  172. data/lib/webamm_to_rails/sources/views/devise/standard/templates/passwords/new.html.erb +31 -0
  173. data/lib/webamm_to_rails/sources/views/devise/standard/templates/registrations/edit.html.erb +43 -0
  174. data/lib/webamm_to_rails/sources/views/devise/standard/templates/registrations/new.html.erb +39 -0
  175. data/lib/webamm_to_rails/sources/views/devise/standard/templates/sessions/new.html.erb +23 -0
  176. data/lib/webamm_to_rails/sources/views/devise/standard/templates/shared/_links.html.erb +27 -0
  177. data/lib/webamm_to_rails/sources/views/resource/edit_definition/presenter.rb +41 -0
  178. data/lib/webamm_to_rails/sources/views/resource/edit_definition/template.erb +1 -0
  179. data/lib/webamm_to_rails/sources/views/resource/form_definition/presenter.rb +50 -0
  180. data/lib/webamm_to_rails/sources/views/resource/form_definition/template.erb +82 -0
  181. data/lib/webamm_to_rails/sources/views/resource/index_definition/presenter.rb +69 -0
  182. data/lib/webamm_to_rails/sources/views/resource/index_definition/template.erb +78 -0
  183. data/lib/webamm_to_rails/sources/views/resource/new_definition/presenter.rb +41 -0
  184. data/lib/webamm_to_rails/sources/views/resource/new_definition/template.erb +1 -0
  185. data/lib/webamm_to_rails/sources/views/resource/presenter.rb +41 -0
  186. data/lib/webamm_to_rails/sources/views/resource/show_definition/presenter.rb +61 -0
  187. data/lib/webamm_to_rails/sources/views/resource/show_definition/template.erb +34 -0
  188. data/lib/webamm_to_rails/utils/format_code.rb +11 -0
  189. data/lib/webamm_to_rails/utils/format_template.rb +11 -0
  190. data/lib/webamm_to_rails/version.rb +5 -0
  191. data/lib/webamm_to_rails.rb +112 -0
  192. data/webamm_to_rails.gemspec +28 -0
  193. metadata +332 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 7fdd1ccfe0c4337456780dbccbc8b94490db3d43ec6fea627f14d9a03c408119
4
+ data.tar.gz: 5a2a3f70e63ca2302f47baa9c936b564016bae624df5d7924353c5173f14de14
5
+ SHA512:
6
+ metadata.gz: 2f1cd09012889fbfaa1734ed8d88d1e56bb07d157d780ad8f7dcabee41ca6d980e94e43781dbe1c90fa912d62d80381a6773bddbb523ec9266ff72d7f6448baa
7
+ data.tar.gz: d1e8c1008d6d854faf6a699b7b0c6314473c2e61373ddb2b66680874ca678a3b9b29841c4d3882be14385d083c38f28e9065202e74a91a13f4c56e8556b88132
data/README.md ADDED
@@ -0,0 +1,3 @@
1
+ # WEBAMM definition to Ruby on Rails code
2
+
3
+ Library to convert WEBAMM (Web Application Metadata Markup) definition to Ruby on Rails code.
@@ -0,0 +1,19 @@
1
+ require_relative 'devise_onlineable/definition'
2
+
3
+ module WebammToRails
4
+ module Features
5
+ class Definitions
6
+ def initialize(waml_definition:)
7
+ @waml_definition = waml_definition
8
+ end
9
+
10
+ def collection
11
+ features = []
12
+
13
+ features |= ::WebammToRails::Features::DeviseOnlineable::Definition.new(waml_definition: @waml_definition).collection
14
+
15
+ features
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,44 @@
1
+ require_relative 'definitions/connection/presenter'
2
+
3
+ module WebammToRails
4
+ module Features
5
+ module DeviseOnlineable
6
+ class Definition
7
+ def initialize(waml_definition:)
8
+ @waml_definition = waml_definition
9
+ end
10
+
11
+ def collection
12
+ return [] if @waml_definition.authentication.none? { |auth| auth.features.include?('online_indication') }
13
+
14
+ [
15
+ {
16
+ path: 'app/channels/application_cable/connection.rb',
17
+ content: ::WebammToRails::Features::DeviseOnlineable::Definitions::Connection::Presenter.new(waml_definition: @waml_definition).render
18
+ },
19
+ {
20
+ path: 'app/channels/online_channel.rb',
21
+ content: File.read(File.expand_path('templates/app/channels/online_channel.rb.erb', __dir__))
22
+ },
23
+ {
24
+ path: 'app/models/concerns/devise_onlineable.rb',
25
+ content: File.read(File.expand_path('templates/app/models/concerns/devise_onlineable.rb.erb', __dir__))
26
+ },
27
+ {
28
+ path: 'app/javascript/channels/consumer.js',
29
+ content: File.read(File.expand_path('templates/app/javascript/channels/consumer.js.erb', __dir__))
30
+ },
31
+ {
32
+ path: 'app/javascript/channels/index.js',
33
+ content: File.read(File.expand_path('templates/app/javascript/channels/index.js.erb', __dir__))
34
+ },
35
+ {
36
+ path: 'app/javascript/channels/online_channel.js',
37
+ content: File.read(File.expand_path('templates/app/javascript/channels/online_channel.js.erb', __dir__))
38
+ }
39
+ ]
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,29 @@
1
+ module WebammToRails
2
+ module Features
3
+ module DeviseOnlineable
4
+ module Definitions
5
+ module Connection
6
+ class Presenter
7
+ def initialize(waml_definition:)
8
+ @waml_definition = waml_definition
9
+ end
10
+
11
+ def render
12
+ template_path = File.expand_path('template.erb', __dir__)
13
+ template_content = File.read(template_path)
14
+ raw_content = ERB.new(template_content, trim_mode: '-').result(instance_eval { binding })
15
+
16
+ ::WebammToRails::Utils::FormatCode.call(raw_content)
17
+ end
18
+
19
+ private
20
+
21
+ def devise_models
22
+ @waml_definition.authentication.select { |auth| auth.features.include?('online_indication') }.map(&:table).map(&:singularize)
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ApplicationCable
4
+ class Connection < ActionCable::Connection::Base
5
+ identified_by :current_user
6
+
7
+ def connect
8
+ self.current_user = find_verified_user
9
+ end
10
+
11
+ private
12
+
13
+ def find_verified_user
14
+ <%= devise_models.map { |name| "env['warden'].user(:#{name.underscore})" }.join(" || ") %> || reject_unauthorized_connection
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,13 @@
1
+ class OnlineChannel < ApplicationCable::Channel
2
+ def subscribed
3
+ current_user.appear
4
+ end
5
+
6
+ def unsubscribed
7
+ current_user.disappear
8
+ end
9
+
10
+ def appear
11
+ current_user.appear
12
+ end
13
+ end
@@ -0,0 +1,6 @@
1
+ // Action Cable provides the framework to deal with WebSockets in Rails.
2
+ // You can generate new channels where WebSocket features live using the `rails generate channel` command.
3
+
4
+ import { createConsumer } from "@rails/actioncable"
5
+
6
+ export default createConsumer()
@@ -0,0 +1,5 @@
1
+ // Load all the channels within this directory and all subdirectories.
2
+ // Channel files must be named *_channel.js.
3
+
4
+ const channels = require.context('.', true, /_channel\.js$/)
5
+ channels.keys().forEach(channels)
@@ -0,0 +1,48 @@
1
+ import consumer from "./consumer"
2
+
3
+ consumer.subscriptions.create("OnlineChannel", {
4
+ initialized() {
5
+ this.update = this.update.bind(this)
6
+ },
7
+
8
+ connected() {
9
+ this.install()
10
+ this.update()
11
+ },
12
+
13
+ disconnected() {
14
+ this.uninstall()
15
+ },
16
+
17
+ rejected() {
18
+ this.uninstall()
19
+ },
20
+
21
+ update() {
22
+ if(this.documentIsActive) {
23
+ this.appear()
24
+ }
25
+ },
26
+
27
+ appear() {
28
+ this.perform("appear")
29
+ },
30
+
31
+ install() {
32
+ window.addEventListener("focus", this.update)
33
+ window.addEventListener("blur", this.update)
34
+ document.addEventListener("turbo:load", this.update)
35
+ document.addEventListener("visibilitychange", this.update)
36
+ },
37
+
38
+ uninstall() {
39
+ window.removeEventListener("focus", this.update)
40
+ window.removeEventListener("blur", this.update)
41
+ document.removeEventListener("turbo:load", this.update)
42
+ document.removeEventListener("visibilitychange", this.update)
43
+ },
44
+
45
+ get documentIsActive() {
46
+ return document.visibilityState === "visible" && document.hasFocus()
47
+ },
48
+ })
@@ -0,0 +1,39 @@
1
+ module DeviseOnlineable
2
+ extend ActiveSupport::Concern
3
+
4
+ def appear
5
+ redis_client.multi do |multi|
6
+ multi.set(online_status_key, 1)
7
+ multi.expire(online_status_key, 3_600)
8
+ multi.set("#{online_status_key}:last_seen", Time.zone.now.to_i)
9
+ multi.expire("#{online_status_key}:last_seen", 3_600)
10
+ end
11
+ end
12
+
13
+ def disappear
14
+ redis_client.multi do |multi|
15
+ multi.del(online_status_key)
16
+ multi.del("#{online_status_key}:last_seen")
17
+ end
18
+ end
19
+
20
+ def online_status
21
+ return :offline unless redis_client.exists?(online_status_key)
22
+
23
+ last_seen = redis_client.get("#{online_status_key}:last_seen").to_i
24
+
25
+ Time.zone.at(last_seen) > 5.minutes.ago ? :online : :away
26
+ end
27
+
28
+ private
29
+
30
+ def online_status_key
31
+ "#{self.class.to_s.underscore}_online_presence:#{id}"
32
+ end
33
+
34
+ def redis_client
35
+ @redis_client ||= Redis.new(
36
+ url: ENV.fetch('REDIS_URL') { 'redis://localhost:6379/1' }
37
+ )
38
+ end
39
+ end
@@ -0,0 +1,318 @@
1
+ module WebammToRails
2
+ module RailsBoilerplate
3
+ class Builder
4
+ def self.call
5
+ files = [
6
+ {
7
+ path: '.github/workflows/ci.yml',
8
+ content: File.read(File.expand_path('templates/github/workflows/ci.yml.erb', __dir__))
9
+ },
10
+ {
11
+ path: '.github/dependabot.yml',
12
+ content: File.read(File.expand_path('templates/github/dependabot.yml.erb', __dir__))
13
+ },
14
+ {
15
+ path: 'app/assets/builds/.keep',
16
+ content: ''
17
+ },
18
+ {
19
+ path: 'app/assets/config/manifest.js',
20
+ content: File.read(File.expand_path('templates/app/assets/config/manifest.js.erb', __dir__))
21
+ },
22
+ {
23
+ path: 'app/assets/images/.keep',
24
+ content: ''
25
+ },
26
+ {
27
+ path: 'app/assets/stylesheets/application.tailwind.css',
28
+ content: File.read(File.expand_path('templates/app/assets/stylesheets/application.tailwind.css.erb', __dir__))
29
+ },
30
+ {
31
+ path: 'app/channels/application_cable/channel.rb',
32
+ content: File.read(File.expand_path('templates/app/channels/application_cable/channel.rb.erb', __dir__))
33
+ },
34
+ {
35
+ path: 'app/channels/application_cable/connection.rb',
36
+ content: File.read(File.expand_path('templates/app/channels/application_cable/connection.rb.erb', __dir__))
37
+ },
38
+ {
39
+ path: 'app/controllers/concerns/.keep',
40
+ content: ''
41
+ },
42
+ {
43
+ path: 'app/helpers/application_helper.rb',
44
+ content: File.read(File.expand_path('templates/app/helpers/application_helper.rb.erb', __dir__))
45
+ },
46
+ {
47
+ path: 'app/javascript/application.js',
48
+ content: File.read(File.expand_path('templates/app/javascript/application.js.erb', __dir__))
49
+ },
50
+ {
51
+ path: 'app/javascript/controllers/index.js',
52
+ content: File.read(File.expand_path('templates/app/javascript/controllers/index.js.erb', __dir__))
53
+ },
54
+ {
55
+ path: 'app/javascript/controllers/application.js',
56
+ content: File.read(File.expand_path('templates/app/javascript/controllers/application.js.erb', __dir__))
57
+ },
58
+ {
59
+ path: 'app/javascript/controllers/hello_controller.js',
60
+ content: File.read(File.expand_path('templates/app/javascript/controllers/hello_controller.js.erb', __dir__))
61
+ },
62
+ {
63
+ path: 'app/jobs/application_job.rb',
64
+ content: File.read(File.expand_path('templates/app/jobs/application_job.rb.erb', __dir__))
65
+ },
66
+ {
67
+ path: 'app/mailers/application_mailer.rb',
68
+ content: File.read(File.expand_path('templates/app/mailers/application_mailer.rb.erb', __dir__))
69
+ },
70
+ {
71
+ path: 'app/models/application_record.rb',
72
+ content: File.read(File.expand_path('templates/app/models/application_record.rb.erb', __dir__))
73
+ },
74
+ {
75
+ path: 'app/models/concerns/.keep',
76
+ content: ''
77
+ },
78
+ {
79
+ path: 'app/models/application_record.rb',
80
+ content: File.read(File.expand_path('templates/app/models/application_record.rb.erb', __dir__))
81
+ },
82
+ {
83
+ path: 'app/views/layouts/application.html.erb',
84
+ content: File.read(File.expand_path('templates/app/views/layouts/application.html.erb', __dir__))
85
+ },
86
+ {
87
+ path: 'app/views/layouts/mailer.html.erb',
88
+ content: File.read(File.expand_path('templates/app/views/layouts/mailer.html.erb', __dir__))
89
+ },
90
+ {
91
+ path: 'app/views/layouts/mailer.text.erb',
92
+ content: File.read(File.expand_path('templates/app/views/layouts/mailer.text.erb', __dir__))
93
+ },
94
+ {
95
+ path: 'app/views/pwa/manifest.json.erb',
96
+ content: File.read(File.expand_path('templates/app/views/pwa/manifest.json.erb', __dir__))
97
+ },
98
+ {
99
+ path: 'app/views/pwa/service-worker.js',
100
+ content: File.read(File.expand_path('templates/app/views/pwa/service-worker.js.erb', __dir__))
101
+ },
102
+ {
103
+ path: 'bin/brakeman',
104
+ content: File.read(File.expand_path('templates/bin/brakeman.erb', __dir__))
105
+ },
106
+ {
107
+ path: 'bin/bundle',
108
+ content: File.read(File.expand_path('templates/bin/bundle.erb', __dir__))
109
+ },
110
+ {
111
+ path: 'bin/dev',
112
+ content: File.read(File.expand_path('templates/bin/dev.erb', __dir__))
113
+ },
114
+ {
115
+ path: 'bin/docker-entrypoint',
116
+ content: File.read(File.expand_path('templates/bin/docker-entrypoint.erb', __dir__))
117
+ },
118
+ {
119
+ path: 'bin/rails',
120
+ content: File.read(File.expand_path('templates/bin/rails.erb', __dir__))
121
+ },
122
+ {
123
+ path: 'bin/rake',
124
+ content: File.read(File.expand_path('templates/bin/rake.erb', __dir__))
125
+ },
126
+ {
127
+ path: 'bin/rubocop',
128
+ content: File.read(File.expand_path('templates/bin/rubocop.erb', __dir__))
129
+ },
130
+ {
131
+ path: 'bin/setup',
132
+ content: File.read(File.expand_path('templates/bin/setup.erb', __dir__))
133
+ },
134
+ {
135
+ path: 'config/environments/development.rb',
136
+ content: File.read(File.expand_path('templates/config/environments/development.rb.erb', __dir__))
137
+ },
138
+ {
139
+ path: 'config/environments/production.rb',
140
+ content: File.read(File.expand_path('templates/config/environments/production.rb.erb', __dir__))
141
+ },
142
+ {
143
+ path: 'config/environments/test.rb',
144
+ content: File.read(File.expand_path('templates/config/environments/test.rb.erb', __dir__))
145
+ },
146
+ {
147
+ path: 'config/initializers/assets.rb',
148
+ content: File.read(File.expand_path('templates/config/initializers/assets.rb.erb', __dir__))
149
+ },
150
+ {
151
+ path: 'config/initializers/content_security_policy.rb',
152
+ content: File.read(File.expand_path('templates/config/initializers/content_security_policy.rb.erb', __dir__))
153
+ },
154
+ {
155
+ path: 'config/initializers/filter_parameter_logging.rb',
156
+ content: File.read(File.expand_path('templates/config/initializers/filter_parameter_logging.rb.erb', __dir__))
157
+ },
158
+ {
159
+ path: 'config/initializers/inflections.rb',
160
+ content: File.read(File.expand_path('templates/config/initializers/inflections.rb.erb', __dir__))
161
+ },
162
+ {
163
+ path: 'config/initializers/permissions_policy.rb',
164
+ content: File.read(File.expand_path('templates/config/initializers/permissions_policy.rb.erb', __dir__))
165
+ },
166
+ {
167
+ path: 'config/locales/en.yml',
168
+ content: File.read(File.expand_path('templates/config/locales/en.yml.erb', __dir__))
169
+ },
170
+ {
171
+ path: 'config/application.rb',
172
+ content: File.read(File.expand_path('templates/config/application.rb.erb', __dir__))
173
+ },
174
+ {
175
+ path: 'config/boot.rb',
176
+ content: File.read(File.expand_path('templates/config/boot.rb.erb', __dir__))
177
+ },
178
+ {
179
+ path: 'config/cable.yml',
180
+ content: File.read(File.expand_path('templates/config/cable.yml.erb', __dir__))
181
+ },
182
+ {
183
+ path: 'config/credentials.yml.enc',
184
+ content: File.read(File.expand_path('templates/config/credentials.yml.enc.erb', __dir__))
185
+ },
186
+ {
187
+ path: 'config/database.yml',
188
+ content: File.read(File.expand_path('templates/config/database.yml.erb', __dir__))
189
+ },
190
+ {
191
+ path: 'config/environment.rb',
192
+ content: File.read(File.expand_path('templates/config/environment.rb.erb', __dir__))
193
+ },
194
+ {
195
+ path: 'config/master.key',
196
+ content: File.read(File.expand_path('templates/config/master.key.erb', __dir__))
197
+ },
198
+ {
199
+ path: 'config/puma.rb',
200
+ content: File.read(File.expand_path('templates/config/puma.rb.erb', __dir__))
201
+ },
202
+ {
203
+ path: 'config/storage.yml',
204
+ content: File.read(File.expand_path('templates/config/storage.yml.erb', __dir__))
205
+ },
206
+ {
207
+ path: 'db/seeds.rb',
208
+ content: File.read(File.expand_path('templates/db/seeds.rb.erb', __dir__))
209
+ },
210
+ {
211
+ path: 'lib/assets/.keep',
212
+ content: ''
213
+ },
214
+ {
215
+ path: 'lib/tasks/.keep',
216
+ content: ''
217
+ },
218
+ {
219
+ path: 'log/.keep',
220
+ content: ''
221
+ },
222
+ {
223
+ path: 'log/development.log',
224
+ content: ''
225
+ },
226
+ {
227
+ path: 'public/404.html',
228
+ content: File.read(File.expand_path('templates/public/404.html.erb', __dir__))
229
+ },
230
+ {
231
+ path: 'public/406-unsupported-browser.html',
232
+ content: File.read(File.expand_path('templates/public/406-unsupported-browser.html.erb', __dir__))
233
+ },
234
+ {
235
+ path: 'public/422.html',
236
+ content: File.read(File.expand_path('templates/public/422.html.erb', __dir__))
237
+ },
238
+ {
239
+ path: 'public/500.html',
240
+ content: File.read(File.expand_path('templates/public/500.html.erb', __dir__))
241
+ },
242
+ # {
243
+ # path: 'public/icon.png',
244
+ # content: File.read(File.expand_path('templates/public/icon.png.erb', __dir__))
245
+ # },
246
+ # {
247
+ # path: 'public/icon.svg',
248
+ # content: File.read(File.expand_path('templates/public/icon.svg.erb', __dir__))
249
+ # },
250
+ {
251
+ path: 'public/robots.txt',
252
+ content: File.read(File.expand_path('templates/public/robots.txt.erb', __dir__))
253
+ },
254
+ {
255
+ path: 'storage/.keep',
256
+ content: ''
257
+ },
258
+ {
259
+ path: 'tmp/.keep',
260
+ content: ''
261
+ },
262
+ {
263
+ path: 'vendor/.keep',
264
+ content: ''
265
+ },
266
+ {
267
+ path: '.dockerignore',
268
+ content: File.read(File.expand_path('templates/dockerignore.erb', __dir__))
269
+ },
270
+ {
271
+ path: '.gitattributes',
272
+ content: File.read(File.expand_path('templates/gitattributes.erb', __dir__))
273
+ },
274
+ {
275
+ path: '.gitignore',
276
+ content: File.read(File.expand_path('templates/gitignore.erb', __dir__))
277
+ },
278
+ {
279
+ path: '.node-version',
280
+ content: File.read(File.expand_path('templates/node-version.erb', __dir__))
281
+ },
282
+ {
283
+ path: '.rubocop.yml',
284
+ content: File.read(File.expand_path('templates/rubocop.yml.erb', __dir__))
285
+ },
286
+ {
287
+ path: '.ruby-version',
288
+ content: File.read(File.expand_path('templates/ruby-version.erb', __dir__))
289
+ },
290
+ {
291
+ path: 'config.ru',
292
+ content: File.read(File.expand_path('templates/config.ru.erb', __dir__))
293
+ },
294
+ {
295
+ path: 'Dockerfile',
296
+ content: File.read(File.expand_path('templates/Dockerfile.erb', __dir__))
297
+ },
298
+ {
299
+ path: 'Procfile.dev',
300
+ content: File.read(File.expand_path('templates/Procfile.dev.erb', __dir__))
301
+ },
302
+ {
303
+ path: 'Rakefile',
304
+ content: File.read(File.expand_path('templates/Rakefile.erb', __dir__))
305
+ },
306
+ {
307
+ path: 'README.md',
308
+ content: File.read(File.expand_path('templates/README.md.erb', __dir__))
309
+ },
310
+ {
311
+ path: 'tailwind.config.js',
312
+ content: File.read(File.expand_path('templates/tailwind.config.js.erb', __dir__))
313
+ }
314
+ ]
315
+ end
316
+ end
317
+ end
318
+ end
@@ -0,0 +1,83 @@
1
+ # syntax = docker/dockerfile:1
2
+
3
+ # This Dockerfile is designed for production, not development. Use with Kamal or build'n'run by hand:
4
+ # docker build -t my-app .
5
+ # docker run -d -p 80:80 -p 443:443 --name my-app -e RAILS_MASTER_KEY=<value from config/master.key> my-app
6
+
7
+ # Make sure RUBY_VERSION matches the Ruby version in .ruby-version
8
+ ARG RUBY_VERSION=3.2.2
9
+ FROM docker.io/library/ruby:$RUBY_VERSION-slim AS base
10
+
11
+ # Rails app lives here
12
+ WORKDIR /rails
13
+
14
+ # Install base packages
15
+ RUN apt-get update -qq && \
16
+ apt-get install --no-install-recommends -y curl libjemalloc2 libvips postgresql-client && \
17
+ rm -rf /var/lib/apt/lists /var/cache/apt/archives
18
+
19
+ # Set production environment
20
+ ENV RAILS_ENV="production" \
21
+ BUNDLE_DEPLOYMENT="1" \
22
+ BUNDLE_PATH="/usr/local/bundle" \
23
+ BUNDLE_WITHOUT="development"
24
+
25
+ # Throw-away build stage to reduce size of final image
26
+ FROM base AS build
27
+
28
+ # Install packages needed to build gems and node modules
29
+ RUN apt-get update -qq && \
30
+ apt-get install --no-install-recommends -y build-essential git libpq-dev node-gyp pkg-config python-is-python3 && \
31
+ rm -rf /var/lib/apt/lists /var/cache/apt/archives
32
+
33
+ # Install JavaScript dependencies
34
+ ARG NODE_VERSION=18.0.0
35
+ ARG YARN_VERSION=1.22.19
36
+ ENV PATH=/usr/local/node/bin:$PATH
37
+ RUN curl -sL https://github.com/nodenv/node-build/archive/master.tar.gz | tar xz -C /tmp/ && \
38
+ /tmp/node-build-master/bin/node-build "${NODE_VERSION}" /usr/local/node && \
39
+ npm install -g yarn@$YARN_VERSION && \
40
+ rm -rf /tmp/node-build-master
41
+
42
+ # Install application gems
43
+ COPY Gemfile Gemfile.lock ./
44
+ RUN bundle install && \
45
+ rm -rf ~/.bundle/ "${BUNDLE_PATH}"/ruby/*/cache "${BUNDLE_PATH}"/ruby/*/bundler/gems/*/.git && \
46
+ bundle exec bootsnap precompile --gemfile
47
+
48
+ # Install node modules
49
+ COPY package.json yarn.lock ./
50
+ RUN yarn install --frozen-lockfile
51
+
52
+ # Copy application code
53
+ COPY . .
54
+
55
+ # Precompile bootsnap code for faster boot times
56
+ RUN bundle exec bootsnap precompile app/ lib/
57
+
58
+ # Precompiling assets for production without requiring secret RAILS_MASTER_KEY
59
+ RUN SECRET_KEY_BASE_DUMMY=1 ./bin/rails assets:precompile
60
+
61
+
62
+ RUN rm -rf node_modules
63
+
64
+
65
+ # Final stage for app image
66
+ FROM base
67
+
68
+ # Copy built artifacts: gems, application
69
+ COPY --from=build "${BUNDLE_PATH}" "${BUNDLE_PATH}"
70
+ COPY --from=build /rails /rails
71
+
72
+ # Run and own only the runtime files as a non-root user for security
73
+ RUN groupadd --system --gid 1000 rails && \
74
+ useradd rails --uid 1000 --gid 1000 --create-home --shell /bin/bash && \
75
+ chown -R rails:rails db log storage tmp
76
+ USER 1000:1000
77
+
78
+ # Entrypoint prepares the database.
79
+ ENTRYPOINT ["/rails/bin/docker-entrypoint"]
80
+
81
+ # Start the server by default, this can be overwritten at runtime
82
+ EXPOSE 3000
83
+ CMD ["./bin/rails", "server"]
@@ -0,0 +1,3 @@
1
+ web: env RUBY_DEBUG_OPEN=true bin/rails server
2
+ js: yarn build --watch
3
+ css: yarn build:css --watch
@@ -0,0 +1,24 @@
1
+ # README
2
+
3
+ This README would normally document whatever steps are necessary to get the
4
+ application up and running.
5
+
6
+ Things you may want to cover:
7
+
8
+ * Ruby version
9
+
10
+ * System dependencies
11
+
12
+ * Configuration
13
+
14
+ * Database creation
15
+
16
+ * Database initialization
17
+
18
+ * How to run the test suite
19
+
20
+ * Services (job queues, cache servers, search engines, etc.)
21
+
22
+ * Deployment instructions
23
+
24
+ * ...