plutonium 0.20.1 → 0.20.3

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e4bef64109c5d7a4f0806307b70f4506a4e39df4b9599b3dca7e93735d6d9695
4
- data.tar.gz: e08c935a33e869842f9299b401a451ac5f008f5c3bad349f64d12ec15740fcfd
3
+ metadata.gz: 545bfd12db25550638b5a2e1bd63f238490416df72cb799385561c28792684a4
4
+ data.tar.gz: 8658bb44139a602f1b8adcd66a888ee4c98a708bcec45e6aafc4afea328438e8
5
5
  SHA512:
6
- metadata.gz: 330f168dd3d9ea13d1666a47d8b54ff4aac2154d8a5ac90d48e66a553f2b1a19cc467c94af482528ee9ed31d4828a6e376306c53443411ac31b64665c70e5945
7
- data.tar.gz: c00da81b08def50023b1d09c4e9aa347f26db6bc766153c9d507ea363f9c9bf371787002a644fe6467305f5523152ceaa7cd2efa176ae06838b9412025e9a58b
6
+ metadata.gz: d0e4767510da8df48a19ad7450c377afa7b138b32dc04bdbc5de076d0600555b5a811df2b9161b5cede2b2ffad03c8ffd5faf3512cbaabfafc537e5abf9691dd
7
+ data.tar.gz: 48205cfc48b3ecac7b073ccd05629f839489ae9a923a1f79961a9cf1cf863b8c6e3b74344e6418ec9bd67b2dfed6a8673bf5768d755d3af28b1d287282e58440
@@ -18,13 +18,13 @@ module.exports = {
18
18
  }
19
19
  })),
20
20
  theme: plutoniumTailwindConfig.merge(
21
+ plutoniumTailwindConfig.theme,
21
22
  {
23
+ // define your custom theme here
22
24
  },
23
- plutoniumTailwindConfig.theme
24
25
  ),
25
26
  content: [
26
27
  `${__dirname}/app/**/*.{erb,haml,html,slim,rb}`,
27
- `${__dirname}/app/assets/stylesheets/**/*.css`,
28
28
  `${__dirname}/app/javascript/**/*.js`,
29
29
  `${__dirname}/packages/**/app/**/*.{erb,haml,html,slim,rb}`,
30
30
  ].concat(plutoniumTailwindConfig.content),
@@ -93,6 +93,9 @@ module Plutonium
93
93
  case options
94
94
  when RouteOptions
95
95
  options
96
+ when Array
97
+ kwargs = options.extract_options!
98
+ RouteOptions.new(*options, **kwargs)
96
99
  when Hash
97
100
  RouteOptions.new(**options)
98
101
  when nil
@@ -17,7 +17,7 @@ module Plutonium
17
17
 
18
18
  helper Plutonium::Helpers
19
19
  helper_method :make_page_title, :resource_url_for,
20
- :resource_url_args_for, :root_path, :app_name
20
+ :resource_url_args_for, :root_path, :app_name, :route_options_to_url
21
21
 
22
22
  append_view_path File.expand_path("app/views", Plutonium.root)
23
23
  layout -> { turbo_frame_request? ? false : "resource" }
@@ -111,6 +111,33 @@ module Plutonium
111
111
  def registered_resources
112
112
  current_engine.resource_register.resources
113
113
  end
