plutonium 0.10.2 → 0.11.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (228) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +1 -0
  3. data/Rakefile +1 -2
  4. data/app/assets/application.js.bk +31419 -0
  5. data/app/assets/plutonium-logo-original.png +0 -0
  6. data/app/assets/plutonium-logo-white.png +0 -0
  7. data/app/assets/plutonium-logo.png +0 -0
  8. data/app/assets/plutonium.css +1 -0
  9. data/app/assets/plutonium.ico +0 -0
  10. data/app/assets/plutonium.js +12416 -0
  11. data/app/assets/plutonium.js.map +7 -0
  12. data/app/assets/plutonium.min.js +39 -0
  13. data/app/assets/plutonium.min.js.map +7 -0
  14. data/app/views/application/_flash_alerts.html.erb +5 -2
  15. data/app/views/application/_flash_toasts.html.erb +2 -0
  16. data/app/views/application/_resource_header.html.erb +263 -697
  17. data/app/views/application/_resource_sidebar.html.erb +14 -12
  18. data/app/views/components/action_button/action_button_component.rb +3 -3
  19. data/app/views/components/attributes.rb +184 -0
  20. data/app/views/components/base.rb +19 -40
  21. data/app/views/components/block/block_component.html.erb +1 -1
  22. data/app/views/components/block/block_component.rb +11 -7
  23. data/app/views/components/breadcrumbs/breadcrumbs_component.rb +3 -3
  24. data/app/views/components/button/button_component.html.erb +2 -2
  25. data/app/views/components/button/button_component.rb +10 -5
  26. data/app/views/components/dyna_frame_content/dyna_frame_content_component.html.erb +1 -0
  27. data/app/views/components/dyna_frame_content/dyna_frame_content_component.rb +3 -3
  28. data/app/views/components/dyna_frame_host/dyna_frame_host_component.html.erb +1 -2
  29. data/app/views/components/dyna_frame_host/dyna_frame_host_component.rb +12 -5
  30. data/app/views/components/empty_card/empty_card_component.rb +3 -3
  31. data/app/views/components/form/form_builder.rb +1 -1
  32. data/app/views/components/form/form_component.rb +3 -3
  33. data/app/views/components/has_many_panel/has_many_panel_component.html.erb +25 -0
  34. data/app/views/components/has_many_panel/has_many_panel_component.rb +16 -0
  35. data/app/views/components/header/header_component.rb +3 -3
  36. data/app/views/components/interactive_action_form/interactive_action_form_component.rb +3 -3
  37. data/app/views/components/nav_grid_menu/nav_grid_menu_component.html.erb +24 -0
  38. data/app/views/components/nav_grid_menu/nav_grid_menu_component.rb +23 -0
  39. data/app/views/components/nav_grid_menu_item/nav_grid_menu_item_component.html.erb +4 -0
  40. data/app/views/components/nav_grid_menu_item/nav_grid_menu_item_component.rb +20 -0
  41. data/app/views/components/nav_user/nav_user_component.html.erb +50 -0
  42. data/app/views/components/nav_user/nav_user_component.rb +32 -0
  43. data/app/views/components/nav_user_link/nav_user_link_component.html.erb +7 -0
  44. data/app/views/components/nav_user_link/nav_user_link_component.rb +23 -0
  45. data/app/views/components/nav_user_section/nav_user_section_component.html.erb +7 -0
  46. data/app/views/components/nav_user_section/nav_user_section_component.rb +18 -0
  47. data/app/views/components/nested_resource_form_fields/nested_resource_form_fields_component.html.erb +1 -3
  48. data/app/views/components/nested_resource_form_fields/nested_resource_form_fields_component.rb +11 -5
  49. data/app/views/components/pagination/pagination_component.html.erb +1 -1
  50. data/app/views/components/pagination/pagination_component.rb +10 -7
  51. data/app/views/components/panel/panel_component.html.erb +13 -6
  52. data/app/views/components/panel/panel_component.rb +11 -5
  53. data/app/views/components/resource_header/resource_header_component.html.erb +81 -0
  54. data/app/views/components/resource_header/resource_header_component.rb +20 -0
  55. data/app/views/components/resource_layout/resource_layout_component.html.erb +32 -0
  56. data/app/views/components/resource_layout/resource_layout_component.rb +39 -0
  57. data/app/views/components/sidebar/sidebar_component.html.erb +3 -33
  58. data/app/views/components/sidebar/sidebar_component.rb +3 -3
  59. data/app/views/components/sidebar_menu/sidebar_menu_component.html.erb +4 -2
  60. data/app/views/components/sidebar_menu/sidebar_menu_component.rb +10 -6
  61. data/app/views/components/sidebar_menu_item/sidebar_menu_item_component.html.erb +63 -71
  62. data/app/views/components/sidebar_menu_item/sidebar_menu_item_component.rb +27 -8
  63. data/app/views/components/skeleton/table/table_component.html.erb +1 -1
  64. data/app/views/components/skeleton/table/table_component.rb +3 -3
  65. data/app/views/components/table/table_component.html.erb +40 -89
  66. data/app/views/components/table/table_component.rb +124 -28
  67. data/app/views/components/table_search_input/table_search_input_component.html.erb +1 -1
  68. data/app/views/components/table_search_input/table_search_input_component.rb +11 -6
  69. data/app/views/components/table_toolbar/table_toolbar_component.html.erb +1 -1
  70. data/app/views/components/table_toolbar/table_toolbar_component.rb +11 -3
  71. data/app/views/components/toolbar/toolbar_component.html.erb +2 -2
  72. data/app/views/components/toolbar/toolbar_component.rb +16 -8
  73. data/app/views/layouts/resource.html copy.erb +2 -2
  74. data/app/views/layouts/resource.html.erb +21 -37
  75. data/app/views/layouts/rodauth.html.erb +32 -25
  76. data/app/views/resource/_interactive_resource_action_form.html.erb +1 -1
  77. data/app/views/resource/_resource_details.html.erb +8 -5
  78. data/app/views/resource/_resource_table.html.erb +70 -1
  79. data/app/views/resource/interactive_resource_collection_action.html.erb +1 -0
  80. data/app/views/resource/interactive_resource_record_action.html.erb +1 -0
  81. data/app/views/resource/interactive_resource_recordless_action.html.erb +1 -0
  82. data/app/views/resource/new.html.erb +1 -0
  83. data/app/views/rodauth/add_recovery_codes.html.erb +8 -7
  84. data/app/views/rodauth/otp_auth.html.erb +1 -1
  85. data/app/views/rodauth/otp_setup.html.erb +10 -8
  86. data/config/initializers/simple_form.rb +22 -2
  87. data/esbuild.config.js +35 -31
  88. data/lib/generators/pu/core/assets/assets_generator.rb +41 -0
  89. data/lib/generators/pu/core/assets/templates/tailwind.config.js +18 -0
  90. data/lib/generators/pu/core/install/templates/config/initializers/plutonium.rb +3 -0
  91. data/lib/generators/pu/core/ruby/ruby_generator.rb +30 -0
  92. data/lib/generators/pu/core/ruby/templates/.keep +0 -0
  93. data/lib/generators/pu/docker/install/install_generator.rb +35 -0
  94. data/lib/generators/pu/docker/install/templates/.keep +0 -0
  95. data/lib/generators/pu/docker/install/templates/Dockerfile.dev.tt +30 -0
  96. data/lib/generators/pu/docker/install/templates/Dockerfile.tt +75 -0
  97. data/lib/generators/pu/docker/install/templates/bin/console +3 -0
  98. data/lib/generators/pu/docker/install/templates/bin/restart +3 -0
  99. data/lib/generators/pu/docker/install/templates/bin/shell +3 -0
  100. data/lib/generators/pu/docker/install/templates/docker-compose.yml +29 -0
  101. data/lib/generators/pu/gem/dotenv/dotenv_generator.rb +32 -0
  102. data/lib/generators/pu/gem/dotenv/templates/.env +6 -0
  103. data/lib/generators/pu/gem/dotenv/templates/.env.local +5 -0
  104. data/lib/generators/pu/gem/dotenv/templates/.env.local.template +5 -0
  105. data/lib/generators/pu/gem/dotenv/templates/.env.template +6 -0
  106. data/lib/generators/pu/gem/dotenv/templates/.keep +0 -0
  107. data/lib/generators/pu/gem/dotenv/templates/config/initializers/001_ensure_required_env.rb +21 -0
  108. data/lib/generators/pu/gem/redis/redis_generator.rb +22 -0
  109. data/lib/generators/pu/gem/redis/templates/.keep +0 -0
  110. data/lib/generators/pu/gen/component/component_generator.rb +13 -10
  111. data/lib/generators/pu/gen/component/templates/component.html.erb.tt +1 -1
  112. data/lib/generators/pu/gen/component/templates/component.rb.tt +10 -4
  113. data/lib/generators/pu/lib/plutonium_generators/concerns/actions.rb +154 -32
  114. data/lib/generators/pu/lib/plutonium_generators/generator.rb +6 -6
  115. data/lib/generators/pu/lib/plutonium_generators/installer.rb +1 -1
  116. data/lib/generators/pu/pkg/app/app_generator.rb +4 -4
  117. data/lib/generators/pu/pkg/app/templates/app/controllers/concerns/controller.rb.tt +28 -0
  118. data/lib/generators/pu/pkg/app/templates/app/controllers/controller.rb.tt +5 -0
  119. data/lib/generators/pu/pkg/app/templates/app/controllers/dashboard_controller.rb.tt +1 -1
  120. data/lib/generators/pu/res/conn/conn_generator.rb +4 -4
  121. data/lib/generators/pu/res/conn/templates/app/controllers/resource_controller.rb.tt +1 -1
  122. data/lib/generators/pu/res/model/model_generator.rb +3 -3
  123. data/lib/generators/pu/res/scaffold/templates/policy.rb.tt +6 -0
  124. data/lib/generators/pu/rodauth/account_generator.rb +10 -10
  125. data/lib/generators/pu/rodauth/install_generator.rb +9 -2
  126. data/lib/generators/pu/rodauth/migration/sequel/audit_logging.erb +2 -2
  127. data/lib/generators/pu/rodauth/migration_generator.rb +1 -1
  128. data/lib/generators/pu/rodauth/templates/app/{misc → rodauth}/account_rodauth_plugin.rb.tt +2 -2
  129. data/lib/generators/pu/rodauth/templates/app/{misc → rodauth}/rodauth_plugin.rb.tt +0 -3
  130. data/lib/generators/pu/rodauth/templates/db/migrate/install_rodauth.rb.tt +5 -0
  131. data/lib/generators/pu/service/postgres/postgres_generator.rb +61 -0
  132. data/lib/generators/pu/service/postgres/templates/.keep +0 -0
  133. data/lib/generators/pu/service/postgres/templates/bin/initdb.d/create-multiple-postgresql-databases.sh +22 -0
  134. data/lib/generators/pu/service/postgres/templates/database.yml.tt +93 -0
  135. data/lib/generators/pu/service/sidekiq/sidekiq_generator.rb +57 -0
  136. data/lib/generators/pu/service/sidekiq/templates/.keep +0 -0
  137. data/lib/generators/pu/service/sidekiq/templates/app/sidekiq/sidekiq_job.rb +3 -0
  138. data/lib/generators/pu/service/sidekiq/templates/config/initializers/sidekiq.rb +53 -0
  139. data/lib/generators/pu/service/sidekiq/templates/config/sidekiq.yml +6 -0
  140. data/lib/plutonium/config.rb +2 -9
  141. data/lib/plutonium/core/associations/renderers/basic_renderer.rb +28 -0
  142. data/lib/plutonium/core/associations/renderers/factory.rb +36 -0
  143. data/lib/plutonium/core/associations/renderers/has_many_renderer.rb +16 -0
  144. data/lib/plutonium/core/autodiscovery/association_renderer_discoverer.rb +31 -0
  145. data/lib/plutonium/core/controllers/authorizable.rb +13 -17
  146. data/lib/plutonium/core/controllers/base.rb +3 -7
  147. data/lib/plutonium/core/controllers/entity_scoping.rb +3 -3
  148. data/lib/plutonium/core/controllers/presentable.rb +6 -1
  149. data/lib/plutonium/core/definers/association_renderer_definer.rb +33 -0
  150. data/lib/plutonium/core/fields/inputs/checkbox_input.rb +13 -0
  151. data/lib/plutonium/core/fields/inputs/factory.rb +1 -0
  152. data/lib/plutonium/core/fields/inputs/polymorphic_belongs_to_association_input.rb +1 -1
  153. data/lib/plutonium/core/ui/detail.rb +1 -0
  154. data/lib/plutonium/helpers/application_helper.rb +8 -9
  155. data/lib/plutonium/helpers/assets_helper.rb +33 -0
  156. data/lib/plutonium/helpers/display_helper.rb +13 -0
  157. data/lib/plutonium/helpers/form_helper.rb +1 -1
  158. data/lib/plutonium/helpers.rb +1 -0
  159. data/lib/plutonium/icons.rb +12 -5
  160. data/lib/plutonium/pkg/app.rb +10 -0
  161. data/lib/plutonium/pundit/context.rb +18 -0
  162. data/lib/plutonium/pundit/policy_finder.rb +25 -0
  163. data/lib/plutonium/railtie.rb +24 -8
  164. data/lib/plutonium/reloader.rb +18 -7
  165. data/lib/plutonium/resource/controller.rb +5 -0
  166. data/lib/plutonium/resource/policy.rb +69 -47
  167. data/lib/plutonium/resource/presenter.rb +1 -0
  168. data/lib/plutonium/resource/query_object.rb +139 -130
  169. data/lib/plutonium/rodauth/controller_methods.rb +7 -3
  170. data/lib/plutonium/version.rb +1 -1
  171. data/lib/plutonium.rb +10 -54
  172. data/lib/tasks/create_rodauth_admin.rake +16 -0
  173. data/package-lock.json +782 -17
  174. data/package.json +31 -8
  175. data/postcss.config.js +17 -7
  176. data/src/.npmignore +2 -0
  177. data/src/js/controllers/color_mode_controller.js +41 -0
  178. data/src/js/controllers/frame_navigator_controller.js +99 -0
  179. data/src/js/controllers/has_many_panel_controller.js +8 -0
  180. data/src/js/controllers/nav_grid_menu_controller.js +8 -0
  181. data/src/js/controllers/nav_grid_menu_item_controller.js +8 -0
  182. data/{app/views/components/tab_bar/tab_bar_controller.js → src/js/controllers/nav_user_controller.js} +2 -2
  183. data/src/js/controllers/nav_user_link_controller.js +8 -0
  184. data/src/js/controllers/nav_user_section_controller.js +8 -0
  185. data/src/js/controllers/register_controllers.js +45 -0
  186. data/{app/assets/javascripts → src/js}/controllers/resource_dismiss_controller.js +2 -0
  187. data/{app/assets/javascripts → src/js}/controllers/resource_drop_down_controller.js +2 -0
  188. data/src/js/controllers/resource_header_controller.js +8 -0
  189. data/src/js/controllers/resource_layout_controller.js +8 -0
  190. data/src/js/controllers/sidebar_menu_controller.js +8 -0
  191. data/src/js/controllers/sidebar_menu_item_controller.js +8 -0
  192. data/src/js/core.js +4 -0
  193. data/{app/assets/javascripts/plutonium-app.js → src/js/plutonium.js} +1 -1
  194. data/{app/assets/javascripts → src/js}/turbo/turbo_debug.js +2 -4
  195. data/tailwind.config.js +85 -84
  196. metadata +106 -41
  197. data/app/assets/build/plutonium.js +0 -5122
  198. data/app/assets/javascripts/controllers/index.js +0 -34
  199. data/app/assets/javascripts/plutonium.js +0 -1
  200. data/app/views/application/_color_modes.html.erb +0 -57
  201. data/app/views/components/tab_bar/tab_bar_component.html.erb +0 -11
  202. data/app/views/components/tab_bar/tab_bar_component.rb +0 -9
  203. data/app/views/resource/_nav_user.html.erb +0 -4
  204. data/app/views/resource/_tab_menu.html.erb +0 -13
  205. data/css.manifest +0 -3
  206. data/js.manifest +0 -4
  207. data/lib/generators/pu/pkg/app/templates/app/controllers/app_controller.rb.tt +0 -5
  208. data/lib/generators/pu/pkg/app/templates/app/controllers/package_controller.rb.tt +0 -26
  209. data/public/plutonium-assets/application.css +0 -25086
  210. data/public/plutonium-assets/plutonium-app-36KN5FVJ.js +0 -6
  211. data/public/plutonium-assets/plutonium-app-36KN5FVJ.js.map +0 -7
  212. data/public/plutonium-assets/plutonium-app-6WILQCTT.js +0 -39
  213. data/public/plutonium-assets/plutonium-app-6WILQCTT.js.map +0 -7
  214. data/public/plutonium-assets/plutonium.2d4f0c333cd000051d3b.css +0 -3424
  215. data/public/plutonium-assets/plutonium.50232e35b5495f5ad90d.css +0 -3415
  216. /data/{app/assets/build → lib/generators/pu/core/assets/templates}/.keep +0 -0
  217. /data/lib/generators/pu/rodauth/templates/app/{misc → rodauth}/rodauth_app.rb.tt +0 -0
  218. /data/{app/assets/stylesheets → src/css}/plutonium.css +0 -0
  219. /data/{app/views/components/form → src/js/controllers}/form_controller.js +0 -0
  220. /data/{app/views/components/interactive_action_form → src/js/controllers}/interactive_action_form_controller.js +0 -0
  221. /data/{app/views/components/nested_resource_form_fields → src/js/controllers}/nested_resource_form_fields_controller.js +0 -0
  222. /data/{app/views/components/table → src/js/controllers}/table_controller.js +0 -0
  223. /data/{app/views/components/table_search_input → src/js/controllers}/table_search_input_controller.js +0 -0
  224. /data/{app/views/components/table_toolbar → src/js/controllers}/table_toolbar_controller.js +0 -0
  225. /data/{app/views/components/toolbar → src/js/controllers}/toolbar_controller.js +0 -0
  226. /data/{app/assets/javascripts → src/js}/turbo/index.js +0 -0
  227. /data/{app/assets/javascripts → src/js}/turbo/turbo_actions.js +0 -0
  228. /data/{app/assets/javascripts → src/js}/turbo/turbo_frame_monkey_patch.js +0 -0
