plutonium 0.8.0 → 0.9.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (77) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +7 -0
  3. data/Rakefile +10 -0
  4. data/app/assets/build/plutonium.js +5122 -0
  5. data/app/assets/javascripts/controllers/index.js +34 -0
  6. data/app/assets/javascripts/controllers/resource_dismiss_controller.js +37 -0
  7. data/app/assets/javascripts/controllers/resource_drop_down_controller.js +29 -0
  8. data/app/assets/javascripts/plutonium-app.js +7 -0
  9. data/app/assets/javascripts/plutonium.js +1 -0
  10. data/app/assets/{js → javascripts}/turbo/index.js +1 -1
  11. data/app/views/application/_flash.html.erb +1 -1
  12. data/app/views/application/_flash_alerts.html.erb +51 -7
  13. data/app/views/application/_flash_toasts.html.erb +53 -23
  14. data/app/views/application/_resource_header.html.erb +563 -561
  15. data/app/views/components/form/form_builder.rb +2 -2
  16. data/app/views/components/form/form_component.html.erb +5 -6
  17. data/app/views/components/interactive_action_form/interactive_action_form_component.html.erb +1 -1
  18. data/app/views/components/nested_resource_form_fields/nested_resource_form_fields_component.html.erb +66 -0
  19. data/app/views/components/nested_resource_form_fields/nested_resource_form_fields_component.rb +23 -0
  20. data/app/views/components/nested_resource_form_fields/nested_resource_form_fields_controller.js +64 -0
  21. data/app/views/components/sidebar/sidebar_component.html.erb +61 -63
  22. data/app/views/components/table_search_input/table_search_input_component.html.erb +1 -1
  23. data/app/views/layouts/resource.html copy.erb +0 -2
  24. data/app/views/layouts/resource.html.erb +1 -3
  25. data/app/views/layouts/rodauth.html.erb +0 -1
  26. data/app/views/resource/_interactive_resource_action_form.html.erb +1 -1
  27. data/css.manifest +3 -0
  28. data/esbuild.config.js +44 -0
  29. data/exe/pug +6 -0
  30. data/lib/generators/pu/gen/component/component_generator.rb +14 -5
  31. data/lib/generators/pu/gen/pug/pug_generator.rb +1 -1
  32. data/lib/generators/pu/lib/plutonium_generators/cli.rb +42 -0
  33. data/lib/generators/pu/lib/plutonium_generators/concerns/actions.rb +86 -72
  34. data/lib/generators/pu/lib/plutonium_generators/generator.rb +1 -5
  35. data/lib/generators/pu/lib/plutonium_generators.rb +8 -0
  36. data/lib/generators/pu/rodauth/install_generator.rb +1 -2
  37. data/lib/plutonium/core/actions/collection.rb +1 -1
  38. data/lib/plutonium/core/controllers/authorizable.rb +4 -4
  39. data/lib/plutonium/core/fields/inputs/base.rb +1 -1
  40. data/lib/plutonium/core/fields/inputs/nested_input.rb +57 -0
  41. data/lib/plutonium/core/fields/inputs/noop_input.rb +1 -1
  42. data/lib/plutonium/core/fields/inputs/phone_input.rb +1 -1
  43. data/lib/plutonium/core/fields/inputs/polymorphic_belongs_to_association_input.rb +1 -1
  44. data/lib/plutonium/core/fields/inputs/simple_form_association_input.rb +1 -1
  45. data/lib/plutonium/core/fields/inputs/simple_form_input.rb +1 -1
  46. data/lib/plutonium/pkg/base.rb +0 -4
  47. data/lib/plutonium/railtie.rb +10 -2
  48. data/lib/plutonium/resource/policy.rb +6 -0
  49. data/lib/plutonium/resource/presenter.rb +35 -0
  50. data/lib/plutonium/resource/record.rb +40 -7
  51. data/lib/plutonium/version.rb +1 -1
  52. data/lib/plutonium.rb +17 -14
  53. data/package.json +4 -3
  54. data/postcss.config.js +1 -1
  55. data/public/plutonium-assets/plutonium-app-36KN5FVJ.js +6 -0
  56. data/public/plutonium-assets/plutonium-app-36KN5FVJ.js.map +7 -0
  57. data/public/plutonium-assets/plutonium.50232e35b5495f5ad90d.css +3415 -0
  58. data/tailwind.config.js +11 -12
  59. data/templates/base.rb +8 -0
  60. metadata +28 -21
  61. data/app/assets/js/controllers/application.js +0 -6
  62. data/app/assets/js/controllers/dropdown_controller.js +0 -12
  63. data/app/assets/js/controllers/index.js +0 -21
  64. data/app/assets/js/plutonium.js +0 -2
  65. data/build.js +0 -12
  66. data/lib/generators/pu/gem/pagy/pagy_generator.rb +0 -25
  67. data/lib/generators/pu/gem/pagy/templates/config/initializers/pagy.rb +0 -4
  68. data/lib/generators/pu/gem/rabl/rabl_generator.rb +0 -25
  69. data/lib/generators/pu/gem/rabl/templates/.keep +0 -0
  70. data/lib/generators/pu/gem/rabl/templates/config/initializers/rabl.rb +0 -60
  71. data/lib/generators/pu/gem/simple_form/simple_form_generator.rb +0 -25
  72. data/lib/generators/pu/gem/simple_form/templates/.keep +0 -0
  73. /data/{lib/generators/pu/gem/pagy/templates → app/assets/build}/.keep +0 -0
  74. /data/app/assets/{js → javascripts}/turbo/turbo_actions.js +0 -0
  75. /data/app/assets/{js → javascripts}/turbo/turbo_debug.js +0 -0
  76. /data/app/assets/{js → javascripts}/turbo/turbo_frame_monkey_patch.js +0 -0
  77. /data/app/assets/{css → stylesheets}/plutonium.css +0 -0
