plutonium 0.15.5 → 0.15.6

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 (48) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/plutonium.css +1 -1
  3. data/app/assets/plutonium.ico +0 -0
  4. data/app/assets/plutonium.png +0 -0
  5. data/docs/.vitepress/config.ts +61 -0
  6. data/docs/.vitepress/theme/custom.css +61 -0
  7. data/docs/.vitepress/theme/index.ts +4 -0
  8. data/docs/api-examples.md +49 -0
  9. data/docs/guide/getting-started/authorization.md +296 -0
  10. data/docs/guide/getting-started/core-concepts.md +432 -0
  11. data/docs/guide/getting-started/index.md +18 -0
  12. data/docs/guide/getting-started/installation.md +269 -0
  13. data/docs/guide/getting-started/resources.md +254 -0
  14. data/docs/guide/what-is-plutonium.md +211 -0
  15. data/docs/index.md +43 -0
  16. data/docs/markdown-examples.md +85 -0
  17. data/docs/public/android-chrome-192x192.png +0 -0
  18. data/docs/public/android-chrome-512x512.png +0 -0
  19. data/docs/public/apple-touch-icon.png +0 -0
  20. data/docs/public/favicon-16x16.png +0 -0
  21. data/docs/public/favicon-32x32.png +0 -0
  22. data/docs/public/favicon.ico +0 -0
  23. data/docs/public/plutonium.png +0 -0
  24. data/docs/public/site.webmanifest +1 -0
  25. data/docs/public/templates/plutonium.rb +21 -0
  26. data/lib/generators/pu/core/assets/assets_generator.rb +2 -3
  27. data/lib/generators/pu/core/assets/templates/tailwind.config.js +2 -2
  28. data/lib/generators/pu/core/install/install_generator.rb +9 -1
  29. data/lib/generators/pu/core/install/templates/config/initializers/plutonium.rb +0 -1
  30. data/lib/plutonium/core/controllers/authorizable.rb +1 -1
  31. data/lib/plutonium/railtie.rb +0 -10
  32. data/lib/plutonium/resource/controllers/crud_actions.rb +1 -1
  33. data/lib/plutonium/resource/policy.rb +4 -5
  34. data/lib/plutonium/resource/register.rb +3 -0
  35. data/lib/plutonium/ui/action_button.rb +34 -19
  36. data/lib/plutonium/ui/form/resource.rb +2 -1
  37. data/lib/plutonium/ui/table/components/search_bar.rb +1 -1
  38. data/lib/plutonium/version.rb +1 -1
  39. data/package-lock.json +5767 -1851
  40. data/package.json +10 -4
  41. data/src/js/core.js +0 -1
  42. data/tailwind.options.js +89 -11
  43. metadata +27 -11
  44. data/app/assets/plutonium-original.png +0 -0
  45. data/app/assets/plutonium-white.png +0 -0
  46. data/public/plutonium-assets/fonts/bootstrap-icons.woff +0 -0
  47. data/public/plutonium-assets/fonts/bootstrap-icons.woff2 +0 -0
  48. /data/{templates → docs/public/templates}/base.rb +0 -0
@@ -9,7 +9,7 @@ module Plutonium
9
9
 
10
10
  included do
11
11
  authorize :user, through: :current_user
12
- authorize :scope, through: :entity_scope_for_authorize
12
+ authorize :entity_scope, through: :entity_scope_for_authorize
13
13
 
14
14
  helper_method :policy_for, :authorized_resource_scope
15
15
  end
@@ -53,10 +53,6 @@ module Plutonium
53
53
  extend_action_dispatch
54
54
  end
55
55
 
56
- initializer "plutonium.active_record_extensions" do
57
- extend_active_record
58
- end
59
-
60
56
  initializer "plutonium.phlexi_themes" do
61
57
  setup_phlexi_themes
62
58
  end
@@ -114,11 +110,5 @@ module Plutonium
114
110
  ActionDispatch::Routing::RouteSet.prepend Plutonium::Routing::RouteSetExtensions
115
111
  Rails::Engine.include Plutonium::Routing::ResourceRegistration
116
112
  end
117
-
118
- def extend_active_record
119
- ActiveSupport.on_load(:active_record) do
120
- include Plutonium::Resource::Record
121
- end
122
- end
123
113
  end
124
114
  end
@@ -148,7 +148,7 @@ module Plutonium
148
148
  end
149
149
 
150
150
  def redirect_url_after_destroy
151
- if (return_to = url_from(params[:return_to]))
151
+ if (return_to = url_from(params[:return_to])) && return_to != request.url
152
152
  return return_to
153
153
  end
154
154
 