@@ -0,0 +1,30 @@
1
+ # syntax = docker/dockerfile:1
2
+
3
+ # Make sure RUBY_VERSION matches the Ruby version in .ruby-version and Gemfile
4
+ ARG RUBY_VERSION=<%= ruby_version %>
5
+ FROM registry.docker.com/library/ruby:$RUBY_VERSION
6
+
7
+ WORKDIR /rails
8
+
9
+ # Install packages needed to build gems and node modules
10
+ RUN apt-get update -qq && \
11
+ apt-get install --no-install-recommends -y build-essential curl git libpq-dev node-gyp pkg-config python-is-python3
12
+
13
+ # Install JavaScript dependencies
14
+ ARG NODE_VERSION=22.2.0
15
+ ARG YARN_VERSION=1.22.22
16
+ ENV PATH=/usr/local/node/bin:$PATH
17
+ RUN curl -sL https://github.com/nodenv/node-build/archive/master.tar.gz | tar xz -C /tmp/ && \
18
+ /tmp/node-build-master/bin/node-build "${NODE_VERSION}" /usr/local/node && \
19
+ npm install -g yarn@$YARN_VERSION && \
20
+ rm -rf /tmp/node-build-master
21
+
22
+ # Additional dependencies go here
23
+
24
+ # Upgrade RubyGems and install the latest Bundler version
25
+ RUN gem update --system && gem install bundler
26
+
27
+ # Document that we're going to expose port 3000
28
+ EXPOSE 3000
29
+ # Use Bash as the default command
30
+ CMD ["/bin/bash"]
@@ -0,0 +1,75 @@
1
+ # syntax = docker/dockerfile:1
2
+
3
+ # Make sure RUBY_VERSION matches the Ruby version in .ruby-version and Gemfile
4
+ ARG RUBY_VERSION=<%= ruby_version %>
5
+ FROM registry.docker.com/library/ruby:$RUBY_VERSION-slim as base
6
+
7
+ # Rails app lives here
8
+ WORKDIR /rails
9
+
10
+ # Set production environment
11
+ ENV RAILS_ENV="production" \
12
+ BUNDLE_DEPLOYMENT="1" \
13
+ BUNDLE_PATH="/usr/local/bundle" \
14
+ BUNDLE_WITHOUT="development"
15
+
16
+
17
+ # Throw-away build stage to reduce size of final image
18
+ FROM base as build
19
+
20
+ # Install packages needed to build gems and node modules
21
+ RUN apt-get update -qq && \
22
+ apt-get install --no-install-recommends -y build-essential curl git libpq-dev node-gyp pkg-config python-is-python3
23
+
24
+ # Install JavaScript dependencies
25
+ ARG NODE_VERSION=22.2.0
26
+ ARG YARN_VERSION=1.22.22
27
+ ENV PATH=/usr/local/node/bin:$PATH
28
+ RUN curl -sL https://github.com/nodenv/node-build/archive/master.tar.gz | tar xz -C /tmp/ && \
29
+ /tmp/node-build-master/bin/node-build "${NODE_VERSION}" /usr/local/node && \
30
+ npm install -g yarn@$YARN_VERSION && \
31
+ rm -rf /tmp/node-build-master
32
+
33
+ # Install application gems
34
+ COPY .ruby-version Gemfile Gemfile.lock ./
35
+ RUN bundle install && \
36
+ rm -rf ~/.bundle/ "${BUNDLE_PATH}"/ruby/*/cache "${BUNDLE_PATH}"/ruby/*/bundler/gems/*/.git && \
37
+ bundle exec bootsnap precompile --gemfile
38
+
39
+ # Install node modules
40
+ COPY package.json yarn.lock ./
41
+ RUN yarn install --frozen-lockfile
42
+
43
+ # Copy application code
44
+ COPY . .
45
+
46
+ # Precompile bootsnap code for faster boot times
47
+ RUN bundle exec bootsnap precompile app/ lib/
48
+
49
+ # Precompiling assets for production without requiring secret RAILS_MASTER_KEY
50
+ RUN SECRET_KEY_BASE_DUMMY=1 ./bin/rails assets:precompile
51
+
52
+
53
+ # Final stage for app image
54
+ FROM base
55
+
56
+ # Install packages needed for deployment
57
+ RUN apt-get update -qq && \
58
+ apt-get install --no-install-recommends -y curl postgresql-client && \
59
+ rm -rf /var/lib/apt/lists /var/cache/apt/archives
60
+
61
+ # Copy built artifacts: gems, application
62
+ COPY --from=build /usr/local/bundle /usr/local/bundle
63
+ COPY --from=build /rails /rails
64
+
65
+ # Run and own only the runtime files as a non-root user for security
66
+ RUN useradd rails --create-home --shell /bin/bash && \
67
+ chown -R rails:rails db log tmp
68
+ USER rails:rails
69
+
70
+ # Entrypoint prepares the database.
71
+ ENTRYPOINT ["/rails/bin/docker-entrypoint"]
72
+
73
+ # Start the server by default, this can be overwritten at runtime
74
+ EXPOSE 3000
75
+ CMD ["./bin/rails", "server"]
@@ -0,0 +1,3 @@
1
+ #!/bin/bash -e
2
+
3
+ docker compose run --rm web bash -c "bundle && rails c"
@@ -0,0 +1,3 @@
1
+ #!/bin/bash -e
2
+
3
+ touch tmp/restart.txt
@@ -0,0 +1,3 @@
1
+ #!/bin/bash -e
2
+
3
+ docker compose run --rm web bash
@@ -0,0 +1,29 @@
1
+ ---
2
+ x-managed-by: plutonium
3
+
4
+ x-app: &app
5
+ build: # x-app
6
+ context: . # x-app
7
+ dockerfile: Dockerfile.dev # x-app
8
+ # x-app properties
9
+ volumes: # x-app
10
+ - ".:/rails" # x-app
11
+ - "./.volumes/bundle:/usr/local/bundle" # x-app
12
+ - "./.volumes/node_modules:/rails/node_modules" # x-app
13
+ - "./.volumes/shell_history:/root/shell_history" # x-app
14
+ depends_on: [] # x-app
15
+ environment: # x-app
16
+ RUBY_DEBUG_OPEN: true # x-app
17
+ PORT: 3000 # x-app
18
+ HISTFILE: /root/shell_history/.bash_history # x-app
19
+ tty: true # for binding.pry # x-app
20
+ stdin_open: true # for binding.pry # x-app
21
+
22
+ services:
23
+ web:
24
+ <<: *app
25
+ command: /bin/sh -c "rm -f tmp/pids/server.pid && bundle && yarn && bin/dev" # web
26
+ # web properties
27
+ ports: # web
28
+ - "3000:3000" # app
29
+ # additional services go here
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "../../lib/plutonium_generators"
4
+
5
+ module Pu
6
+ module Gem
7
+ class DotenvGenerator < Rails::Generators::Base
8
+ include PlutoniumGenerators::Generator
9
+
10
+ source_root File.expand_path("templates", __dir__)
11
+
12
+ desc "Set up dotenv"
13
+
14
+ def start
15
+ in_root do
16
+ [".env", ".env.local", ".env.template", ".env.local.template"].each do |file|
17
+ copy_file file
18
+ end
19
+
20
+ copy_file "config/initializers/001_ensure_required_env.rb"
21
+
22
+ gitignore "!/.env.template", "!/.env.local.template", "!/.env"
23
+
24
+ insert_into_file "Gemfile", "\ngem \"dotenv\", :groups => [:development, :test]\n", after: /^gem ["']rails["'].*\n/
25
+ bundle!
26
+ end
27
+ rescue => e
28
+ exception "#{self.class} failed:", e
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,6 @@
1
+ # Secrets should NOT be added here.
2
+ # Set them in `.env.local`
3
+
4
+ # # == S3
5
+ # S3_REGION=S3_REGION
6
+ # S3_BUCKET=S3_BUCKET
@@ -0,0 +1,5 @@
1
+ # Secrets for local testing should be added here.
2
+
3
+ # # == S3
4
+ # S3_ACCESS_KEY_ID=S3_ACCESS_KEY_ID
5
+ # S3_SECRET_ACCESS_KEY=S3_SECRET_ACCESS_KEY
@@ -0,0 +1,5 @@
1
+ # Secrets for local testing should be added here.
2
+
3
+ # # == S3
4
+ # S3_ACCESS_KEY_ID=S3_ACCESS_KEY_ID
5
+ # S3_SECRET_ACCESS_KEY=S3_SECRET_ACCESS_KEY
@@ -0,0 +1,6 @@
1
+ # Secrets should NOT be added here.
2
+ # Set them in `.env.local`
3
+
4
+ # # == S3
5
+ # S3_REGION=S3_REGION
6
+ # S3_BUCKET=S3_BUCKET
File without changes
@@ -0,0 +1,21 @@
1
+ return if ENV["SECRET_KEY_BASE_DUMMY"].present?
2
+
3
+ # Add required env vars to this list
4
+ required_env_vars = %w[]
5
+
6
+ if Rails.env.production?
7
+ required_env_vars += %w[RAILS_MASTER_KEY DATABASE_URL]
8
+ end
9
+
10
+ # Add additional env vars here
11
+
12
+ # Check required env vars
13
+ required_env_vars.each do |env_var|
14
+ if !ENV.has_key?(env_var) || ENV[env_var].blank?
15
+ raise <<~EOL
16
+ Missing required environment variable: #{env_var}
17
+
18
+ Ask a teammate for the appropriate value.
19
+ EOL
20
+ end
21
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "../../lib/plutonium_generators"
4
+
5
+ module Pu
6
+ module Gem
7
+ class RedisGenerator < Rails::Generators::Base
8
+ include PlutoniumGenerators::Generator
9
+
10
+ source_root File.expand_path("templates", __dir__)
11
+
12
+ desc "Set up redis"
13
+
14
+ def start
15
+ bundle "redis"
16
+ bundle "hiredis"
17
+ rescue => e
18
+ exception "#{self.class} failed:", e
19
+ end
20
+ end
21
+ end
22
+ end
File without changes
@@ -20,10 +20,9 @@ module Pu
20
20
  template "component.html.erb", "#{component_path}.html.erb"
21
21
  template "controller.js", controller_path
22
22
 
23
- controllers_index_file = File.join __dir__, "../../../../../app/assets/javascripts/controllers/index.js"
23
+ controllers_index_file = File.join __dir__, "../../../../../src/js/controllers/register_controllers.js"
24
24
  insert_into_file controllers_index_file, controller_import, after: /.*Import controllers here*\n/
25
25
  insert_into_file controllers_index_file, controller_registration, after: /.*Register controllers here*\n/
26
- insert_into_file controllers_index_file, controller_export, after: /.*Export controllers here*\n/
27
26
  end
28
27
 
29
28
  protected
@@ -45,7 +44,7 @@ module Pu
45
44
  end
46
45
 
47
46
  def component_namespace
48
- ["Plutonium::Ui", component_module].compact.join "::"
47
+ ["PlutoniumUi", component_module].compact.join "::"
49
48
  end
50
49
 
51
50
  def component_reference
@@ -68,8 +67,16 @@ module Pu
68
67
  [component_module, component_name].compact.join("::").gsub("::", "__").underscore
69
68
  end
70
69
 
70
+ def controller_filename
71
+ "#{[component_module, component_name].compact.join("::").underscore}_controller.js"
72
+ end
73
+
74
+ def controllers_dir
75
+ File.join "src", "js", "controllers"
76
+ end
77
+
71
78
  def controller_path
72
- "#{component_base_path}_controller.js"
79
+ File.join controllers_dir, controller_filename
73
80
  end
74
81
 
75
82
  def controller_identifier
@@ -77,20 +84,16 @@ module Pu
77
84
  end
78
85
 
79
86
  def controller_reference
80
- [component_module, "#{component_name}Controller"].compact.join("::").gsub("::", "_")
87
+ [component_module, "#{component_name}Controller"].compact.join("")
81
88
  end
82
89
 
83
90
  def controller_import
84
- "import #{controller_reference} from \"../../../../#{controller_path}\"\n"
91
+ "import #{controller_reference} from \"./#{controller_filename}\"\n"
85
92
  end
86
93
 
87
94
  def controller_registration
88
95
  " application.register(\"#{controller_identifier}\", #{controller_reference})\n"
89
96
  end
90
-
91
- def controller_export
92
- "export { #{controller_reference} }\n"
93
- end
94
97
  end
95
98
  end
96
99
  end
@@ -1,3 +1,3 @@
1
- <div data-controller="<%= controller_identifier %>" <%%= render_component_attributes %>>
1
+ <div <%%= attributes_html %>>
2
2
  <%%= content %>
3
3
  </div>
@@ -1,8 +1,14 @@
1
1
  module <%= component_namespace %>
2
- class <%= component_classname %> < Plutonium::Ui::Base
3
- # def base_classname
4
- # "base classnames here"
5
- # end
2
+ class <%= component_classname %> < PlutoniumUi::Base
3
+ private
4
+
5
+ def base_attributes
6
+ # base attributes go here
7
+ {
8
+ classname: "<%= controller_identifier %>",
9
+ controller: "<%= controller_identifier %>"
10
+ }
11
+ end
6
12
  end
7
13
  end
8
14
 
@@ -22,7 +22,10 @@ module PlutoniumGenerators
22
22
 
23
23
  in_root do
24
24
  create_file ".ruby-version", version, force: true, verbose: false
25
- gsub_file "Gemfile", /^ruby ["'].*["']/, "ruby '~> #{version}'", verbose: false
25
+ gsub_file("Gemfile", /^ruby .*/, "ruby File.read(\".ruby-version\").strip", verbose: false)
26
+ %w[Dockerfile Dockerfile.prod Dockerfile.dev].each do |file|
27
+ gsub_file(file, /^ARG RUBY_VERSION=.*/, "ARG RUBY_VERSION=#{version}", verbose: false) if File.exist?(file)
28
+ end
26
29
  end
