effective_resources 0.4.7 → 0.4.8
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
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 326b467ef37eca6b23e074d9e63d538ebf5f53b8
|
4
|
+
data.tar.gz: 8ab92828dc5506e8fa805adf33473dbaaa01ccff
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8dbd78d7467af34c9938cb99e43e0bfc5f947397e3c40fb66e9d4ffc02d634039e47451b7961f0b9571510d1610eb44e4b7429e658a495e0822a9a555fa9a300
|
7
|
+
data.tar.gz: 96e77365add2fb7a2af01cca14ac84648c0e2a70f369ee3bd1a485227813319faeafc2b631f5e36bc9f526282bc2fcf10e0dda586537d6fed172b3f1288e6314
|
@@ -27,7 +27,7 @@ module Effective
|
|
27
27
|
end
|
28
28
|
|
29
29
|
if effective_resource.scope?(action)
|
30
|
-
self.resources ||= resource_scope.
|
30
|
+
self.resources ||= resource_scope.public_send(action)
|
31
31
|
end
|
32
32
|
|
33
33
|
self.resources ||= resource_scope.all
|
@@ -44,8 +44,8 @@ module Effective
|
|
44
44
|
def page_title(label = nil, opts = {}, &block)
|
45
45
|
raise 'expected a label or block' unless (label || block_given?)
|
46
46
|
|
47
|
-
|
48
|
-
before_action(opts) { @page_title ||= (block_given? ?
|
47
|
+
instance_exec do
|
48
|
+
before_action(opts) { @page_title ||= (block_given? ? instance_exec(&block) : label) }
|
49
49
|
end
|
50
50
|
end
|
51
51
|
|
@@ -61,17 +61,9 @@ module Effective
|
|
61
61
|
def resource_scope(obj = nil, opts = {}, &block)
|
62
62
|
raise 'expected a proc or block' unless (obj.respond_to?(:call) || block_given?)
|
63
63
|
|
64
|
-
|
64
|
+
instance_exec do
|
65
65
|
before_action(opts) do
|
66
|
-
@_effective_resource_scope ||= (
|
67
|
-
if block_given?
|
68
|
-
instance_exec(&block)
|
69
|
-
elsif obj.respond_to?(:call)
|
70
|
-
instance_exec(&obj)
|
71
|
-
else
|
72
|
-
obj
|
73
|
-
end
|
74
|
-
)
|
66
|
+
@_effective_resource_scope ||= instance_exec(&(block_given? ? block : obj))
|
75
67
|
end
|
76
68
|
end
|
77
69
|
end
|
@@ -158,10 +150,10 @@ module Effective
|
|
158
150
|
flash[:danger] = "Unable to delete #{resource_human_name}: #{resource.errors.full_messages.to_sentence}"
|
159
151
|
end
|
160
152
|
|
161
|
-
if request.referer.present? && !request.referer.include?(
|
153
|
+
if request.referer.present? && !request.referer.include?(effective_resource.show_path)
|
162
154
|
redirect_to(request.referer)
|
163
155
|
else
|
164
|
-
redirect_to(
|
156
|
+
redirect_to(resource_index_path)
|
165
157
|
end
|
166
158
|
end
|
167
159
|
|
@@ -179,17 +171,13 @@ module Effective
|
|
179
171
|
|
180
172
|
referer = request.referer.to_s
|
181
173
|
|
182
|
-
|
183
|
-
new_path = effective_resource.new_path if respond_to?(effective_resource.new_path)
|
184
|
-
show_path = effective_resource.show_path if respond_to?(effective_resource.show_path)
|
185
|
-
|
186
|
-
if edit_path && referer.end_with?(edit_path)
|
174
|
+
if resource_edit_path && referer.end_with?(resource_edit_path)
|
187
175
|
@page_title ||= "Edit #{resource}"
|
188
176
|
render :edit
|
189
|
-
elsif
|
177
|
+
elsif resource_new_path && referer.end_with?(resource_new_path)
|
190
178
|
@page_title ||= "New #{resource_name.titleize}"
|
191
179
|
render :new
|
192
|
-
elsif
|
180
|
+
elsif resource_show_path && referer.end_with?(resource_show_path)
|
193
181
|
@page_title ||= resource_name.titleize
|
194
182
|
render :show
|
195
183
|
else
|
@@ -197,7 +185,7 @@ module Effective
|
|
197
185
|
flash[:danger] = flash.now[:danger]
|
198
186
|
|
199
187
|
if referer.present? && (Rails.application.routes.recognize_path(URI(referer).path) rescue false)
|
200
|
-
redirect_back
|
188
|
+
redirect_back(fallback_location: resource_redirect_path)
|
201
189
|
else
|
202
190
|
redirect_to(resource_redirect_path)
|
203
191
|
end
|
@@ -230,18 +218,37 @@ module Effective
|
|
230
218
|
|
231
219
|
def resource_redirect_path
|
232
220
|
case params[:commit].to_s
|
233
|
-
when 'Save'
|
234
|
-
|
235
|
-
when 'Save and
|
221
|
+
when 'Save'
|
222
|
+
[resource_edit_path, resource_show_path, resource_index_path].compact.first
|
223
|
+
when 'Save and Add New'
|
224
|
+
[resource_new_path, resource_index_path].compact.first
|
225
|
+
when 'Save and Continue'
|
226
|
+
resource_index_path
|
236
227
|
when 'Save and Return'
|
237
|
-
request.referer.present? ? request.referer :
|
228
|
+
request.referer.present? ? request.referer : resource_index_path
|
238
229
|
else
|
239
|
-
|
230
|
+
[resource_edit_path, resource_show_path, resource_index_path].compact.first
|
240
231
|
end
|
241
232
|
end
|
242
233
|
|
243
234
|
def resource_index_path
|
244
|
-
effective_resource.index_path
|
235
|
+
send(effective_resource.index_path) if effective_resource.index_path(check: true)
|
236
|
+
end
|
237
|
+
|
238
|
+
def resource_new_path
|
239
|
+
send(effective_resource.new_path) if effective_resource.new_path(check: true)
|
240
|
+
end
|
241
|
+
|
242
|
+
def resource_edit_path
|
243
|
+
send(effective_resource.edit_path, resource) if effective_resource.edit_path(check: true)
|
244
|
+
end
|
245
|
+
|
246
|
+
def resource_show_path
|
247
|
+
send(effective_resource.show_path, resource) if effective_resource.show_path(check: true)
|
248
|
+
end
|
249
|
+
|
250
|
+
def resource_destroy_path
|
251
|
+
send(effective_resource.destroy_path, resource) if effective_resource.destroy_path(check: true)
|
245
252
|
end
|
246
253
|
|
247
254
|
def resource # @thing
|
@@ -303,7 +310,7 @@ module Effective
|
|
303
310
|
end
|
304
311
|
|
305
312
|
unless relation.kind_of?(ActiveRecord::Relation)
|
306
|
-
raise("unable to build
|
313
|
+
raise("unable to build resource_scope for #{effective_resource.klass || 'unknown klass'}.")
|
307
314
|
end
|
308
315
|
|
309
316
|
relation
|
@@ -322,6 +329,5 @@ module Effective
|
|
322
329
|
["#{resource_name}_params", "#{resource_plural_name}_params", 'permitted_params'].find { |name| respond_to?(name, true) } || 'params'
|
323
330
|
end
|
324
331
|
|
325
|
-
|
326
332
|
end
|
327
333
|
end
|
@@ -1,18 +1,20 @@
|
|
1
1
|
module EffectiveResourcesHelper
|
2
2
|
|
3
|
-
def simple_form_submit(form, options = {class: '
|
4
|
-
|
3
|
+
def simple_form_submit(form, options = {class: 'form-actions'}, &block)
|
4
|
+
resource = (@_effective_resource || Effective::Resource.new(controller_path))
|
5
|
+
|
6
|
+
content_tag(:div, class: options[:class]) do
|
5
7
|
[
|
6
8
|
form.button(:submit, 'Save', data: { disable_with: 'Saving...' }),
|
7
|
-
form.button(:submit, 'Save and Continue', data: { disable_with: 'Saving...' }),
|
8
|
-
form.button(:submit, 'Save and Add New', data: { disable_with: 'Saving...' }),
|
9
|
+
(form.button(:submit, 'Save and Continue', data: { disable_with: 'Saving...' }) if resource.index_path(check: true)),
|
10
|
+
(form.button(:submit, 'Save and Add New', data: { disable_with: 'Saving...' }) if resource.new_path(check: true)),
|
9
11
|
(capture(&block) if block_given?)
|
10
12
|
].compact.join(' ').html_safe
|
11
13
|
end
|
12
14
|
end
|
13
15
|
|
14
|
-
def simple_form_save(form, options = {class: '
|
15
|
-
content_tag(:
|
16
|
+
def simple_form_save(form, options = {class: 'form-actions'}, &block)
|
17
|
+
content_tag(:div, class: options[:class]) do
|
16
18
|
form.button(:submit, 'Save', data: { disable_with: 'Saving...' }) + (capture(&:block) if block_given?)
|
17
19
|
end
|
18
20
|
end
|
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: 0.4.
|
4
|
+
version: 0.4.8
|
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: 2017-09-
|
11
|
+
date: 2017-09-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|