five-two-nw-olivander 0.2.0.33 → 0.2.0.35

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: a2488764b16b7943eac6350511c32575af3e60d154eac16a3cd2b834f849fdfc
4
- data.tar.gz: 56f377cfc38c89759ff1047036217b8e6f536b9f97081ff34ea5200bfeacb335
3
+ metadata.gz: 20309038b9a2b17f545f6c06658c87f41fc20a565b8d39b6c079894add49c644
4
+ data.tar.gz: 5c6429e2fdd1204b7324b36a7c4cd118ea136229b23a56f9ded5cab92fab801a
5
5
  SHA512:
6
- metadata.gz: dcbd6cf9861cfbfa95455a2f38ac26c9273ca5f46459602f87770295fff0b2c427d1343245e6204481765e71115449a5dbf8db3467b7edb256167d4443749b45
7
- data.tar.gz: 874a8a647b8bc5e860b79793775ee9778a918dda189367efa9885c8e9948370a1f5a41f0aa4b082259a192d11fe2f3404a9192ccfc1da21f4626386d2a14bfe3
6
+ metadata.gz: 248d5ca6b004d3f76c47b0a70e5268ec26970df86e7a0e45ba2879cf07468b0f9c71fb045321ccd76c7dea764252fc40a865de5a19a3b14c1f657045f6dedb39
7
+ data.tar.gz: 884dd31cca4c245d24b227ca9ae2d7854d36059df578a70bb1325f76758ad87a1eb0b987273db88757d4e332028d277b5d659593dacc6f6b851762c6454f5663
@@ -4,14 +4,15 @@
4
4
  - rfg.sections.each do |section|
5
5
  .row
6
6
  - section.fields.each do |field|
7
+ - label = field_label_for(@resource.class, field.sym)
7
8
  %div{ class: section.column_class }
8
9
  - if association?(field)
9
10
  - collection = collection_for(field)
10
11
  - if one_through?(field)
11
- = @f.input field.sym, collection: [collection].flatten, disabled: !field.editable, input_html: { data: association_data_hash_for(field) }, selected: collection
12
+ = @f.input field.sym, label: label, collection: [collection].flatten, disabled: !field.editable, input_html: { data: association_data_hash_for(field) }, selected: collection
12
13
  - else
13
- = @f.association field.sym, collection: [collection].flatten, disabled: !field.editable, input_html: { data: association_data_hash_for(field) }
14
+ = @f.association field.sym, label: label, collection: [collection].flatten, disabled: !field.editable, input_html: { data: association_data_hash_for(field) }
14
15
  - elsif boolean?(field)
15
- = @f.input field.sym, disabled: !field.editable, as: field.type.to_sym, input_html: { data: input_data_hash_for(field) }
16
+ = @f.input field.sym, label: label, disabled: !field.editable, as: field.type.to_sym, input_html: { data: input_data_hash_for(field) }
16
17
  - else
17
- = @f.input field.sym, disabled: !field.editable, as: field.type.to_sym, picker_options: input_picker_options_for(field), input_html: { rows: 10, data: input_data_hash_for(field) }
18
+ = @f.input field.sym, label: label, disabled: !field.editable, as: field.type.to_sym, picker_options: input_picker_options_for(field), input_html: { rows: 10, data: input_data_hash_for(field) }
@@ -2,6 +2,7 @@
2
2
 
3
3
  class Olivander::Components::ResourceFormComponent < ViewComponent::Base
4
4
  delegate :resource_field_group_label, to: :helpers
5
+ delegate :field_label_for, to: :helpers
5
6
 
6
7
  def initialize(resource, form_builder)
7
8
  @resource = resource
@@ -16,7 +17,8 @@ class Olivander::Components::ResourceFormComponent < ViewComponent::Base
16
17
  def association_data_hash_for(field)
17
18
  {
18
19
  collection_path: collection_path_for(field),
19
- controller: "association-#{@resource.class.name.underscore.dasherize.gsub('/', '-')}-#{field.sym} input-control-association",
20
+ controller: "association-#{@resource.class.name.underscore.dasherize.gsub('/',
21
+ '-')}-#{field.sym} input-control-association",
20
22
  taggable: taggable?(field),
21
23
  tag_field_name: tag_field_name(field)
22
24
  }
@@ -24,7 +26,8 @@ class Olivander::Components::ResourceFormComponent < ViewComponent::Base
24
26
 
25
27
  def input_data_hash_for(field)
26
28
  {
27
- controller: "input-#{@resource.class.name.underscore.dasherize.gsub('/', '-')}-#{field.sym} input-control-#{field.type}",
29
+ controller: "input-#{@resource.class.name.underscore.dasherize.gsub('/',
30
+ '-')}-#{field.sym} input-control-#{field.type}"
28
31
  }
29
32
  end