27
30
  end
28
31
 
@@ -95,29 +98,84 @@ module PlutoniumGenerators
95
98
  # gsub_file "Gemfile", /(:?^.*#.*\n)*.*gem ['"]#{gem}['"].*\n/, "", verbose: false
96
99
  # end
97
100
 
98
- #
99
- # Evaluates the given template and merges it with the project's docker-compose.yml
100
- #
101
- # @param [String] source the template filename
102
- #
103
- # @return [void]
104
- #
105
- def docker_compose(source)
106
- log :docker_compose, source
101
+ # #
102
+ # # Evaluates the given template and merges it with the project's docker-compose.yml
103
+ # #
104
+ # # @param [String] source the template filename
105
+ # #
106
+ # # @return [void]
107
+ # #
108
+ # def docker_compose(source)
109
+ # log :docker_compose, source
110
+
111
+ # in_root do
112
+ # compose_file = "docker-compose.yml"
113
+ # compose_definition = YAML.load_file(compose_file) if File.exist?(compose_file)
114
+ # compose_definition ||= {
115
+ # version: "3.7",
116
+ # services: {}
117
+ # }
118
+ # compose_definition.deep_stringify_keys!
119
+
120
+ # new_definition = YAML.load template_eval("docker-compose/#{source}.yml.tt")
121
+ # compose_definition.deep_merge! new_definition.deep_stringify_keys
122
+
123
+ # create_file compose_file, YAML.dump(compose_definition), force: true
124
+ # end
125
+ # end
126
+
127
+ def managed_compose(file = "docker-compose.yml")
128
+ @managed_compose ||= {}
129
+
130
+ @managed_compose[file] ||= in_root do
131
+ next unless File.exist?(file)
132
+
133
+ parsed_yaml = YAML.load_file(file, aliases: true)
134
+ parsed_yaml if parsed_yaml["x-managed-by"] == "plutonium"
135
+ end
136
+ end
137
+
138
+ def add_compose_service(service, config, file = "docker-compose.yml")
139
+ docker_compose = managed_compose(file)
140
+ error "Docker compose is not managed by plutonium" unless docker_compose
141
+ error "#{service} is already added to compose" if docker_compose["services"].key?(service.to_s)
107
142
 