@@ -0,0 +1,34 @@
1
+ // Import controllers here
2
+ import NestedResourceFormFieldsController from "../../../views/components/nested_resource_form_fields/nested_resource_form_fields_controller.js"
3
+ import TabBarController from "../../../views/components/tab_bar/tab_bar_controller.js"
4
+ import ToolbarController from "../../../views/components/toolbar/toolbar_controller.js"
5
+ import TableSearchInputController from "../../../views/components/table_search_input/table_search_input_controller.js"
6
+ import TableToolbarController from "../../../views/components/table_toolbar/table_toolbar_controller.js"
7
+ import TableController from "../../../views/components/table/table_controller.js"
8
+ import FormController from "../../../views/components/form/form_controller.js"
9
+ import ResourceDropDownController from "./resource_drop_down_controller.js"
10
+ import ResourceDismissController from "./resource_dismiss_controller.js"
11
+
12
+ export function registerControllers(application) {
13
+ // Register controllers here
14
+ application.register("nested-resource-form-fields", NestedResourceFormFieldsController)
15
+ application.register("tab-bar", TabBarController)
16
+ application.register("toolbar", ToolbarController)
17
+ application.register("table-search-input", TableSearchInputController)
18
+ application.register("table-toolbar", TableToolbarController)
19
+ application.register("table", TableController)
20
+ application.register("form", FormController)
21
+ application.register("resource-drop-down", ResourceDropDownController)
22
+ application.register("resource-dismiss", ResourceDismissController)
23
+ }
24
+
25
+ // Export controllers here
26
+ export { NestedResourceFormFieldsController };
27
+ export { TabBarController };
28
+ export { ToolbarController };
29
+ export { TableSearchInputController };
30
+ export { TableToolbarController };
31
+ export { TableController };
32
+ export { FormController };
33
+ export { ResourceDropDownController };
34
+ export { ResourceDismissController };
@@ -0,0 +1,37 @@
1
+ import { Controller } from "@hotwired/stimulus"
2
+ import { Dismiss } from 'flowbite';
3
+
4
+
5
+ // Connects to data-controller="resource-dismiss"
6
+ export default class extends Controller {
7
+ static targets = ["trigger", "target"]
8
+
9
+ static values = {
10
+ after: Number,
11
+ }
12
+
13
+ connect() {
14
+ // https://flowbite.com/docs/components/alerts/#javascript-behaviour
15
+ this.dismiss = new Dismiss(this.targetTarget, this.triggerTarget);
16
+
17
+ console.log(this.hasAfterValue)
18
+ console.log(this.afterValue)
19
+ if (this.hasAfterValue && this.afterValue > 0) {
20
+ this.autoDismissTimeout = setTimeout(() => {
21
+ this.hide()
22
+ this.autoDismissTimeout = null
23
+ }, this.afterValue);
24
+ }
25
+ }
26
+
27
+ disconnect() {
28
+ if (this.autoDismissTimeout) clearTimeout(this.autoDismissTimeout)
29
+
30
+ this.dismiss = null
31
+ this.autoDismissTimeout = null
32
+ }
33
+
34
+ hide() {
35
+ this.dismiss.hide()
36
+ }
37
+ }
@@ -0,0 +1,29 @@
1
+ import { Controller } from "@hotwired/stimulus"
2
+ import { Dropdown } from 'flowbite';
3
+
4
+
5
+ // Connects to data-controller="resource-drop-down"
6
+ export default class extends Controller {
7
+ static targets = ["trigger", "menu"]
8
+
9
+ connect() {
10
+ // https://flowbite.com/docs/components/dropdowns/#javascript-behaviour
11
+ this.dropdown = new Dropdown(this.menuTarget, this.triggerTarget);
12
+ }
13
+
14
+ disconnect() {
15
+ this.dropdown = null
16
+ }
17
+
18
+ toggle() {
19
+ this.dropdown.toggle()
20
+ }
21
+
22
+ show() {
23
+ this.dropdown.show()
24
+ }
25
+
26
+ hide() {
27
+ this.dropdown.show()
28
+ }
29
+ }
@@ -0,0 +1,7 @@
1
+ import { Application } from "@hotwired/stimulus"
2
+ const application = Application.start()
3
+
4
+ import { registerControllers } from "./plutonium"
5
+ registerControllers(application)
6
+
7
+ import "./turbo"
@@ -0,0 +1 @@
1
+ export * from "./controllers"
@@ -1,4 +1,4 @@
1
- import * as Turbo from "@hotwired/turbo"
1
+ // import * as Turbo from "@hotwired/turbo"
2
2
 
