compony 0.5.2 → 0.5.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (65) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +8 -0
  3. data/README.md +2 -0
  4. data/VERSION +1 -1
  5. data/compony.gemspec +3 -3
  6. data/doc/ComponentGenerator.html +1 -1
  7. data/doc/Components.html +1 -1
  8. data/doc/ComponentsGenerator.html +1 -1
  9. data/doc/Compony/Component.html +1 -1
  10. data/doc/Compony/ComponentMixins/Default/Labelling.html +1 -1
  11. data/doc/Compony/ComponentMixins/Default/Standalone/ResourcefulVerbDsl.html +1 -1
  12. data/doc/Compony/ComponentMixins/Default/Standalone/StandaloneDsl.html +1 -1
  13. data/doc/Compony/ComponentMixins/Default/Standalone/VerbDsl.html +1 -1
  14. data/doc/Compony/ComponentMixins/Default/Standalone.html +1 -1
  15. data/doc/Compony/ComponentMixins/Default.html +1 -1
  16. data/doc/Compony/ComponentMixins/Resourceful.html +1 -1
  17. data/doc/Compony/ComponentMixins.html +1 -1
  18. data/doc/Compony/Components/Button.html +9 -5
  19. data/doc/Compony/Components/Destroy.html +1 -1
  20. data/doc/Compony/Components/Edit.html +1 -1
  21. data/doc/Compony/Components/Form.html +146 -75
  22. data/doc/Compony/Components/New.html +1 -1
  23. data/doc/Compony/Components/WithForm.html +1 -1
  24. data/doc/Compony/Components.html +1 -1
  25. data/doc/Compony/ControllerMixin.html +1 -1
  26. data/doc/Compony/Engine.html +1 -1
  27. data/doc/Compony/MethodAccessibleHash.html +1 -1
  28. data/doc/Compony/ModelFields/Anchormodel.html +1 -1
  29. data/doc/Compony/ModelFields/Association.html +1 -1
  30. data/doc/Compony/ModelFields/Attachment.html +1 -1
  31. data/doc/Compony/ModelFields/Base.html +1 -1
  32. data/doc/Compony/ModelFields/Boolean.html +1 -1
  33. data/doc/Compony/ModelFields/Color.html +1 -1
  34. data/doc/Compony/ModelFields/Currency.html +1 -1
  35. data/doc/Compony/ModelFields/Date.html +1 -1
  36. data/doc/Compony/ModelFields/Datetime.html +1 -1
  37. data/doc/Compony/ModelFields/Decimal.html +1 -1
  38. data/doc/Compony/ModelFields/Email.html +1 -1
  39. data/doc/Compony/ModelFields/Float.html +1 -1
  40. data/doc/Compony/ModelFields/Integer.html +1 -1
  41. data/doc/Compony/ModelFields/Percentage.html +1 -1
  42. data/doc/Compony/ModelFields/Phone.html +1 -1
  43. data/doc/Compony/ModelFields/RichText.html +1 -1
  44. data/doc/Compony/ModelFields/String.html +1 -1
  45. data/doc/Compony/ModelFields/Text.html +1 -1
  46. data/doc/Compony/ModelFields/Time.html +1 -1
  47. data/doc/Compony/ModelFields/Url.html +1 -1
  48. data/doc/Compony/ModelFields.html +1 -1
  49. data/doc/Compony/ModelMixin.html +1 -1
  50. data/doc/Compony/NaturalOrdering.html +1 -1
  51. data/doc/Compony/RequestContext.html +1 -1
  52. data/doc/Compony/Version.html +1 -1
  53. data/doc/Compony/ViewHelpers.html +30 -12
  54. data/doc/Compony.html +2 -2
  55. data/doc/ComponyController.html +1 -1
  56. data/doc/_index.html +1 -1
  57. data/doc/file.README.html +4 -1
  58. data/doc/index.html +4 -1
  59. data/doc/method_list.html +147 -139
  60. data/doc/top-level-namespace.html +1 -1
  61. data/lib/compony/components/button.rb +5 -3
  62. data/lib/compony/components/form.rb +9 -1
  63. data/lib/compony/view_helpers.rb +12 -4
  64. data/lib/compony.rb +1 -1
  65. metadata +2 -2
@@ -102,7 +102,7 @@
102
102
  </div>
103
103
 
104
104
  <div id="footer">
105
- Generated on Wed Nov 20 10:54:24 2024 by
105
+ Generated on Fri Dec 20 13:46:32 2024 by
106
106
  <a href="https://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
107
107
  0.9.37 (ruby-3.3.5).
108
108
  </div>
@@ -7,7 +7,7 @@ module Compony
7
7
 
8
8
  # path: If given a block, it will be evaluated in the helpers context when rendering
9
9
  # enabled: If given a block, it will be evaluated in the helpers context when rendering
10
- def initialize(*, label: nil, path: nil, method: nil, type: nil, enabled: nil, visible: nil, title: nil, **, &)
10
+ def initialize(*, label: nil, path: nil, method: nil, type: nil, enabled: nil, visible: nil, title: nil, button_params: nil, value: nil, **, &)
11
11
  @label = label || Compony.button_defaults[:label]
12
12
  @type = type&.to_sym || Compony.button_defaults[:type] || :button
13
13
  @path = path || Compony.button_defaults[:path] || 'javascript:void(0)'