108
143
  in_root do
109
- compose_file = "docker-compose.yml"
110
- compose_definition = YAML.load_file(compose_file) if File.exist?(compose_file)
111
- compose_definition ||= {
112
- version: "3.7",
113
- services: {}
114
- }
115
- compose_definition.deep_stringify_keys!
116
-
117
- new_definition = YAML.load template_eval("docker-compose/#{source}.yml.tt")
118
- compose_definition.deep_merge! new_definition.deep_stringify_keys
119
-
120
- create_file compose_file, YAML.dump(compose_definition), force: true
144
+ insert_into_file file, indent(config, 2), after: /.*# additional services go here.*\n/
145
+ end
146
+ end
147
+
148
+ def add_compose_env(key, value, service = "x-app", file = "docker-compose.yml")
149
+ raise NotImplementedError, "only service: x-app is currently supported" unless service == "x-app"
150
+
151
+ docker_compose = managed_compose(file)
152
+ error "Docker compose is not managed by plutonium" unless docker_compose
153
+
154
+ in_root do
155
+ gsub_file file, "environment: {} # x-app", "environment: # #{service}"
156
+ gsub_file file, /.*#{key}:.*# #{service}.*\n/, ""
157
+ config = "#{key}: #{value} # #{service}\n"
158
+ insert_into_file file, indent(config, 4), after: /.*environment: # #{service}.*\n/
159
+ end
160
+ end
161
+
162
+ def add_compose_dependency(value, service = "x-app", file = "docker-compose.yml")
163
+ raise NotImplementedError, "only service: x-app is currently supported" unless service == "x-app"
164
+
165
+ docker_compose = managed_compose(file)
166
+ error "Docker compose is not managed by plutonium" unless docker_compose
167
+
168
+ in_root do
169
+ gsub_file file, "depends_on: [] # x-app", "depends_on: # #{service}"
170
+ gsub_file file, /.*- #{value}.*# #{service}.*\n/, ""
171
+ config = "- #{value} # #{service}\n"
172
+ insert_into_file file, indent(config, 4), after: /.*depends_on: # #{service}.*\n/
173
+ end
174
+ end
175
+
176
+ def add_docker_dependency(config, file = "Dockerfile.dev")
177
+ in_root do
178
+ insert_into_file file, "#{config}\n", after: /.*# Additional dependencies go here*\n\n/
121
179
  end