30
33
 
@@ -53,11 +56,9 @@ class Olivander::Components::ResourceFormComponent < ViewComponent::Base
53
56
  end
54
57
 
55
58
  def collection_path_for(field)
56
- begin
57
- polymorphic_path(@resource.class.reflect_on_association(field.sym).klass, format: :json)
58
- rescue
59
- ''
60
- end
59
+ polymorphic_path(@resource.class.reflect_on_association(field.sym).klass, format: :json)
60
+ rescue StandardError
61
+ ''
61
62
  end
62
63
 
63
64
  def association?(field)
@@ -2,15 +2,16 @@ module Olivander
2
2
  module ApplicationHelper
3
3
  def chart_column_class_num(label, count, min)
4
4
  return "col-#{label}-#{min}" if count >= 12
5
+
5
6
  modded = count % 12
6
7
  divisor = modded.zero? ? 1 : modded
7
- "col-#{label}-#{[12/divisor, min].max}"
8
-
8
+ "col-#{label}-#{[12 / divisor, min].max}"
9
+
9
10
  divisor = count
10
- result = 12/divisor
11
+ result = 12 / divisor
11
12
  while result < min
12
- divisor = divisor/2
13
- result = 12/divisor
13
+ divisor /= 2
14
+ result = 12 / divisor
14
15
  end
15
16
  "col-#{label}-#{result}"
16
17
  end
@@ -35,21 +36,20 @@ module Olivander
35
36
  end
36
37
 
37
38
  def authorized_resource_actions(resource, for_action: :show)
38
- raw_name = resource.is_a?(Class) ? resource.name : resource.class.name
39
+ action_resource = action_resource_for(resource)
40
+ raw_name = action_resource.name
39
41
  plural_name = raw_name.demodulize.underscore.pluralize
40
42
  routed_resource = Olivander::CurrentContext.application_context.route_builder.resources[plural_name.to_sym]
41
43
  return [] if routed_resource.nil?
42
44
 
43
45
  actions = if resource.is_a?(Class)
44
46
  routed_resource.unpersisted_crud_actions | routed_resource.collection_actions.reject(&:crud_action)
47
+ elsif resource.persisted?
48
+ routed_resource.persisted_crud_actions | routed_resource.member_actions.reject(&:crud_action)
45
49
  else
46
- if resource.persisted?
47
- routed_resource.persisted_crud_actions | routed_resource.member_actions.reject(&:crud_action)
48
- else
49
- []
50
- end
50
+ []
51
51
  end
52
- actions = actions.select{ |a| authorized_resource_action?(a.sym, resource, for_action) }
52
+ actions = actions.select { |a| authorized_resource_action?(a.sym, action_resource, for_action) }
53
53
  preferred = %i[show edit destroy]
54
54
  [].tap do |arr|
55
55
  preferred.each do |p|
@@ -57,12 +57,17 @@ module Olivander
57
57
  arr << a if a.sym == p
58
58
  end
59
59
  end
60
- actions.reject{ |x| preferred.include?(x.sym) }.each do |a|
60
+ actions.reject { |x| preferred.include?(x.sym) }.each do |a|
61
61
  arr << a
62
62
  end
63
63
  end
64
64
  end
65
65
 
66
+ def action_resource_for(resource)
67
+ klazz = resource.is_a?(Class) ? resource : resource.class
68
+ klazz.respond_to?(:action_resource) ? klazz.action_resource : klazz
69
+ end
70
+
66
71
  def authorized_resource_action?(action, resource, except = nil)
67
72
  return false if action == except
68
73
 
@@ -70,12 +75,15 @@ module Olivander
70
75
  end
71
76
 
72
77
  def resource_form_actions(resource, for_action: :show)
73
- render partial: 'resource_form_actions', locals: { actions: authorized_resource_actions(resource, for_action: for_action).select(&:show_in_form) }
78
+ render partial: 'resource_form_actions',
79
+ locals: { actions: authorized_resource_actions(resource, for_action: for_action).select(&:show_in_form) }
74
80
  end
75
81
 
76
82
  def resource_form_action_tooltip(resource, action)
77
83
  key = resource.class.name.underscore
78
- return O18n.t("activerecord.actions.#{key}.#{action}-tooltip") if I18n.exists?("activerecord.actions.#{key}.#{action}-tooltip")
84
+ if I18n.exists?("activerecord.actions.#{key}.#{action}-tooltip")
85
+ return O18n.t("activerecord.actions.#{key}.#{action}-tooltip")
86
+ end
79
87
  return O18n.t("activerecord.actions.#{action}-tooltip") if I18n.exists?("activerecord.actions.#{action}-tooltip")
80
88
 
81
89
  action.to_s.titleize
@@ -91,7 +99,9 @@ module Olivander
91
99
 