@@ -7,13 +7,12 @@ module Plutonium
7
7
  # and to retrieve permitted attributes for these actions.
8
8
  class Policy < ActionPolicy::Base
9
9
  authorize :user, allow_nil: false
10
- authorize :scope, allow_nil: true
10
+ authorize :entity_scope, allow_nil: true
11
11
 
12
12
  relation_scope do |relation|
13
- if scope.present?
14
- relation = relation.associated_with(scope)
15
- end
16
- relation
13
+ next relation unless entity_scope
14
+
15
+ relation.associated_with(entity_scope)
17
16
  end
18
17
 
19
18
  # Sends a method and raises an error if the method is not implemented.
@@ -21,6 +21,9 @@ module Plutonium
21
21
  # @return [void]
22
22
  def register(resource)
23
23
  raise FrozenRegisterError, "Cannot modify frozen resource register" if @frozen
24
+ unless resource.include?(Plutonium::Resource::Record)
25
+ raise ArgumentError, "#{resource} must include Plutonium::Resource::Record before being registered"
26
+ end
24
27
 
25
28
  @resources.add(resource.to_s)
26
29
  end
@@ -80,7 +80,7 @@ module Plutonium
80
80
  if @variant == :table
81
81
  "h-4 w-4 mr-1"
82
82
  else
83
- "h-3.5 w-3.5 mr-2 -ml-1"
83
+ "h-3.5 w-3.5 -ml-1"
84
84
  end
85
85
  end
86
86
 
@@ -91,35 +91,50 @@ module Plutonium
91
91
  def color_classes
92
92
  case @action.color || @action.category.to_sym
93
93
  when :primary