122
180
  end
123
181
 
@@ -283,6 +341,23 @@ module PlutoniumGenerators
283
341
  end
284
342
  end
285
343
 
344
+ #
345
+ # Insert the given directives into .dockerignore
346
+ #
347
+ # @param [String] *directives directives to ignore
348
+ #
349
+ # @return [void]
350
+ #
351
+ def dockerignore(*directives)
352
+ in_root do
353
+ # Doing this one by one so that duplication detection during insertion will work
354
+ directives.each do |directive|
355
+ log :dockerignore, directive
356
+ insert_into_file ".dockerignore", "#{directive}\n", verbose: false
357
+ end
358
+ end
359
+ end
360
+
286
361
  #
287
362
  # Similar to #run, this executes a command but returns both success and output
288
363
  #
@@ -313,6 +388,58 @@ module PlutoniumGenerators
313
388
  [success, output]
314
389
  end
315
390
 
391
+ def bin_directory
392
+ # Copy the directory and store the list of copied files
393
+ @copied_files = directory "bin"
394
+ # Change permissions of the copied files to make them executable
395
+ in_root do
396
+ @copied_files.each do |file|
397
+ file = file.split("/bin/")[1]
398
+ file = "bin/#{file}"
399
+ puts file
400
+ chmod file, "+x" if File.file?(file)
401
+ end
402
+ end
403
+ end
404
+
405
+ def bundle!
406
+ log :bundle, "install"
407
+
408
+ Bundler.with_unbundled_env do
409
+ run "bundle install", verbose: false
410
+ end
411
+ end
412
+
413
+ def bundle(*gems, **options)
414
+ gems = Array(gems).join " "
415
+ options = hash_to_cli_options options
416
+ cmd_args = "add #{gems} #{options}"
417
+
418
+ log :bundle, cmd_args
419
+ Bundler.with_unbundled_env do
420
+ run "bundle #{cmd_args}", verbose: false
421
+ end
422
+ end
423
+
424
+ def unbundle(*gems)
425
+ gems = Array(gems).join " "
426
+ cmd_args = "remove #{gems}"
427
+
428
+ log :bundle, cmd_args
429
+ Bundler.with_unbundled_env do
430
+ run "bundle remove #{Array(gems).join " "}", verbose: false
431
+ end
432
+ end
433
+
434
+ def add_required_env_vars(*vars)
435
+ vars = Array(vars).join " "
436
+ log :equired_env_vars, vars
437
+ in_root do
438
+ cmd = "required_env_vars += %w[#{vars}]\n"
439
+ insert_into_file "config/initializers/001_ensure_required_env.rb", cmd, after: /# Add additional env vars here.*\n/
440
+ end
441
+ end
442
+
316
443
  private