3
3
  import "./turbo_debug"
4
4
  // import "./turbo_actions"
@@ -1 +1 @@
1
- <%= render "flash_toasts" %>
1
+ <%= render "flash_alerts" %>
@@ -1,9 +1,53 @@
1
1
  <% flash.each do |type, msg| %>
2
- <%
3
- type = { alert: :danger, warning: :warning, success: :success }[type.to_sym] || :primary
4
- %>
5
- <div class="alert alert-<%= type %> alert-dismissible fade show" role="alert" data-turbo-temporary>
6
- <%= msg %>
7
- <button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close">
8
- </div>
2
+ <%
3
+ color = case type.to_sym
4
+ when :success
5
+ # bg-green-50 text-green-800 text-green-500 text-green-400 ring-green-400
6
+ "green"
7
+ when :warning
8
+ # bg-yellow-50 text-yellow-800 text-yellow-500 text-yellow-400 ring-yellow-400
9
+ "yellow"
10
+ when :alert, :danger, :error
11
+ # bg-red-50 text-red-800 text-red-500 text-red-400 ring-red-400
12
+ "red"
13
+ else
14
+ # bg-blue-50 text-blue-800 text-blue-500 text-blue-400 ring-blue-400
15
+ "blue"
16
+ end
17
+ %>
18
+
19
+ <div data-controller="resource-dismiss"
20
+ data-resource-dismiss-target="target"
21
+ data-resource-dismiss-after-value="6000"
22
+ class="flex items-center p-4 mb-4 text-<%= color %>-800 rounded-lg bg-<%= color %>-50 dark:bg-gray-800 dark:text-<%= color %>-400"
23
+ role="alert">
24
+ <% case type.to_sym %>
25
+ <% when :success %>
26
+ <svg class="flex-shrink-0 w-4 h-4" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" fill="currentColor" viewBox="0 0 20 20">
27
+ <path d="M10 .5a9.5 9.5 0 1 0 9.5 9.5A9.51 9.51 0 0 0 10 .5Zm3.707 8.207-4 4a1 1 0 0 1-1.414 0l-2-2a1 1 0 0 1 1.414-1.414L9 10.586l3.293-3.293a1 1 0 0 1 1.414 1.414Z"/>
28
+ </svg>
29
+ <% when :warning %>
30
+ <svg class="flex-shrink-0 w-4 h-4" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" fill="currentColor" viewBox="0 0 20 20">
31
+ <path d="M10 .5a9.5 9.5 0 1 0 9.5 9.5A9.51 9.51 0 0 0 10 .5ZM10 15a1 1 0 1 1 0-2 1 1 0 0 1 0 2Zm1-4a1 1 0 0 1-2 0V6a1 1 0 0 1 2 0v5Z"/>
32
+ </svg>
33
+ <% when :alert, :danger, :error %>
34
+ <svg class="flex-shrink-0 w-4 h-4" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" fill="currentColor" viewBox="0 0 20 20">
35
+ <path d="M10 .5a9.5 9.5 0 1 0 9.5 9.5A9.51 9.51 0 0 0 10 .5Zm3.707 11.793a1 1 0 1 1-1.414 1.414L10 11.414l-2.293 2.293a1 1 0 0 1-1.414-1.414L8.586 10 6.293 7.707a1 1 0 0 1 1.414-1.414L10 8.586l2.293-2.293a1 1 0 0 1 1.414 1.414L11.414 10l2.293 2.293Z"/>
36
+ </svg>
37
+ <% else %>
38
+ <svg class="w-4 h-4" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 18 20">
39
+ <path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15.147 15.085a7.159 7.159 0 0 1-6.189 3.307A6.713 6.713 0 0 1 3.1 15.444c-2.679-4.513.287-8.737.888-9.548A4.373 4.373 0 0 0 5 1.608c1.287.953 6.445 3.218 5.537 10.5 1.5-1.122 2.706-3.01 2.853-6.14 1.433 1.049 3.993 5.395 1.757 9.117Z"/>
40
+ </svg>
9
41
  <% end %>