92
100
  def resource_form_action_icon(resource, action)
93
101
  key = resource.class.name.underscore
94
- return O18n.t("activerecord.actions.#{key}.#{action}-icon") if I18n.exists?("activerecord.actions.#{key}.#{action}-icon")
102
+ if I18n.exists?("activerecord.actions.#{key}.#{action}-icon")
103
+ return O18n.t("activerecord.actions.#{key}.#{action}-icon")
104
+ end
95
105
  return O18n.t("activerecord.actions.#{action}-icon") if I18n.exists?("activerecord.actions.#{action}-icon")
96
106
 
97
107
  action.to_s.titleize
@@ -111,7 +121,7 @@ module Olivander
111
121
  end
112
122
 
113
123
  def resource_attributes(resource, effective_resource)
114
- er_attributes = effective_resource&.model_attributes&.collect{ |x| x[0] }
124
+ er_attributes = effective_resource&.model_attributes&.collect { |x| x[0] }
115
125
  return er_attributes if er_attributes.present? && er_attributes.size.positive?
116
126
 
117
127
  resource.auto_form_attributes
@@ -119,7 +129,6 @@ module Olivander
119
129
 
120
130
  def render_optional_partial(partial, locals: {})
121
131
  render partial: partial, locals: locals
122
-
123
132
  rescue ActionView::MissingTemplate
124
133
  Rails.logger.debug "did not find partial: #{partial}"
125
134
  nil
@@ -138,7 +147,9 @@ module Olivander
138
147
  end
139
148
 
140
149
  def sidebar_context_name
141
- [Olivander::CurrentContext.application_context.name, sidebar_context_suffix&.upcase].reject{ |x| x.blank? or x == 'PRODUCTION' }.join(' ')
150
+ [Olivander::CurrentContext.application_context.name, sidebar_context_suffix&.upcase].reject do |x|
151
+ x.blank? or x == 'PRODUCTION'
152
+ end.join(' ')
142
153
  end
143
154
 
144
155
  def sidebar_context_suffix
@@ -166,31 +177,31 @@ module Olivander
166
177
  favicon_link_tag(image_path(favicon_path))
167
178
  end
168
179
 
169
- def flash_class key
180
+ def flash_class(key)
170
181
  case key
171
- when "error"
172
- "danger"
173
- when "notice"
174
- "info"
175
- when "alert"
176
- "danger"
182
+ when 'error'
183
+ 'danger'
184
+ when 'notice'
185
+ 'info'
186
+ when 'alert'
187
+ 'danger'
177
188
  else
178
189
  key
179
190
  end
180
191
  end
181
192
 
182
- def flash_icon key
193
+ def flash_icon(key)
183
194
  case key
184
- when "error"
185
- "fas fa-exclamation-circle"
186
- when "notice"
187
- "fas fa-info-circle"
188
- when "alert"
189
- "fas fa-info-circle"
190
- when "success"
191
- "fas fa-check-circle"
195
+ when 'error'
196
+ 'fas fa-exclamation-circle'
197
+ when 'notice'
198
+ 'fas fa-info-circle'
199
+ when 'alert'
200
+ 'fas fa-info-circle'
201
+ when 'success'
202
+ 'fas fa-check-circle'
192
203
  else
193
- "fas fa-question-circle"
204
+ 'fas fa-question-circle'
194
205
  end
195
206
  end
196
207
 
@@ -209,7 +220,7 @@ module Olivander
209
220
  builder.footer_buttons.call
210
221
  end
211
222
  end
212
- end
223
+ end
213
224
  end
214
225
  end
215
226
  end
data/lib/o18n.rb CHANGED
@@ -6,13 +6,13 @@ class O18n
6
6
 
7
7
  def self.t(*args, **kwargs)
8
8
  value = I18n.t(*args, **kwargs)
9
- value.gsub(ENV_REGEX) {
10
- envar = ENV[$1]
11
- unless envar.blank?
12
- I18n.exists?(envar) ? I18n.t(envar) : envar
9
+ value.gsub(ENV_REGEX) do
10
+ envar = ENV[Regexp.last_match(1)]
11
+ if envar.blank?
12
+ Regexp.last_match(1).titleize
13
13
  else
14
- $1.titleize
14
+ I18n.exists?(envar) ? I18n.t(envar) : envar
15
15
  end
16
- }
16
+ end
17
17
  end
18
18
  end
@@ -2,5 +2,5 @@
2
2
 
3
3
  # needed for gem
4
4
  module Olivander
5
- VERSION = '0.2.0.33'
5
+ VERSION = '0.2.0.35'
6
6
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: five-two-nw-olivander
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0.33
4
+ version: 0.2.0.35
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eric Dennis
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-10-04 00:00:00.000000000 Z
11
+ date: 2024-10-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: chartkick