317
444
 
318
445
  #
@@ -351,16 +478,11 @@ module PlutoniumGenerators
351
478
  end
352
479
  end
353
480
 
354
- def bundle(*gems)
355
- Bundler.with_unbundled_env do
356
- run "bundle add #{Array(gems).join " "}"
357
- end
358
- end
359
-
360
- def unbundle(*gems)
361
- Bundler.with_unbundled_env do
362
- run "bundle remove #{Array(gems).join " "}"
363
- end
481
+ def hash_to_cli_options(hash)
482
+ hash.map do |key, value|
483
+ formatted_value = value.is_a?(Array) ? value.join(",") : value
484
+ "--#{key.to_s.tr("_", "-")}=#{formatted_value}"
485
+ end.join(" ")
364
486
  end
365
487
  end
366
488
  end
@@ -64,13 +64,13 @@ module PlutoniumGenerators
64
64
  @prompt ||= TTY::Prompt.new
65
65
  end
66
66
 
67
- def appname
68
- defined?(Rails.application) ? Rails.application.class.module_parent.name : "PlutoniumGenerators"
69
- end
67
+ # def appname
68
+ # defined?(Rails.application) ? Rails.application.class.module_parent.name : "PlutoniumGenerators"
69
+ # end
70
70
 
71
- def app_name
72
- appname.underscore
73
- end
71
+ # def app_name
72
+ # appname.underscore
73
+ # end
74
74
 
