compony 0.5.1 → 0.5.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (75) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +14 -0
  3. data/README.md +33 -0
  4. data/VERSION +1 -1
  5. data/compony.gemspec +4 -4
  6. data/config/routes.rb +9 -6
  7. data/doc/ComponentGenerator.html +3 -3
  8. data/doc/Components.html +3 -3
  9. data/doc/ComponentsGenerator.html +3 -3
  10. data/doc/Compony/Component.html +3 -3
  11. data/doc/Compony/ComponentMixins/Default/Labelling.html +3 -3
  12. data/doc/Compony/ComponentMixins/Default/Standalone/ResourcefulVerbDsl.html +3 -3
  13. data/doc/Compony/ComponentMixins/Default/Standalone/StandaloneDsl.html +40 -28
  14. data/doc/Compony/ComponentMixins/Default/Standalone/VerbDsl.html +3 -3
  15. data/doc/Compony/ComponentMixins/Default/Standalone.html +3 -3
  16. data/doc/Compony/ComponentMixins/Default.html +3 -3
  17. data/doc/Compony/ComponentMixins/Resourceful.html +3 -3
  18. data/doc/Compony/ComponentMixins.html +3 -3
  19. data/doc/Compony/Components/Button.html +11 -7
  20. data/doc/Compony/Components/Destroy.html +3 -3
  21. data/doc/Compony/Components/Edit.html +3 -3
  22. data/doc/Compony/Components/Form.html +148 -77
  23. data/doc/Compony/Components/New.html +3 -3
  24. data/doc/Compony/Components/WithForm.html +3 -3
  25. data/doc/Compony/Components.html +3 -3
  26. data/doc/Compony/ControllerMixin.html +3 -3
  27. data/doc/Compony/Engine.html +3 -3
  28. data/doc/Compony/MethodAccessibleHash.html +3 -3
  29. data/doc/Compony/ModelFields/Anchormodel.html +3 -3
  30. data/doc/Compony/ModelFields/Association.html +4 -4
  31. data/doc/Compony/ModelFields/Attachment.html +3 -3
  32. data/doc/Compony/ModelFields/Base.html +3 -3
  33. data/doc/Compony/ModelFields/Boolean.html +3 -3
  34. data/doc/Compony/ModelFields/Color.html +3 -3
  35. data/doc/Compony/ModelFields/Currency.html +3 -3
  36. data/doc/Compony/ModelFields/Date.html +3 -3
  37. data/doc/Compony/ModelFields/Datetime.html +3 -3
  38. data/doc/Compony/ModelFields/Decimal.html +3 -3
  39. data/doc/Compony/ModelFields/Email.html +3 -3
  40. data/doc/Compony/ModelFields/Float.html +3 -3
  41. data/doc/Compony/ModelFields/Integer.html +3 -3
  42. data/doc/Compony/ModelFields/Percentage.html +3 -3
  43. data/doc/Compony/ModelFields/Phone.html +3 -3
  44. data/doc/Compony/ModelFields/RichText.html +3 -3
  45. data/doc/Compony/ModelFields/String.html +3 -3
  46. data/doc/Compony/ModelFields/Text.html +3 -3
  47. data/doc/Compony/ModelFields/Time.html +3 -3
  48. data/doc/Compony/ModelFields/Url.html +3 -3
  49. data/doc/Compony/ModelFields.html +3 -3
  50. data/doc/Compony/ModelMixin.html +3 -3
  51. data/doc/Compony/NaturalOrdering.html +3 -3
  52. data/doc/Compony/RequestContext.html +3 -3
  53. data/doc/Compony/Version.html +3 -3
  54. data/doc/Compony/ViewHelpers.html +32 -14
  55. data/doc/Compony.html +4 -4
  56. data/doc/ComponyController.html +3 -3
  57. data/doc/_index.html +4 -4
  58. data/doc/class_list.html +6 -3
  59. data/doc/css/full_list.css +3 -3
  60. data/doc/css/style.css +6 -0
  61. data/doc/file.README.html +36 -3
  62. data/doc/file_list.html +5 -2
  63. data/doc/frames.html +10 -5
  64. data/doc/index.html +36 -3
  65. data/doc/js/app.js +294 -264
  66. data/doc/js/full_list.js +30 -4
  67. data/doc/method_list.html +152 -141
  68. data/doc/top-level-namespace.html +3 -3
  69. data/lib/compony/component_mixins/default/standalone/standalone_dsl.rb +7 -1
  70. data/lib/compony/components/button.rb +5 -3
  71. data/lib/compony/components/form.rb +9 -1
  72. data/lib/compony/model_fields/association.rb +1 -1
  73. data/lib/compony/view_helpers.rb +12 -4
  74. data/lib/compony.rb +1 -1
  75. metadata +3 -3
@@ -6,7 +6,7 @@
6
6
  <title>
7
7
  Top Level Namespace
8
8
 
9
- &mdash; Documentation by YARD 0.9.34
9
+ &mdash; Documentation by YARD 0.9.37
10
10
 
11
11
  </title>
12
12
 
@@ -102,9 +102,9 @@
102
102
  </div>
103
103
 
104
104
  <div id="footer">
105
- Generated on Mon Sep 16 14:57:51 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
- 0.9.34 (ruby-3.3.5).
107
+ 0.9.37 (ruby-3.3.5).
108
108
  </div>
109
109
 
110
110
  </div>
@@ -6,12 +6,15 @@ module Compony
6
6
  # Wrapper and DSL helper for component's standalone config
7
7
  # Pass `provide_defaults` true if this is the first standalone DSL of a component. Pass false if it is a subsequent one (e.g. if subclassed comp)
8
8
  class StandaloneDsl < Dslblend::Base
9
- def initialize(component, name = nil, provide_defaults:, path: nil)
9
+ def initialize(component, name = nil, provide_defaults:, path: nil, constraints: nil, scope: nil, scope_args: {})
10
10
  super()
11
11
  @component = component
12
12
  @name = name&.to_sym
13
13
  @provide_defaults = provide_defaults
14
14
  @path = path
15
+ @constraints = constraints
16
+ @scope = scope
17
+ @scope_args = scope_args
15
18
  @verbs = {}
16
19
  @skip_authentication = false
17
20
  @layout = true # can be overriden by false or a string
@@ -24,6 +27,9 @@ module Compony
24
27
  return {
25
28
  name: @name,
26
29
  path: @path,
30
+ constraints: @constraints,
31
+ scope: @scope,
32
+ scope_args: @scope_args,
27
33
  verbs: @verbs,
28
34
  rails_action_name: Compony.rails_action_name(comp_name, family_name, @name),
29
35
  path_helper_name: Compony.path_helper_name(comp_name, family_name, @name),
@@ -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
@@ -44,7 +44,7 @@ module Compony
44
44
  end
45
45
 
46
46
  def simpleform_input(form, _component, name: nil, **input_opts)
47
- return form.association name || @name, **input_opts
47
+ return form.association name || @name, **{ label_method: :label }.deep_merge(input_opts)
48
48
  end
49
49
 
50
50
  def simpleform_input_hidden(form, _component, name: nil, **input_opts)
@@ -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.1
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-09-16 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
@@ -330,7 +330,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
330
330
  - !ruby/object:Gem::Version
331
331
  version: '0'
332
332
  requirements: []
333
- rubygems_version: 3.5.18
333
+ rubygems_version: 3.5.22
334
334
  signing_key:
335
335
  specification_version: 4
336
336
  summary: Compony is a Gem that allows you to write your Rails application in component-style