42
+ <div class="ms-3 text-sm font-normal"><%= msg %></div>
43
+ <button type="button"
44
+ class="ms-auto -mx-1.5 -my-1.5 bg-<%= color %>-50 text-<%= color %>-500 rounded-lg focus:ring-2 focus:ring-<%= color %>-400 p-1.5 hover:bg-<%= color %>-200 inline-flex items-center justify-center h-8 w-8 dark:bg-gray-800 dark:text-<%= color %>-400 dark:hover:bg-gray-700"
45
+ data-resource-dismiss-target="trigger"
46
+ aria-label="Close">
47
+ <span class="sr-only">Close</span>
48
+ <svg class="w-3 h-3" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 14 14">
49
+ <path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="m1 1 6 6m0 0 6 6M7 7l6-6M7 7l-6 6"/>
50
+ </svg>
51
+ </button>
52
+ </div>
53
+ <% end %>
@@ -1,26 +1,56 @@
1
- <div aria-live="polite" aria-atomic="true" class="position-relative" data-controller="toasts">
2
- <div class="toast-container top-0 end-0 p-3 ">
3
- <% flash.each do |type, msg| %>
4
- <%
5
- type = { alert: :danger, error: :danger, warning: :warning, success: :success }[type.to_sym] || :primary
6
- title = { danger: 'Error', warning: 'Warning', success: 'Success' }[type] || 'Info'
7
- icon = {
8
- danger: 'exclamation-triangle-fill',
9
- warning: 'exclamation-diamond',
10
- success: 'check-circle-fill'
11
- }[type] || 'exclamation-circle'
12
- %>
13
- <div class="toast text-bg-<%= type %>" role="alert" aria-live="assertive" aria-atomic="true" data-turbo-temporary>
14
- <div class="toast-header">
15
- <i class="bi bi-<%= icon %>"></i>&nbsp;
16
- <strong class="me-auto"><%= title %></strong>
17
- <small class="text-body-secondary"><%= timeago(DateTime.now) %></small>
18
- <button type="button" class="btn-close" data-bs-dismiss="toast" aria-label="Close"></button>
19
- </div>
20
- <div class="toast-body">
21
- <%= msg %>
22
- </div>
23
- </div>
1
+ <% flash.each do |type, msg| %>
2
+ <%
3
+ color = case type.to_sym
4
+ when :success
5
+ # text-green-500 bg-green-100 bg-green-800 text-green-200 bg-green-50 text-green-400 ring-green-400
6
+ "green"
7
+ when :warning
8
+ # text-yellow-500 bg-yellow-100 bg-yellow-800 text-yellow-200 bg-yellow-50 text-yellow-400 ring-yellow-400
9
+ "yellow"
10
+ when :alert, :danger, :error
11
+ # text-red-500 bg-red-100 bg-red-800 text-red-200 bg-red-50 text-red-400 ring-red-400
12
+ "red"
13
+ else
14
+ # text-blue-500 bg-blue-100 bg-blue-800 text-blue-200 bg-blue-50 text-blue-400 ring-blue-400
15
+ "blue"
16
+ end
17
+ %>
18
+
19
+ <div data-controller="resource-dismiss"
20
+ data-resource-dismiss-target="target"
21
+ data-resource-dismiss-after-value="6000"
22
+ class="fixed z-50 top-16 right-5 flex items-center w-full max-w-md p-4 text-gray-500 bg-<%= color %>-50 rounded-lg shadow dark:text-<%= color %>-400 dark:bg-gray-800"
23
+ role="alert">
24
+
25
+ <div class="inline-flex items-center justify-center flex-shrink-0 w-8 h-8 text-<%= color %>-500 bg-<%= color %>-100 rounded-lg dark:bg-<%= color %>-800 dark:text-<%= color %>-200">
26
+ <% case type.to_sym %>
27
+ <% when :success %>
28
+ <svg class="w-5 h-5" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" fill="currentColor" viewBox="0 0 20 20">
29
+ <path d="M10 .5a9.5 9.5 0 1 0 9.5 9.5A9.51 9.51 0 0 0 10 .5Zm3.707 8.207-4 4a1 1 0 0 1-1.414 0l-2-2a1 1 0 0 1 1.414-1.414L9 10.586l3.293-3.293a1 1 0 0 1 1.414 1.414Z"/>
30
+ </svg>
31
+ <% when :warning %>
32
+ <svg class="w-5 h-5" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" fill="currentColor" viewBox="0 0 20 20">
33
+ <path d="M10 .5a9.5 9.5 0 1 0 9.5 9.5A9.51 9.51 0 0 0 10 .5ZM10 15a1 1 0 1 1 0-2 1 1 0 0 1 0 2Zm1-4a1 1 0 0 1-2 0V6a1 1 0 0 1 2 0v5Z"/>
34
+ </svg>
35
+ <% when :alert, :danger, :error %>
36
+ <svg class="w-5 h-5" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" fill="currentColor" viewBox="0 0 20 20">
37
+ <path d="M10 .5a9.5 9.5 0 1 0 9.5 9.5A9.51 9.51 0 0 0 10 .5Zm3.707 11.793a1 1 0 1 1-1.414 1.414L10 11.414l-2.293 2.293a1 1 0 0 1-1.414-1.414L8.586 10 6.293 7.707a1 1 0 0 1 1.414-1.414L10 8.586l2.293-2.293a1 1 0 0 1 1.414 1.414L11.414 10l2.293 2.293Z"/>
38
+ </svg>
39
+ <% else %>
40
+ <svg class="w-4 h-4" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 18 20">
41
+ <path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15.147 15.085a7.159 7.159 0 0 1-6.189 3.307A6.713 6.713 0 0 1 3.1 15.444c-2.679-4.513.287-8.737.888-9.548A4.373 4.373 0 0 0 5 1.608c1.287.953 6.445 3.218 5.537 10.5 1.5-1.122 2.706-3.01 2.853-6.14 1.433 1.049 3.993 5.395 1.757 9.117Z"/>
42
+ </svg>
24
43
  <% end %>
25
44
  </div>
45
+ <div class="ms-3 text-sm font-normal"><%= msg %></div>
46
+ <button type="button"
47
+ class="ms-auto -mx-1.5 -my-1.5 bg-<%= color %>-50 text-<%= color %>-400 rounded-lg focus:ring-2 focus:ring-<%= color %>-400 p-1.5 hover:bg-<%= color %>-200 inline-flex items-center justify-center h-8 w-8 dark:text-<%= color %>-400 dark:bg-gray-800 dark:hover:bg-gray-700"
48
+ data-resource-dismiss-target="trigger"
49
+ aria-label="Close">
50
+ <span class="sr-only">Close</span>
51
+ <svg class="w-3 h-3" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 14 14">
52
+ <path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="m1 1 6 6m0 0 6 6M7 7l6-6M7 7l-6 6"/>
53
+ </svg>
54
+ </button>
26
55
  </div>
56
+ <% end %>