75
75
  def pug_installed?(feature, version: nil)
76
76
  installed_version = read_config(:installed, feature)
@@ -21,7 +21,7 @@ module PlutoniumGenerators
21
21
  protected
22
22
 
23
23
  def install!(feature)
24
- set_ruby_version! if root_pug?
24
+ # set_ruby_version! if root_pug?
25
25
 
26
26
  from_version = read_config(:installed, feature, default: "0.0.0")
27
27
  versions = methods.map do |m|
@@ -28,10 +28,10 @@ module Pu
28
28
  template "lib/engine.rb", "packages/#{package_namespace}/lib/engine.rb"
29
29
  template "config/routes.rb", "packages/#{package_namespace}/config/routes.rb"
30
30
 
31
- template "app/controllers/package_controller.rb",
32
- "packages/#{package_namespace}/app/controllers/#{package_namespace}/#{package_namespace}_controller.rb"
33
- template "app/controllers/app_controller.rb",
34
- "packages/#{package_namespace}/app/controllers/#{package_namespace}/app_controller.rb"
31
+ template "app/controllers/concerns/controller.rb",
32
+ "packages/#{package_namespace}/app/controllers/#{package_namespace}/concerns/controller.rb"
33
+ template "app/controllers/controller.rb",
34
+ "packages/#{package_namespace}/app/controllers/#{package_namespace}/controller.rb"
35
35
 
