compony 0.6.4 → 0.7.0
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 +12 -0
- data/Gemfile.lock +1 -1
- data/README.md +6 -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 +247 -156
- 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 +1 -1
- data/doc/Compony/ComponentMixins/Default.html +1 -1
- data/doc/Compony/ComponentMixins/Resourceful.html +1 -1
- data/doc/Compony/ComponentMixins.html +1 -1
- data/doc/Compony/Components/Button.html +2 -2
- 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/Index.html +2 -2
- data/doc/Compony/Components/List.html +2 -2
- data/doc/Compony/Components/New.html +2 -2
- data/doc/Compony/Components/Show.html +2 -2
- data/doc/Compony/Components/WithForm.html +19 -21
- 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 +1 -1
- 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 +44 -42
- data/doc/ComponyController.html +1 -1
- data/doc/_index.html +1 -1
- data/doc/file.README.html +7 -1
- data/doc/index.html +7 -1
- data/doc/method_list.html +109 -101
- data/doc/top-level-namespace.html +1 -1
- data/lib/compony/component.rb +30 -8
- data/lib/compony/components/with_form.rb +1 -2
- data/lib/compony.rb +9 -8
- metadata +2 -2
|
@@ -102,7 +102,7 @@
|
|
|
102
102
|
</div>
|
|
103
103
|
|
|
104
104
|
<div id="footer">
|
|
105
|
-
Generated on
|
|
105
|
+
Generated on Fri Nov 14 15:08:15 2025 by
|
|
106
106
|
<a href="https://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
|
107
107
|
0.9.34 (ruby-3.3.5).
|
|
108
108
|
</div>
|
data/lib/compony/component.rb
CHANGED
|
@@ -49,6 +49,14 @@ module Compony
|
|
|
49
49
|
@content_blocks = NaturalOrdering.new
|
|
50
50
|
@actions = NaturalOrdering.new
|
|
51
51
|
@skipped_actions = Set.new
|
|
52
|
+
@path_block = proc do |model = nil, *args_for_path_helper, standalone_name: nil, **kwargs_for_path_helper|
|
|
53
|
+
kwargs_for_path_helper.merge!(id: model.id) if model
|
|
54
|
+
next Rails.application.routes.url_helpers.send(
|
|
55
|
+
"#{Compony.path_helper_name(comp_cst, family_cst, standalone_name&.to_sym)}_path",
|
|
56
|
+
*args_for_path_helper,
|
|
57
|
+
**kwargs_for_path_helper
|
|
58
|
+
)
|
|
59
|
+
end
|
|
52
60
|
|
|
53
61
|
init_standalone
|
|
54
62
|
init_labelling
|
|
@@ -83,26 +91,26 @@ module Compony
|
|
|
83
91
|
"#{family_name}_#{comp_name}_#{@index}"
|
|
84
92
|
end
|
|
85
93
|
|
|
86
|
-
# Returns the
|
|
94
|
+
# Returns the id_path from the root_comp.
|
|
87
95
|
# Do not overwrite.
|
|
88
|
-
def
|
|
96
|
+
def id_path
|
|
89
97
|
if root_comp?
|
|
90
98
|
id
|
|
91
99
|
else
|
|
92
|
-
"#{parent_comp.
|
|
100
|
+
"#{parent_comp.id_path}/#{id}"
|
|
93
101
|
end
|
|
94
102
|
end
|
|
95
103
|
|
|
96
|
-
# Returns a hash for the
|
|
104
|
+
# Returns a hash for the id_path. Used for params prefixing.
|
|
97
105
|
# Do not overwrite.
|
|
98
|
-
def
|
|
99
|
-
Digest::SHA1.hexdigest(
|
|
106
|
+
def id_path_hash
|
|
107
|
+
Digest::SHA1.hexdigest(id_path)[..4]
|
|
100
108
|
end
|
|
101
109
|
|
|
102
|
-
# Given an unprefixed name of a param, adds the
|
|
110
|
+
# Given an unprefixed name of a param, adds the id_path hash
|
|
103
111
|
# Do not overwrite.
|
|
104
112
|
def param_name(unprefixed_param_name)
|
|
105
|
-
"#{
|
|
113
|
+
"#{id_path_hash}_#{unprefixed_param_name}"
|
|
106
114
|
end
|
|
107
115
|
|
|
108
116
|
# Instanciate a component with `self` as a parent
|
|
@@ -124,6 +132,20 @@ module Compony
|
|
|
124
132
|
# Returns the component name
|
|
125
133
|
delegate :comp_name, to: :class
|
|
126
134
|
|
|
135
|
+
# DSL method
|
|
136
|
+
# Overrides how the path to this component should be generated.
|
|
137
|
+
# The block will be given the following args: a model (optional), pos. args for the path helper, the kwarg `standalone_name` and kwargs for the path helper.
|
|
138
|
+
# The block is expected to return a Rails path. It is not given `controller` or `helpers`, instead use: `Rails.application.routes.url_helpers`.
|
|
139
|
+
# For an example, refer to the initializer of this class, where the default block is defined.
|
|
140
|
+
def path(*, **, &block)
|
|
141
|
+
if block_given?
|
|
142
|
+
# Assignment via DSL
|
|
143
|
+
@path_block = block
|
|
144
|
+
else
|
|
145
|
+
@path_block.call(*, **)
|
|
146
|
+
end
|
|
147
|
+
end
|
|
148
|
+
|
|
127
149
|
# DSL method
|
|
128
150
|
# Adds or overrides a before_render block.
|
|
129
151
|
# You can use controller.redirect_to to redirect away and halt the before_render/content chain
|
|
@@ -5,8 +5,7 @@ module Compony
|
|
|
5
5
|
# It can be called via :get or via `submit_verb` depending on whether its form should be shown or submitted.
|
|
6
6
|
class WithForm < Component
|
|
7
7
|
def initialize(...)
|
|
8
|
-
|
|
9
|
-
@submit_path_block = ->(controller) { controller.helpers.send("#{Compony.path_helper_name(comp_name, family_name)}_path") }
|
|
8
|
+
@submit_path_block = proc { Compony.path(comp_name, family_name, @data) }
|
|
10
9
|
@form_cancancan_action = :missing
|
|
11
10
|
super
|
|
12
11
|
end
|
data/lib/compony.rb
CHANGED
|
@@ -95,7 +95,7 @@ module Compony
|
|
|
95
95
|
##########=====-------
|
|
96
96
|
|
|
97
97
|
# Generates a Rails path to a component. Examples: `Compony.path(:index, :users)`, `Compony.path(:show, User.first)`
|
|
98
|
-
# @param
|
|
98
|
+
# @param comp_name_or_cst_or_class [String,Symbol] The component that should be loaded, for instance `ShowForAll`, `'ShowForAll'` or `:show_for_all`
|
|
99
99
|
# or can also pass a component class (such as Components::Users::Show)
|
|
100
100
|
# @param model_or_family_name_or_cst [String,Symbol,ApplicationRecord] Either the family that contains the requested component,
|
|
101
101
|
# or an instance implementing `model_name` from which the family name is auto-generated. Examples:
|
|
@@ -104,14 +104,15 @@ module Compony
|
|
|
104
104
|
# @param args_for_path_helper [Array] Positional arguments passed to the Rails helper
|
|
105
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`,
|
|
106
106
|
# the param `id` defaults to the passed model's ID.
|
|
107
|
-
def self.path(
|
|
107
|
+
def self.path(comp_name_or_cst_or_class, model_or_family_name_or_cst = nil, *args_for_path_helper, standalone_name: nil, **kwargs_for_path_helper)
|
|
108
108
|
# Extract model if any, to get the ID
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
109
|
+
model = model_or_family_name_or_cst.respond_to?(:model_name) ? model_or_family_name_or_cst : nil
|
|
110
|
+
comp_class = if comp_name_or_cst_or_class.is_a?(Class) && (comp_name_or_cst_or_class <= Compony::Component)
|
|
111
|
+
comp_name_or_cst_or_class
|
|
112
|
+
else
|
|
113
|
+
comp_class_for!(comp_name_or_cst_or_class, model_or_family_name_or_cst)
|
|
114
|
+
end
|
|
115
|
+
return comp_class.new.path(model, *args_for_path_helper, standalone_name:, **kwargs_for_path_helper)
|
|
115
116
|
end
|
|
116
117
|
|
|
117
118
|
# Given a component and a family/model, this returns the matching component class if any, or nil if the component does not exist.
|
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
|
+
version: 0.7.0
|
|
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: 2025-11-
|
|
12
|
+
date: 2025-11-14 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
|
14
14
|
- !ruby/object:Gem::Dependency
|
|
15
15
|
name: yard
|