compony 0.4.0 → 0.4.1
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 +4 -4
- data/CHANGELOG.md +8 -0
- data/VERSION +1 -1
- data/compony.gemspec +3 -3
- data/doc/ComponentGenerator.html +1 -1
- data/doc/Components.html +1 -1
- data/doc/ComponentsGenerator.html +1 -1
- data/doc/Compony/Component.html +419 -159
- data/doc/Compony/ComponentMixins/Default/Labelling.html +1 -1
- data/doc/Compony/ComponentMixins/Default/Standalone/ResourcefulVerbDsl.html +1 -1
- data/doc/Compony/ComponentMixins/Default/Standalone/StandaloneDsl.html +1 -1
- data/doc/Compony/ComponentMixins/Default/Standalone/VerbDsl.html +1 -1
- data/doc/Compony/ComponentMixins/Default/Standalone.html +6 -6
- data/doc/Compony/ComponentMixins/Default.html +1 -1
- data/doc/Compony/ComponentMixins/Resourceful.html +5 -5
- data/doc/Compony/ComponentMixins.html +1 -1
- data/doc/Compony/Components/Button.html +6 -6
- data/doc/Compony/Components/Destroy.html +2 -2
- data/doc/Compony/Components/Edit.html +2 -2
- data/doc/Compony/Components/Form.html +2 -2
- data/doc/Compony/Components/New.html +2 -2
- data/doc/Compony/Components/WithForm.html +2 -2
- data/doc/Compony/Components.html +1 -1
- data/doc/Compony/ControllerMixin.html +1 -1
- data/doc/Compony/Engine.html +1 -1
- data/doc/Compony/MethodAccessibleHash.html +1 -1
- data/doc/Compony/ModelFields/Anchormodel.html +1 -1
- data/doc/Compony/ModelFields/Association.html +1 -1
- data/doc/Compony/ModelFields/Attachment.html +2 -2
- data/doc/Compony/ModelFields/Base.html +1 -1
- data/doc/Compony/ModelFields/Boolean.html +1 -1
- data/doc/Compony/ModelFields/Color.html +1 -1
- data/doc/Compony/ModelFields/Currency.html +1 -1
- data/doc/Compony/ModelFields/Date.html +1 -1
- data/doc/Compony/ModelFields/Datetime.html +1 -1
- data/doc/Compony/ModelFields/Decimal.html +1 -1
- data/doc/Compony/ModelFields/Email.html +1 -1
- data/doc/Compony/ModelFields/Float.html +1 -1
- data/doc/Compony/ModelFields/Integer.html +1 -1
- data/doc/Compony/ModelFields/Percentage.html +1 -1
- data/doc/Compony/ModelFields/Phone.html +1 -1
- data/doc/Compony/ModelFields/RichText.html +1 -1
- data/doc/Compony/ModelFields/String.html +1 -1
- data/doc/Compony/ModelFields/Text.html +1 -1
- data/doc/Compony/ModelFields/Time.html +1 -1
- data/doc/Compony/ModelFields/Url.html +1 -1
- data/doc/Compony/ModelFields.html +1 -1
- data/doc/Compony/ModelMixin.html +1 -1
- data/doc/Compony/NaturalOrdering.html +1 -1
- data/doc/Compony/RequestContext.html +1 -1
- data/doc/Compony/Version.html +1 -1
- data/doc/Compony/ViewHelpers.html +1 -1
- data/doc/Compony.html +152 -92
- data/doc/ComponyController.html +1 -1
- data/doc/_index.html +1 -1
- data/doc/file.README.html +1 -1
- data/doc/index.html +1 -1
- data/doc/method_list.html +32 -0
- data/doc/top-level-namespace.html +1 -1
- data/lib/compony/component.rb +24 -4
- data/lib/compony/component_mixins/default/standalone.rb +3 -3
- data/lib/compony/component_mixins/resourceful.rb +2 -2
- data/lib/compony/components/button.rb +2 -2
- data/lib/compony/model_fields/attachment.rb +1 -1
- data/lib/compony.rb +24 -11
- metadata +3 -3
data/doc/method_list.html
CHANGED
|
@@ -221,6 +221,14 @@
|
|
|
221
221
|
|
|
222
222
|
|
|
223
223
|
<li class="odd ">
|
|
224
|
+
<div class="item">
|
|
225
|
+
<span class='object_link'><a href="Compony/Component.html#comp_cst-class_method" title="Compony::Component.comp_cst (method)">comp_cst</a></span>
|
|
226
|
+
<small>Compony::Component</small>
|
|
227
|
+
</div>
|
|
228
|
+
</li>
|
|
229
|
+
|
|
230
|
+
|
|
231
|
+
<li class="even ">
|
|
224
232
|
<div class="item">
|
|
225
233
|
<span class='object_link'><a href="Compony/Component.html#comp_cst-instance_method" title="Compony::Component#comp_cst (method)">#comp_cst</a></span>
|
|
226
234
|
<small>Compony::Component</small>
|
|
@@ -228,6 +236,14 @@
|
|
|
228
236
|
</li>
|
|
229
237
|
|
|
230
238
|
|
|
239
|
+
<li class="odd ">
|
|
240
|
+
<div class="item">
|
|
241
|
+
<span class='object_link'><a href="Compony/Component.html#comp_name-class_method" title="Compony::Component.comp_name (method)">comp_name</a></span>
|
|
242
|
+
<small>Compony::Component</small>
|
|
243
|
+
</div>
|
|
244
|
+
</li>
|
|
245
|
+
|
|
246
|
+
|
|
231
247
|
<li class="even ">
|
|
232
248
|
<div class="item">
|
|
233
249
|
<span class='object_link'><a href="Compony/Component.html#comp_name-instance_method" title="Compony::Component#comp_name (method)">#comp_name</a></span>
|
|
@@ -397,6 +413,14 @@
|
|
|
397
413
|
|
|
398
414
|
|
|
399
415
|
<li class="odd ">
|
|
416
|
+
<div class="item">
|
|
417
|
+
<span class='object_link'><a href="Compony/Component.html#family_cst-class_method" title="Compony::Component.family_cst (method)">family_cst</a></span>
|
|
418
|
+
<small>Compony::Component</small>
|
|
419
|
+
</div>
|
|
420
|
+
</li>
|
|
421
|
+
|
|
422
|
+
|
|
423
|
+
<li class="even ">
|
|
400
424
|
<div class="item">
|
|
401
425
|
<span class='object_link'><a href="Compony/Component.html#family_cst-instance_method" title="Compony::Component#family_cst (method)">#family_cst</a></span>
|
|
402
426
|
<small>Compony::Component</small>
|
|
@@ -404,6 +428,14 @@
|
|
|
404
428
|
</li>
|
|
405
429
|
|
|
406
430
|
|
|
431
|
+
<li class="odd ">
|
|
432
|
+
<div class="item">
|
|
433
|
+
<span class='object_link'><a href="Compony/Component.html#family_name-class_method" title="Compony::Component.family_name (method)">family_name</a></span>
|
|
434
|
+
<small>Compony::Component</small>
|
|
435
|
+
</div>
|
|
436
|
+
</li>
|
|
437
|
+
|
|
438
|
+
|
|
407
439
|
<li class="even ">
|
|
408
440
|
<div class="item">
|
|
409
441
|
<span class='object_link'><a href="Compony/Component.html#family_name-instance_method" title="Compony::Component#family_name (method)">#family_name</a></span>
|
|
@@ -102,7 +102,7 @@
|
|
|
102
102
|
</div>
|
|
103
103
|
|
|
104
104
|
<div id="footer">
|
|
105
|
-
Generated on
|
|
105
|
+
Generated on Thu Sep 12 16:31:18 2024 by
|
|
106
106
|
<a href="https://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
|
107
107
|
0.9.36 (ruby-3.2.2).
|
|
108
108
|
</div>
|
data/lib/compony/component.rb
CHANGED
|
@@ -20,6 +20,26 @@ module Compony
|
|
|
20
20
|
setup_blocks << block
|
|
21
21
|
end
|
|
22
22
|
|
|
23
|
+
# Returns the name of the module constant (=family) of this component. Do not override.
|
|
24
|
+
def self.family_cst
|
|
25
|
+
module_parent.to_s.demodulize.to_sym
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
# Returns the family name
|
|
29
|
+
def self.family_name
|
|
30
|
+
family_cst.to_s.underscore
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
# Returns the name of the class constant of this component. Do not override.
|
|
34
|
+
def self.comp_cst
|
|
35
|
+
name.demodulize.to_sym
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
# Returns the component name
|
|
39
|
+
def self.comp_name
|
|
40
|
+
comp_cst.to_s.underscore
|
|
41
|
+
end
|
|
42
|
+
|
|
23
43
|
def initialize(parent_comp = nil, index: 0, **comp_opts)
|
|
24
44
|
@parent_comp = parent_comp
|
|
25
45
|
@sub_comps = []
|
|
@@ -94,22 +114,22 @@ module Compony
|
|
|
94
114
|
|
|
95
115
|
# Returns the name of the module constant (=family) of this component. Do not override.
|
|
96
116
|
def family_cst
|
|
97
|
-
self.class.
|
|
117
|
+
self.class.family_cst
|
|
98
118
|
end
|
|
99
119
|
|
|
100
120
|
# Returns the family name
|
|
101
121
|
def family_name
|
|
102
|
-
|
|
122
|
+
self.class.family_name
|
|
103
123
|
end
|
|
104
124
|
|
|
105
125
|
# Returns the name of the class constant of this component. Do not override.
|
|
106
126
|
def comp_cst
|
|
107
|
-
self.class.
|
|
127
|
+
self.class.comp_cst
|
|
108
128
|
end
|
|
109
129
|
|
|
110
130
|
# Returns the component name
|
|
111
131
|
def comp_name
|
|
112
|
-
|
|
132
|
+
self.class.comp_name
|
|
113
133
|
end
|
|
114
134
|
|
|
115
135
|
# DSL method
|
|
@@ -108,13 +108,13 @@ module Compony
|
|
|
108
108
|
# To have a component listen to multiple paths, call standalone again and provide a name, e.g.: standalone(:autocomplete, path: 'foo/bar/autocomplete')
|
|
109
109
|
# The kwarg parameter `path` is handled analog to the Rails route path
|
|
110
110
|
# @param name [Symbol,nil] The name of the standalone config, defaults to nil. Only provide if you add additional configs.
|
|
111
|
-
def standalone(name = nil,
|
|
111
|
+
def standalone(name = nil, *, **nargs, &block)
|
|
112
112
|
block = proc {} unless block_given? # If called without a block, must default to an empty block to provide a binding to the DSL.
|
|
113
113
|
name = name&.to_sym # nil name is the most common case
|
|
114
114
|
if @standalone_configs[name]
|
|
115
|
-
@standalone_configs[name].deep_merge! StandaloneDsl.new(self, name,
|
|
115
|
+
@standalone_configs[name].deep_merge! StandaloneDsl.new(self, name, *, provide_defaults: false, **nargs).to_conf(&block)
|
|
116
116
|
else
|
|
117
|
-
@standalone_configs[name] = Compony::MethodAccessibleHash.new(StandaloneDsl.new(self, name,
|
|
117
|
+
@standalone_configs[name] = Compony::MethodAccessibleHash.new(StandaloneDsl.new(self, name, *, provide_defaults: true, **nargs).to_conf(&block))
|
|
118
118
|
end
|
|
119
119
|
end
|
|
120
120
|
|
|
@@ -15,14 +15,14 @@ module Compony
|
|
|
15
15
|
attr_reader :global_after_assign_attributes_block
|
|
16
16
|
attr_reader :global_store_data_block
|
|
17
17
|
|
|
18
|
-
def initialize(
|
|
18
|
+
def initialize(*, data: nil, data_class: nil, **nargs, &)
|
|
19
19
|
@data = data
|
|
20
20
|
@data_class = data_class
|
|
21
21
|
|
|
22
22
|
# Provide defaults for hook blocks
|
|
23
23
|
@global_load_data_block ||= proc { @data = self.data_class.find(controller.params[:id]) }
|
|
24
24
|
|
|
25
|
-
super(
|
|
25
|
+
super(*, **nargs, &)
|
|
26
26
|
end
|
|
27
27
|
|
|
28
28
|
# DSL method
|
|
@@ -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(
|
|
10
|
+
def initialize(*, label: nil, path: nil, method: nil, type: nil, enabled: nil, visible: nil, title: 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)'
|
|
@@ -26,7 +26,7 @@ module Compony
|
|
|
26
26
|
|
|
27
27
|
fail "Unsupported button type #{@type}, use on of: #{SUPPORTED_TYPES.inspect}" unless SUPPORTED_TYPES.include?(@type)
|
|
28
28
|
|
|
29
|
-
super(
|
|
29
|
+
super(*, **, &)
|
|
30
30
|
end
|
|
31
31
|
|
|
32
32
|
setup do
|
|
@@ -12,7 +12,7 @@ module Compony
|
|
|
12
12
|
end
|
|
13
13
|
|
|
14
14
|
def simpleform_input(form, _component, name: nil, accept: nil, **input_opts)
|
|
15
|
-
input_opts.
|
|
15
|
+
input_opts.deep_merge!(input_html: { accept: }) if accept
|
|
16
16
|
return form.input(name || @name, **input_opts)
|
|
17
17
|
end
|
|
18
18
|
end
|
data/lib/compony.rb
CHANGED
|
@@ -96,17 +96,19 @@ module Compony
|
|
|
96
96
|
|
|
97
97
|
# Generates a Rails path to a component. Examples: `Compony.path(:index, :users)`, `Compony.path(:show, User.first)`
|
|
98
98
|
# @param comp_name_or_cst [String,Symbol] The component that should be loaded, for instance `ShowForAll`, `'ShowForAll'` or `:show_for_all`
|
|
99
|
+
# or can also pass a component class (such as Components::Users::Show)
|
|
99
100
|
# @param model_or_family_name_or_cst [String,Symbol,ApplicationRecord] Either the family that contains the requested component,
|
|
100
101
|
# or an instance implementing `model_name` from which the family name is auto-generated. Examples:
|
|
101
102
|
# `Users`, `'Users'`, `:users`, `User.first`
|
|
103
|
+
# @param standalone_name [Symbol,nil] Name of the standalone config to point to (defaults to nil the default standalone config).
|
|
102
104
|
# @param args_for_path_helper [Array] Positional arguments passed to the Rails helper
|
|
103
105
|
# @param kwargs_for_path_helper [Hash] Named arguments passed to the Rails helper. If a model is given to `model_or_family_name_or_cst`,
|
|
104
106
|
# the param `id` defaults to the passed model's ID.
|
|
105
|
-
def self.path(comp_name_or_cst, model_or_family_name_or_cst, *args_for_path_helper, **kwargs_for_path_helper)
|
|
107
|
+
def self.path(comp_name_or_cst, model_or_family_name_or_cst = nil, *args_for_path_helper, standalone_name: nil, **kwargs_for_path_helper)
|
|
106
108
|
# Extract model if any, to get the ID
|
|
107
109
|
kwargs_for_path_helper.merge!(id: model_or_family_name_or_cst.id) if model_or_family_name_or_cst.respond_to?(:model_name)
|
|
108
110
|
return Rails.application.routes.url_helpers.send(
|
|
109
|
-
"#{path_helper_name(comp_name_or_cst, model_or_family_name_or_cst)}_path",
|
|
111
|
+
"#{path_helper_name(comp_name_or_cst, model_or_family_name_or_cst, standalone_name&.to_sym)}_path",
|
|
110
112
|
*args_for_path_helper,
|
|
111
113
|
**kwargs_for_path_helper
|
|
112
114
|
)
|
|
@@ -143,18 +145,23 @@ module Compony
|
|
|
143
145
|
"#{rails_action_name(...)}_comp"
|
|
144
146
|
end
|
|
145
147
|
|
|
146
|
-
# Given a component and a family, this returns the name of the ComponyController action for this component.<br>
|
|
148
|
+
# Given a component and a family or a component class, this returns the name of the ComponyController action for this component.<br>
|
|
147
149
|
# Optionally can pass a name for extra standalone configs.
|
|
148
150
|
# @param comp_name_or_cst [String,Symbol] Name of the component the action points to.
|
|
149
151
|
# @param model_or_family_name_or_cst [String,Symbol] Name of the family the action points to.
|
|
150
152
|
# @param name [String,Symbol] If referring to an extra standalone entrypoint, specify its name using this param.
|
|
151
153
|
# @see Compony#path
|
|
152
|
-
def self.rails_action_name(
|
|
153
|
-
|
|
154
|
+
def self.rails_action_name(comp_name_or_cst_or_class, model_or_family_name_or_cst, name = nil)
|
|
155
|
+
if comp_name_or_cst_or_class.is_a?(Class) && (comp_name_or_cst_or_class <= Compony::Component)
|
|
156
|
+
comp_class = comp_name_or_cst_or_class
|
|
157
|
+
comp_name_or_cst_or_class = comp_class.comp_name
|
|
158
|
+
model_or_family_name_or_cst = comp_class.family_name
|
|
159
|
+
end
|
|
160
|
+
[name.presence, comp_name_or_cst_or_class.to_s.underscore, family_name_for(model_or_family_name_or_cst)].compact.join('_')
|
|
154
161
|
end
|
|
155
162
|
|
|
156
163
|
# Given a component and a family/model, this instanciates and returns a button component.
|
|
157
|
-
# @param
|
|
164
|
+
# @param comp_name_or_cst_or_class [String,Symbol,Class] The component that should be loaded, for instance `ShowForAll`, `'ShowForAll'` or `:show_for_all`
|
|
158
165
|
# @param model_or_family_name_or_cst [String,Symbol,ApplicationRecord] Either the family that contains the requested component,
|
|
159
166
|
# or an instance implementing `model_name` from which the family name is auto-generated. Examples:
|
|
160
167
|
# `Users`, `'Users'`, `:users`, `User.first`
|
|
@@ -162,28 +169,34 @@ module Compony
|
|
|
162
169
|
# @param params [Hash] GET parameters to be inclued into the path this button points to. Special case: e.g. format: :pdf -> some.url/foo/bar.pdf
|
|
163
170
|
# @param feasibility_action [Symbol] Name of the feasibility action that should be checked for this button, defaults to the component name
|
|
164
171
|
# @param feasibility_target [Symbol] Name of the feasibility target (subject) that the feasibility should be checked on, defaults to the model if given
|
|
172
|
+
# @param standalone_name [Symbol,nil] Name of the standalone config to point to (defaults to nil the default standalone config).
|
|
165
173
|
# @param override_kwargs [Hash] Override button options, see options for {Compony::Components::Button}
|
|
166
174
|
# @see Compony::ViewHelpers#compony_button View helper providing a wrapper for this method that immediately renders a button.
|
|
167
175
|
# @see Compony::Components::Button Compony::Components::Button: the default underlying implementation
|
|
168
|
-
def self.button(
|
|
169
|
-
model_or_family_name_or_cst,
|
|
176
|
+
def self.button(comp_name_or_cst_or_class,
|
|
177
|
+
model_or_family_name_or_cst = nil,
|
|
170
178
|
label_opts: nil,
|
|
171
179
|
params: nil,
|
|
172
180
|
feasibility_action: nil,
|
|
173
181
|
feasibility_target: nil,
|
|
174
182
|
method: nil,
|
|
183
|
+
standalone_name: nil,
|
|
175
184
|
**override_kwargs)
|
|
176
185
|
label_opts ||= button_defaults[:label_opts] || {}
|
|
177
186
|
params ||= button_defaults[:params] || {}
|
|
178
187
|
model = model_or_family_name_or_cst.respond_to?(:model_name) ? model_or_family_name_or_cst : nil
|
|
179
|
-
|
|
180
|
-
|
|
188
|
+
if comp_name_or_cst_or_class.is_a?(Class) && (comp_name_or_cst_or_class <= Compony::Component)
|
|
189
|
+
target_comp_instance = comp_name_or_cst_or_class.new(data: model)
|
|
190
|
+
else
|
|
191
|
+
target_comp_instance = Compony.comp_class_for!(comp_name_or_cst_or_class, model_or_family_name_or_cst).new(data: model)
|
|
192
|
+
end
|
|
193
|
+
feasibility_action ||= button_defaults[:feasibility_action] || comp_name_or_cst_or_class.to_s.underscore.to_sym
|
|
181
194
|
feasibility_target ||= button_defaults[:feasibility_target] || model
|
|
182
195
|
options = {
|
|
183
196
|
label: target_comp_instance.label(model, **label_opts),
|
|
184
197
|
icon: target_comp_instance.icon,
|
|
185
198
|
color: target_comp_instance.color,
|
|
186
|
-
path: Compony.path(target_comp_instance.comp_name, target_comp_instance.family_name, model, **params),
|
|
199
|
+
path: Compony.path(target_comp_instance.comp_name, target_comp_instance.family_name, model, standalone_name:, **params),
|
|
187
200
|
method:,
|
|
188
201
|
visible: ->(controller) { target_comp_instance.standalone_access_permitted_for?(controller, verb: method) }
|
|
189
202
|
}
|
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.4.
|
|
4
|
+
version: 0.4.1
|
|
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-
|
|
12
|
+
date: 2024-09-12 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.
|
|
333
|
+
rubygems_version: 3.5.16
|
|
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
|