effective_resources 1.3.5 → 1.3.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
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 00676e20bca2b28bf3ade5d56980806ab7bcb55b015681a74d8813f823f597d4
|
4
|
+
data.tar.gz: 0e69b1862f3ed5f64a2327c077cd7aef520c47ca7e7e6d6040b81b55d7777a76
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 219fbc86a55a7251655d2d67d7f46cc603a4e496613c68e5cd276b56839b3bea25f65d7e816984c8c056ef54a338aa98a396eb7c8c455dfd48e9ecfb7196cfb0
|
7
|
+
data.tar.gz: fb1ad2e01fdba48d1e401eff91f6226da6266a0d8717cc07d1d2ab7c632b281aef50d1d687e1edb07e50f4b5d8b7e1d0586c51d9abafaf9329f74812396cbe21
|
data/MIT-LICENSE
CHANGED
@@ -58,43 +58,54 @@ module EffectiveResourcesHelper
|
|
58
58
|
# you can also pass all action names and true/false such as edit: true, show: false
|
59
59
|
def render_resource_actions(resource, atts = {}, &block)
|
60
60
|
unless resource.kind_of?(ActiveRecord::Base) || resource.kind_of?(Class) || resource.kind_of?(Array) || resource.class.ancestors.include?(ActiveModel::Model)
|
61
|
-
raise 'expected first argument to be an ActiveRecord::Base object or Array of objects'
|
61
|
+
raise 'expected first argument to be an ActiveRecord::Base object or Array of objects'
|
62
62
|
end
|
63
|
-
|
63
|
+
|
64
64
|
raise 'expected attributes to be a Hash' unless atts.kind_of?(Hash)
|
65
65
|
|
66
66
|
btn_class = atts[:btn_class]
|
67
|
+
effective_resource = atts[:effective_resource]
|
68
|
+
namespace = atts[:controller_namespace] || atts[:namespace]
|
67
69
|
locals = atts[:locals] || {}
|
68
70
|
partial = atts[:partial]
|
69
71
|
spacer_template = locals[:spacer_template]
|
70
72
|
|
71
|
-
effective_resource
|
72
|
-
namespace
|
73
|
+
effective_resource ||= find_effective_resource(resource)
|
74
|
+
namespace ||= (effective_resource.namespace.to_sym if effective_resource.namespace)
|
73
75
|
|
74
76
|
# Assign actions
|
75
77
|
actions = if atts.key?(:actions) # We filter out any actions passed to us that aren't supported
|
76
|
-
available = effective_resource.actions
|
78
|
+
available = effective_resource.actions + atts[:actions].map { |k, v| v[:action] if v[:path] }.compact
|
77
79
|
atts[:actions].inject({}) { |h, (commit, opts)| h[commit] = opts if available.include?(opts[:action]); h }
|
78
80
|
else
|
79
81
|
(resource.kind_of?(Class) ? effective_resource.resource_klass_actions : effective_resource.resource_actions)
|
80
82
|
end
|
81
83
|
|
82
84
|
# Filter out false and proc false
|
83
|
-
actions = actions.select
|
85
|
+
actions = actions.select do |_, opts|
|
86
|
+
if atts[opts[:action]].respond_to?(:call)
|
87
|
+
Effective::ResourceExec.new(self, resource).instance_exec(&atts[opts[:action]])
|
88
|
+
else
|
89
|
+
atts[opts[:action]] != false
|
90
|
+
end
|
91
|
+
end
|
84
92
|
|
85
93
|
# Select Partial
|
86
94
|
partial = ['effective/resource/actions', partial.to_s].join('_') if partial.kind_of?(Symbol)
|
87
95
|
partial = (partial.presence || 'effective/resource/actions') + '.html'
|
88
96
|
|
89
97
|
# Assign Locals
|
90
|
-
locals = {
|
98
|
+
locals = {
|
99
|
+
resource: resource,
|
100
|
+
effective_resource: effective_resource,
|
101
|
+
format_block: (block if block_given?),
|
102
|
+
namespace: namespace,
|
103
|
+
actions: actions,
|
104
|
+
btn_class: (btn_class || '')
|
105
|
+
}.compact.merge(locals)
|
91
106
|
|
92
|
-
# Render
|
93
107
|
if resource.kind_of?(Array)
|
94
|
-
locals[:format_block] = block if block_given?
|
95
108
|
render(partial: partial, collection: resource, as: :resource, locals: locals.except(:resource), spacer_template: spacer_template)
|
96
|
-
elsif block_given?
|
97
|
-
render(partial, locals) { capture(&block).to_s.html_safe }
|
98
109
|
else
|
99
110
|
render(partial, locals)
|
100
111
|
end
|
@@ -16,13 +16,21 @@ module EffectiveResourcesPrivateHelper
|
|
16
16
|
(args.key?(:unless) ? !executor.instance_exec(&args[:unless]) : true) &&
|
17
17
|
EffectiveResources.authorized?(controller, action, resource)
|
18
18
|
end.inject({}) do |h, (commit, args)|
|
19
|
-
opts = args.except(:default, :only, :except, :if, :unless, :redirect, :success, :danger)
|
19
|
+
opts = args.except(:default, :only, :except, :if, :unless, :redirect, :success, :danger, :klass)
|
20
20
|
|
21
21
|
# Transform data: { ... } hash into 'data-' keys
|
22
22
|
if opts.key?(:data)
|
23
23
|
opts.delete(:data).each { |k, v| opts["data-#{k}"] ||= v }
|
24
24
|
end
|
25
25
|
|
26
|
+
if opts.key?(:path)
|
27
|
+
opts[:href] = opts.delete(:path)
|
28
|
+
end
|
29
|
+
|
30
|
+
if opts.key?(:url)
|
31
|
+
opts[:href] = opts.delete(:url)
|
32
|
+
end
|
33
|
+
|
26
34
|
# Replace resource name in any token strings
|
27
35
|
if opts.key?('data-confirm')
|
28
36
|
opts['data-confirm'] = opts['data-confirm'].gsub('@resource', (resource.to_s.presence || resource.class.name.gsub('::', ' ').underscore.gsub('_', ' ')).to_s)
|
@@ -98,6 +98,15 @@ module Effective
|
|
98
98
|
end
|
99
99
|
end
|
100
100
|
|
101
|
+
# Used by datatables
|
102
|
+
def fallback_resource_actions
|
103
|
+
{
|
104
|
+
'Show': { action: :show, default: true },
|
105
|
+
'Edit': { action: :edit, default: true },
|
106
|
+
'Delete': { action: :destroy, default: true, 'data-method' => :delete, 'data-confirm' => "Really delete @resource?" }
|
107
|
+
}
|
108
|
+
end
|
109
|
+
|
101
110
|
# This is the fallback for render_resource_actions when no actions are specified, but a class is given
|
102
111
|
# Used by Datatables new
|
103
112
|
def resource_klass_actions
|
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.3.
|
4
|
+
version: 1.3.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: 2019-06-
|
11
|
+
date: 2019-06-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|