effective_resources 1.8.1 → 1.8.6
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/app/helpers/effective_resources_helper.rb +10 -2
- data/app/models/concerns/acts_as_slugged.rb +5 -0
- data/app/models/concerns/has_many_rich_texts.rb +54 -0
- data/app/models/effective/resources/associations.rb +2 -1
- data/app/models/effective/resources/instance.rb +1 -0
- data/app/views/application/member_action.js.erb +1 -1
- data/lib/effective_resources/engine.rb +1 -0
- data/lib/effective_resources/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3054f246623c2920a43e74b98bdb52aa03501ca936da01036523ac76e6f35049
|
4
|
+
data.tar.gz: 2121fdfa7914e4b0c4c516a26d030f6ff3c1bda0d60ff54a5f683fe0c4280c51
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c714c8640357cbb5c52aeca16a5cef0a6e0caf9eafe1a54cccf8c9aee79f27afb65ae022a8512c4297c379b96b9dc9c98275345709a24591aa8b1544051d64fc
|
7
|
+
data.tar.gz: be065c497d1b2b664b9d82dedf8fa2e3fd77bc25f89b06d51a1841ce9069fdd41e933d681cf11a66a2f76d2846c09b9f1c2353e75d88c69d48d8df0cbdacde27
|
@@ -148,6 +148,7 @@ module EffectiveResourcesHelper
|
|
148
148
|
effective_resource = (atts.delete(:effective_resource) || find_effective_resource)
|
149
149
|
|
150
150
|
action = atts.delete(:action)
|
151
|
+
safe = atts.delete(:safe)
|
151
152
|
atts = { :namespace => (effective_resource.namespace.to_sym if effective_resource.namespace), effective_resource.name.to_sym => resource }.compact.merge(atts)
|
152
153
|
|
153
154
|
if lookup_context.template_exists?("form_#{action}", controller._prefixes, :partial)
|
@@ -168,7 +169,10 @@ module EffectiveResourcesHelper
|
|
168
169
|
end
|
169
170
|
end
|
170
171
|
|
171
|
-
|
172
|
+
# Will raise the regular error
|
173
|
+
return ''.html_safe if safe
|
174
|
+
|
175
|
+
render('form', atts)
|
172
176
|
end
|
173
177
|
|
174
178
|
# Similar to render_resource_form
|
@@ -182,6 +186,7 @@ module EffectiveResourcesHelper
|
|
182
186
|
effective_resource = (atts.delete(:effective_resource) || find_effective_resource)
|
183
187
|
|
184
188
|
action = atts.delete(:action)
|
189
|
+
safe = atts.delete(:safe)
|
185
190
|
atts = { :namespace => (effective_resource.namespace.to_sym if effective_resource.namespace), effective_resource.name.to_sym => resource }.compact.merge(atts)
|
186
191
|
|
187
192
|
if lookup_context.template_exists?(effective_resource.name, controller._prefixes, :partial)
|
@@ -194,7 +199,10 @@ module EffectiveResourcesHelper
|
|
194
199
|
end
|
195
200
|
end
|
196
201
|
|
197
|
-
|
202
|
+
# Will raise the regular error
|
203
|
+
return ''.html_safe if safe
|
204
|
+
|
205
|
+
render(resource, atts)
|
198
206
|
end
|
199
207
|
alias_method :render_resource, :render_resource_partial
|
200
208
|
|
@@ -42,6 +42,11 @@ module ActsAsSlugged
|
|
42
42
|
|
43
43
|
where(slug: args.first).or(where(id: args.first)).first || raise(::ActiveRecord::RecordNotFound.new("Couldn't find #{name} with 'slug'=#{args.first}"))
|
44
44
|
end
|
45
|
+
|
46
|
+
def find_by_slug_or_id(*args)
|
47
|
+
where(slug: args.first).or(where(id: args.first)).first
|
48
|
+
end
|
49
|
+
|
45
50
|
end
|
46
51
|
|
47
52
|
# Instance Methods
|
@@ -0,0 +1,54 @@
|
|
1
|
+
# HasManyRichTexts
|
2
|
+
#
|
3
|
+
# Mark your model with 'has_many_rich_texts'
|
4
|
+
# Then it will automatically create a region when using a method named rich_text_*
|
5
|
+
# object.rich_text_body = "<p>Stuff</p>"
|
6
|
+
# object.rich_text_body => ActionText::RichText<name="body" body="<p>Stuff</p>">
|
7
|
+
|
8
|
+
module HasManyRichTexts
|
9
|
+
extend ActiveSupport::Concern
|
10
|
+
|
11
|
+
module Base
|
12
|
+
def has_many_rich_texts(options = nil)
|
13
|
+
include ::HasManyRichTexts
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
included do
|
18
|
+
has_many :rich_texts, class_name: 'ActionText::RichText', as: :record, inverse_of: :record, dependent: :destroy
|
19
|
+
accepts_nested_attributes_for :rich_texts, allow_destroy: true
|
20
|
+
end
|
21
|
+
|
22
|
+
module ClassMethods
|
23
|
+
end
|
24
|
+
|
25
|
+
# Find or build
|
26
|
+
def rich_text(name)
|
27
|
+
name = name.to_s
|
28
|
+
rich_texts.find { |rt| rt.name == name } || rich_texts.build(name: name)
|
29
|
+
end
|
30
|
+
|
31
|
+
def assign_rich_text_body(name, body)
|
32
|
+
rich_text(name).assign_attributes(body: body)
|
33
|
+
end
|
34
|
+
|
35
|
+
# Prevents an ActiveModel::UnknownAttributeError
|
36
|
+
# https://github.com/rails/rails/blob/main/activemodel/lib/active_model/attribute_assignment.rb#L48
|
37
|
+
def respond_to?(*args)
|
38
|
+
args.first.to_s.start_with?('rich_text_') ? true : super
|
39
|
+
end
|
40
|
+
|
41
|
+
def method_missing(method, *args, &block)
|
42
|
+
method = method.to_s
|
43
|
+
super unless method.start_with?('rich_text_')
|
44
|
+
|
45
|
+
name = method.chomp('=').sub('rich_text_', '')
|
46
|
+
|
47
|
+
if method.end_with?('=')
|
48
|
+
send(:assign_rich_text_body, name, *args)
|
49
|
+
else
|
50
|
+
send(:rich_text, name, *args)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
@@ -70,7 +70,8 @@ module Effective
|
|
70
70
|
end
|
71
71
|
|
72
72
|
def action_texts
|
73
|
-
klass.reflect_on_all_associations(:has_one).select { |ass| ass.class_name == 'ActionText::RichText' }
|
73
|
+
klass.reflect_on_all_associations(:has_one).select { |ass| ass.class_name == 'ActionText::RichText' } +
|
74
|
+
klass.reflect_on_all_associations(:has_many).select { |ass| ass.class_name == 'ActionText::RichText' }
|
74
75
|
end
|
75
76
|
|
76
77
|
def action_texts_has_ones_ids
|
@@ -1,7 +1,7 @@
|
|
1
1
|
<% resource = (@_effective_resource || Effective::Resource.new(controller_path)) %>
|
2
2
|
<% @resource = instance_variable_get('@' + resource.name) if resource.name %>
|
3
3
|
|
4
|
-
EffectiveForm.remote_form_payload = "<%= j render_resource_form(@resource, action: action) %>";
|
4
|
+
EffectiveForm.remote_form_payload = "<%= j render_resource_form(@resource, action: action, safe: true) %>";
|
5
5
|
EffectiveForm.remote_form_commit = "<%= params[:commit] %>";
|
6
6
|
EffectiveForm.remote_form_flash = <%= raw flash.to_json %>;
|
7
7
|
|
@@ -27,6 +27,7 @@ module EffectiveResources
|
|
27
27
|
ActiveRecord::Base.extend(ActsAsSlugged::Base)
|
28
28
|
ActiveRecord::Base.extend(ActsAsStatused::Base)
|
29
29
|
ActiveRecord::Base.extend(ActsAsWizard::Base)
|
30
|
+
ActiveRecord::Base.extend(HasManyRichTexts::Base)
|
30
31
|
|
31
32
|
ActiveRecord::Base.extend(EffectiveDeviseUser::Base)
|
32
33
|
ActiveRecord::Base.extend(EffectiveResource::Base)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: effective_resources
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.8.
|
4
|
+
version: 1.8.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Code and Effect
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-03-
|
11
|
+
date: 2021-03-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -143,6 +143,7 @@ files:
|
|
143
143
|
- app/models/concerns/acts_as_wizard.rb
|
144
144
|
- app/models/concerns/effective_devise_user.rb
|
145
145
|
- app/models/concerns/effective_resource.rb
|
146
|
+
- app/models/concerns/has_many_rich_texts.rb
|
146
147
|
- app/models/effective/access_denied.rb
|
147
148
|
- app/models/effective/action_failed.rb
|
148
149
|
- app/models/effective/attribute.rb
|