compony 0.3.0 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +8 -0
- data/README.md +10 -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 +139 -44
- 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 +14 -14
- data/doc/Compony/Components/Edit.html +2 -2
- data/doc/Compony/Components/Form.html +86 -86
- data/doc/Compony/Components/New.html +14 -14
- 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 +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 +14 -6
- data/doc/Compony/RequestContext.html +16 -4
- data/doc/Compony/Version.html +1 -1
- data/doc/Compony/ViewHelpers.html +1 -1
- data/doc/Compony.html +1 -1
- data/doc/ComponyController.html +1 -1
- data/doc/_index.html +1 -1
- data/doc/file.README.html +10 -1
- data/doc/index.html +10 -1
- data/doc/method_list.html +69 -61
- data/doc/top-level-namespace.html +1 -1
- data/lib/compony/component.rb +14 -2
- data/lib/compony/components/destroy.rb +9 -1
- data/lib/compony/components/form.rb +16 -5
- data/lib/compony/components/new.rb +1 -0
- data/lib/compony/natural_ordering.rb +6 -2
- data/lib/compony/request_context.rb +8 -2
- metadata +2 -2
@@ -15,21 +15,25 @@ module Compony
|
|
15
15
|
# collection.map(&:payload) # --> a_new_payload, b_payload, c_payload, d_payload
|
16
16
|
# ```
|
17
17
|
class NaturalOrdering < Array
|
18
|
-
def natural_push(name, payload, before: nil, **kwargs)
|
18
|
+
def natural_push(name, payload = :missing, before: nil, **kwargs)
|
19
19
|
name = name.to_sym
|
20
20
|
before_name = before&.to_sym
|
21
21
|
old_kwargs = {}
|
22
|
+
old_payload = nil
|
22
23
|
|
23
24
|
# Fetch existing element if any
|
24
25
|
existing_index = find_index { |el| el.name == name }
|
25
26
|
if existing_index.present?
|
26
27
|
# Copy all non-mentionned kwargs from the element we are about to overwrite
|
27
28
|
old_kwargs = self[existing_index].except(:name, :payload)
|
29
|
+
old_payload = self[existing_index].payload
|
28
30
|
|
29
31
|
# Replacing an existing element with a before: directive - must delete before calculating indices
|
30
32
|
if before_name.present?
|
31
33
|
delete_at(existing_index)
|
32
34
|
end
|
35
|
+
elsif payload == :missing
|
36
|
+
fail("Cannot insert new element #{name} without a payload (payload can only omitted if overriding another element) in #{inspect}.")
|
33
37
|
end
|
34
38
|
|
35
39
|
# Fetch before element
|
@@ -38,7 +42,7 @@ module Compony
|
|
38
42
|
end
|
39
43
|
|
40
44
|
# Create the element to insert
|
41
|
-
element = MethodAccessibleHash.new(name:, payload
|
45
|
+
element = MethodAccessibleHash.new(name:, payload: payload == :missing ? old_payload : payload, **old_kwargs.merge(kwargs))
|
42
46
|
|
43
47
|
# Insert new element
|
44
48
|
if before_index.present?
|
@@ -46,8 +46,14 @@ module Compony
|
|
46
46
|
def content(name)
|
47
47
|
name = name.to_sym
|
48
48
|
content_block = component.content_blocks.find { |el| el.name == name } || fail("Content block #{name.inspect} not found in #{component.inspect}.")
|
49
|
-
#
|
50
|
-
concat
|
49
|
+
# We have to clear Rails' output_buffer to prevent double rendering of blocks. To achieve this, a fresh render context is instanciated.
|
50
|
+
concat controller.render_to_string(
|
51
|
+
type: :dyny,
|
52
|
+
locals: { render_component: component, render_controller: controller, render_locals: local_assigns, render_block: content_block },
|
53
|
+
inline: <<~RUBY
|
54
|
+
Compony::RequestContext.new(render_component, render_controller, helpers: self, locals: local_assigns).evaluate_with_backfire(&render_block.payload)
|
55
|
+
RUBY
|
56
|
+
)
|
51
57
|
end
|
52
58
|
end
|
53
59
|
end
|
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.3.
|
4
|
+
version: 0.3.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-05-
|
12
|
+
date: 2024-05-31 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: yard
|