36
36
  template "app/controllers/dashboard_controller.rb",
37
37
  "packages/#{package_namespace}/app/controllers/#{package_namespace}/dashboard_controller.rb"
@@ -0,0 +1,28 @@
1
+ module <%= package_name %>
2
+ module Concerns
3
+ module Controller
4
+ extend ActiveSupport::Concern
5
+ include Plutonium::Application::Controller
6
+ <%- if rodauth_account.present? -%>
7
+ include Plutonium::Auth.rodauth(:<%= rodauth_account %>)
8
+ <%- elsif public_access? -%>
9
+ include Plutonium::Auth::Public
10
+ <%- end -%>
11
+ # add concerns above.
12
+
13
+ included do
14
+ boot <%= package_name %>
15
+ <%- if bring_your_own_auth? -%>
16
+
17
+ helper_method :current_user
18
+ <%- end -%>
19
+ end
20
+ <%- if bring_your_own_auth? -%>
21
+
22
+ def current_user
23
+ raise NotImplementedError, "#{self.class}#current_user must return a non nil value"
24
+ end
25
+ <%- end -%>
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,5 @@
1
+ module <%= package_name %>
2
+ class Controller < ::ApplicationController
3
+ include <%= package_name %>::Concerns::Controller
4
+ end
5
+ end
@@ -1,5 +1,5 @@
1
1
  module <%= package_name %>
2
- class DashboardController < AppController
2
+ class DashboardController < Controller
3
3
  def index
4
4
  end
5
5
  end