@@ -23,6 +23,8 @@ module Compony
23
23
  @visible = Compony.button_defaults[:visible] if @visible.nil?
24
24
  @visible = true if @visible.nil?
25
25
  @title = title || Compony.button_defaults[:title]
26
+ @button_params = button_params
27
+ @value = value
26
28
 
27
29
  fail "Unsupported button type #{@type}, use on of: #{SUPPORTED_TYPES.inspect}" unless SUPPORTED_TYPES.include?(@type)
28
30
 
@@ -47,9 +49,9 @@ module Compony
47
49
  if @visible
48
50
  case @type
49
51
  when :button
50
- concat button_to(@label, @path, method: @method, disabled: !@enabled, title: @title)
52
+ concat button_to(@label, @path, method: @method, disabled: !@enabled, title: @title, params: @button_params)
51
53
  when :submit
52
- concat button_tag(@label, type: :submit, disabled: !@enabled, title: @title)
54
+ concat button_tag(@label, type: :submit, disabled: !@enabled, title: @title, value: @value)
53
55
  end
54
56
  end
55
57
  end
@@ -3,9 +3,10 @@ module Compony
3
3
  # @api description
4
4
  # This component is used for the _form partial in the Rails paradigm.
5
5
  class Form < Component
6
- def initialize(*args, cancancan_action: :missing, **kwargs)
6
+ def initialize(*args, cancancan_action: :missing, disabled: false, **kwargs)
7
7
  @schema_lines_for_data = [] # Array of procs taking data returning a Schemacop proc
8
8
  @cancancan_action = cancancan_action
9
+ @form_disabled = disabled
9
10
  super
10
11
  end
11
12
 
@@ -98,6 +99,8 @@ module Compony
98
99
  fail("The `field` method may only be called inside `form_fields` for #{inspect}.") unless @simpleform
99
100
  name = name.to_sym
100
101
 
102
+ input_opts.merge!(disabled: true) if @form_disabled
103
+
101
104
  # Check per-field authorization
102
105
  if @cancancan_action.present? && @controller.current_ability.permitted_attributes(@cancancan_action, @simpleform.object).exclude?(name)
103
106
  Rails.logger.debug do
@@ -155,6 +158,11 @@ module Compony
155
158
  Compony::ModelFields::Anchormodel.collect(...)
156
159
  end
157
160
 
161
+ # DSL method, disables all inputs
162
+ def disable!
163
+ @form_disabled = true
164
+ end
165
+
158
166
  protected
159
167
 
160
168
  # DSL method, adds a new line to the schema whitelisting a single param inside the schema's wrapper
@@ -19,11 +19,19 @@ module Compony
19
19
  # @param link_args [Array] Positional arguments that will be passed to the Rails `link_to` helper
20
20
  # @param label_opts [Hash] Options hash that will be passed to the label method (see {Compony::ComponentMixins::Default::Labelling#label})
21
21
  # @param link_kwargs [Hash] Named arguments that will be passed to the Rails `link_to` helper
22
- def compony_link(comp_name_or_cst, model_or_family_name_or_cst, *link_args, label_opts: {}, **link_kwargs)
22
+ def compony_link(comp_name_or_cst_or_class, model_or_family_name_or_cst = nil, *link_args, label_opts: {}, params: {}, standalone_name: nil, **link_kwargs)
23
23
  model = model_or_family_name_or_cst.respond_to?(:model_name) ? model_or_family_name_or_cst : nil
24
- comp = Compony.comp_class_for!(comp_name_or_cst, model_or_family_name_or_cst).new(data: model)
25
- return unless comp.standalone_access_permitted_for?(self)
26
- return helpers.link_to(comp.label(model, **label_opts), Compony.path(comp.comp_name, comp.family_name, model), *link_args, **link_kwargs)
24
+ if comp_name_or_cst_or_class.is_a?(Class) && (comp_name_or_cst_or_class <= Compony::Component)
25
+ target_comp_instance = comp_name_or_cst_or_class.new(data: model)
26
+ else
27
+ target_comp_instance = Compony.comp_class_for!(comp_name_or_cst_or_class, model_or_family_name_or_cst).new(data: model)
28
+ end
29
+ return unless target_comp_instance.standalone_access_permitted_for?(self, standalone_name:)
30
+ return helpers.link_to(
31
+ target_comp_instance.label(model, **label_opts),
32
+ Compony.path(target_comp_instance.comp_name, target_comp_instance.family_name, model, standalone_name:, **params),
33
+ *link_args, **link_kwargs
34
+ )
27
35
  end
28
36
 
29
37
  # Given a component and a family/model, this instanciates and renders a button component.
data/lib/compony.rb CHANGED
@@ -198,7 +198,7 @@ module Compony
198
198
  color: target_comp_instance.color,
199
199
  path: Compony.path(target_comp_instance.comp_name, target_comp_instance.family_name, model, standalone_name:, **params),
200
200
  method:,
201
- visible: ->(controller) { target_comp_instance.standalone_access_permitted_for?(controller, verb: method) }
201
+ visible: ->(controller) { target_comp_instance.standalone_access_permitted_for?(controller, standalone_name:, verb: method) }
202
202
  }
203
203
  if feasibility_target
204
204
  options.merge!({
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: compony
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.2
4
+ version: 0.5.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sandro Kalbermatter
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2024-11-20 00:00:00.000000000 Z
12
+ date: 2024-12-20 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: yard