94
- table_variant_class(
95
- "bg-primary-100 text-primary-700 hover:bg-primary-200 focus:ring-primary-300 dark:bg-primary-700 dark:text-primary-100 dark:hover:bg-primary-600 dark:focus:ring-primary-600",
96
- "bg-primary-700 text-white hover:bg-primary-800 focus:ring-primary-300 dark:bg-primary-600 dark:hover:bg-primary-700 dark:focus:ring-primary-800"
94
+ variant_class(
95
+ "bg-primary-700 text-white hover:bg-primary-800 focus:ring-primary-300 dark:bg-primary-600 dark:hover:bg-primary-700 dark:focus:ring-primary-800",
96
+ table: "bg-primary-100 text-primary-700 hover:bg-primary-200 focus:ring-primary-300 dark:bg-primary-700 dark:text-primary-100 dark:hover:bg-primary-600 dark:focus:ring-primary-600"
97
+ )
98
+ when :success
99
+ variant_class(
100
+ "bg-success-700 text-white hover:bg-success-800 focus:ring-success-300 dark:bg-success-600 dark:hover:bg-success-700 dark:focus:ring-success-800",
101
+ table: "bg-success-100 text-success-700 hover:bg-success-200 focus:ring-success-300 dark:bg-success-700 dark:text-success-100 dark:hover:bg-success-600 dark:focus:ring-success-600"
102
+ )
103
+ when :info
104
+ variant_class(
105
+ "bg-info-700 text-white hover:bg-info-800 focus:ring-info-300 dark:bg-info-600 dark:hover:bg-info-700 dark:focus:ring-info-800",
106
+ table: "bg-info-100 text-info-700 hover:bg-info-200 focus:ring-info-300 dark:bg-info-700 dark:text-info-100 dark:hover:bg-info-600 dark:focus:ring-info-600"
97
107
  )
98
108
  when :warning
99
- table_variant_class(
100
- "bg-yellow-100 text-yellow-700 hover:bg-yellow-200 focus:ring-yellow-300 dark:bg-yellow-700 dark:text-yellow-100 dark:hover:bg-yellow-600 dark:focus:ring-yellow-600",
101
- "bg-yellow-400 text-white hover:bg-yellow-500 focus:ring-yellow-300 dark:bg-yellow-600 dark:hover:bg-yellow-700 dark:focus:ring-yellow-800"
109
+ variant_class(
110
+ "bg-warning-700 text-white hover:bg-warning-800 focus:ring-warning-300 dark:bg-warning-600 dark:hover:bg-warning-700 dark:focus:ring-warning-800",
111
+ table: "bg-warning-100 text-warning-700 hover:bg-warning-200 focus:ring-warning-300 dark:bg-warning-700 dark:text-warning-100 dark:hover:bg-warning-600 dark:focus:ring-warning-600"
102
112
  )
103
113
  when :danger
104
- table_variant_class(
105
- "bg-red-100 text-red-700 hover:bg-red-200 focus:ring-red-300 dark:bg-red-700 dark:text-red-100 dark:hover:bg-red-600 dark:focus:ring-red-600",
106
- "bg-red-700 text-white hover:bg-red-800 focus:ring-red-300 dark:bg-red-600 dark:hover:bg-red-700 dark:focus:ring-red-900"
114
+ variant_class(
115
+ "bg-danger-700 text-white hover:bg-danger-800 focus:ring-danger-300 dark:bg-danger-600 dark:hover:bg-danger-700 dark:focus:ring-danger-800",
116
+ table: "bg-danger-100 text-danger-700 hover:bg-danger-200 focus:ring-danger-300 dark:bg-danger-700 dark:text-danger-100 dark:hover:bg-danger-600 dark:focus:ring-danger-600"
107
117
  )
108
- when :success
109
- table_variant_class(
110
- "bg-green-100 text-green-700 hover:bg-green-200 focus:ring-green-300 dark:bg-green-700 dark:text-green-100 dark:hover:bg-green-600 dark:focus:ring-green-600",
111
- "bg-green-700 text-white hover:bg-green-800 focus:ring-green-300 dark:bg-green-600 dark:hover:bg-green-700 dark:focus:ring-green-800"
118
+ when :accent
119
+ variant_class(
120
+ "bg-accent-700 text-white hover:bg-accent-800 focus:ring-accent-300 dark:bg-accent-600 dark:hover:bg-accent-700 dark:focus:ring-accent-800",
121
+ table: "bg-accent-100 text-accent-700 hover:bg-accent-200 focus:ring-accent-300 dark:bg-accent-700 dark:text-accent-100 dark:hover:bg-accent-600 dark:focus:ring-accent-600"
112
122
  )
113
123
  else
114
- table_variant_class(
115
- "bg-gray-100 text-gray-700 hover:bg-gray-200 focus:ring-gray-300 dark:bg-gray-700 dark:text-gray-100 dark:hover:bg-gray-600 dark:focus:ring-gray-600",
116
- "border border-gray-200 bg-white text-gray-900 hover:bg-gray-100 hover:text-primary-700 focus:z-10 focus:ring-gray-100 dark:border-gray-600 dark:bg-gray-800 dark:text-gray-200 dark:hover:bg-gray-700 dark:hover:text-white dark:focus:ring-gray-700"
124
+ variant_class(
125
+ "bg-secondary-700 text-white hover:bg-secondary-800 focus:ring-secondary-300 dark:bg-secondary-600 dark:hover:bg-secondary-700 dark:focus:ring-secondary-800",
126
+ table: "bg-secondary-100 text-secondary-700 hover:bg-secondary-200 focus:ring-secondary-300 dark:bg-secondary-700 dark:text-secondary-100 dark:hover:bg-secondary-600 dark:focus:ring-secondary-600"
117
127
  )
118
128
  end
119
129
  end
120
130
 
121
- def table_variant_class(table_class, default_class)
122
- (@variant == :table) ? table_class : default_class
131
+ def variant_class(default, table:)
132
+ case @variant
133
+ when :table
134
+ table
135
+ else
136
+ default
137
+ end
123
138
  end
124
139
  end
125
140
  end
@@ -57,11 +57,12 @@ module Plutonium
57
57
 
58
58
  field_options = field_options.except(:as)
59
59
  wrapper_options = input_options.except(:tag, :as)
60
- if !wrapper_options[:class] || wrapper_options[:class].include?("col-span")
60
+ if !wrapper_options[:class] || !wrapper_options[:class].include?("col-span")
61
61
  # temp hack to allow col span overrides
62
62
  # TODO: remove once we complete theming, which will support merges
63
63
  wrapper_options[:class] = tokens("col-span-full", wrapper_options[:class])
64
64
  end
65
+
65
66
  render field(name, **field_options).wrapped(**wrapper_options) do |f|
66
67
  render tag_block.call(f)
67
68
  end
@@ -16,7 +16,7 @@ module Plutonium
16
16
  private
17
17
 
18
18
  def render?
19
- current_query_object.filter_definitions.present? && current_policy.allowed_to?(:search?)
19
+ (current_query_object.search_filter.present? || current_query_object.filter_definitions.present?) && current_policy.allowed_to?(:search?)
20
20
  end
21
21
  end
22
22
  end
@@ -1,5 +1,5 @@
1
1
  module Plutonium
2
- VERSION = "0.15.5"
2
+ VERSION = "0.15.6"
3
3
  NEXT_MAJOR_VERSION = VERSION.split(".").tap { |v|
4
4
  v[1] = v[1].to_i + 1
5
5
  v[2] = 0