114
+
115
+ # Converts RouteOptions into a URL using the appropriate URL resolver.
116
+ #
117
+ # This method takes a RouteOptions object and generates a URL based on the url_resolver
118
+ # specified within the RouteOptions. It supports different resolution strategies:
119
+ # - If the route_options responds to :to_proc, executes it as a Proc in the current instance context
120
+ # - For :resource_url_for resolver, generates a URL using the provided subject
121
+ # - For :url_for resolver, generates a URL using only the url_options from route_options
122
+ #
123
+ # @param [RouteOptions, #to_proc] route_options The RouteOptions object or callable to convert to a URL
124
+ # @param [Object] subject The subject to use when generating URLs with :resource_url_for
125
+ # @return [String] The generated URL
126
+ # @raise [NotImplementedError] If an unsupported url_resolver is specified
127
+ def route_options_to_url(route_options, subject = nil)
128
+ url_resolver = route_options.url_resolver
129
+
130
+ if url_resolver == :resource_url_for
131
+ raise ArgumentError, "subject is required when url_resolver is: :resource_url_for" unless subject
132
+ resource_url_for(subject, *route_options.url_args, **route_options.url_options)
133
+ elsif url_resolver == :url_for
134
+ url_for(**route_options.url_options)
135
+ elsif url_resolver.respond_to?(:to_proc)
136
+ instance_exec(subject, &url_resolver)
137
+ else
138
+ raise NotImplementedError, "url_resolver: #{url_resolver}"
139
+ end
140
+ end
114
141
  end
115
142
  end
116
143
  end
@@ -44,6 +44,19 @@ module Plutonium
44
44
  value & check == check
45
45
  end
46
46
 
47
+ # Sets the specified flags in the given value.
48
+ #
49
+ # @param value [Integer] The original value to modify.
50
+ # @param flags [Array<Symbol, String>] The flags to set.
51
+ # @return [Integer] A new value with the specified flags set.
52
+ # @example
53
+ # flags.set!(2, :read, :execute) # => 6
54
+ def set!(value, *flags)
55
+ normalized_flags = normalize_flags(flags)
56
+ bits_to_set = bits(*normalized_flags)
57
+ value | bits_to_set
58
+ end
59
+
47
60
  # Extracts the flags that are set in the given value.
48
61
  #
49
62
  # @param value [Integer] The value to extract flags from.
@@ -30,6 +30,7 @@ module Plutonium
30
30
  :resource_name_plural,
31
31
  :display_name_of,
32
32
  :resource_url_for,
33
+ :route_options_to_url,
33
34
  :current_user,
34
35
  :current_parent,
35
36
  :current_definition,
@@ -40,7 +40,8 @@ module Plutonium
40
40
 
41
41
  def render_actions
42
42
  @actions.each do |action|
43
- url = resource_url_for(resource_record? || resource_class, *action.route_options.url_args, **action.route_options.url_options)
43
+ subject = resource_record? || resource_class
44
+ url = route_options_to_url(action.route_options, subject)
44
45
  ActionButton(action, url:)
45
46
  end
46
47
  end
@@ -35,7 +35,7 @@ module Plutonium
35
35
  EmptyCard("No #{resource_name_plural(resource_class)} match your query") {
36
36
  action = resource_definition.defined_actions[:new]
37
37
  if action&.permitted_by?(current_policy)
38
- url = resource_url_for(resource_class, *action.route_options.url_args, **action.route_options.url_options)
38
+ url = route_options_to_url(action.route_options, resource_class)
39
39
  ActionButton(action, url:)
40
40
  end
41
41
  }
@@ -85,14 +85,7 @@ module Plutonium
85
85
  .select { |k, a| a.collection_record_action? && policy.allowed_to?(:"#{k}?") }
86
86
  .values
87
87
  .each do |action|
88
- # TODO: extract this
89
- url = case action.route_options.url_resolver
90
- when :resource_url_for
91
- resource_url_for(record, *action.route_options.url_args, **action.route_options.url_options)
92
- else
93
- raise NotImplementedError, "url_resolver: #{action.route_options.url_resolver}"
94
- end
95
-
88
+ url = route_options_to_url(action.route_options, record)
96
89
  ActionButton(action, url:, variant: :table)
97
90
  end
98
91
  end
@@ -1,5 +1,5 @@
1
1
  module Plutonium
2
- VERSION = "0.20.1"
2
+ VERSION = "0.20.3"
3
3
  NEXT_MAJOR_VERSION = VERSION.split(".").tap { |v|
4
4
  v[1] = v[1].to_i + 1
5
5
  v[2] = 0
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: plutonium
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.20.1
4
+ version: 0.20.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stefan Froelich
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2025-03-03 00:00:00.000000000 Z
11
+ date: 2025-03-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: zeitwerk