effective_resources 0.9.5 → 0.10.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/controllers/concerns/effective/crud_controller.rb +23 -546
- data/app/controllers/concerns/effective/crud_controller/actions.rb +289 -0
- data/app/controllers/concerns/effective/crud_controller/dsl.rb +81 -0
- data/app/controllers/concerns/effective/crud_controller/paths.rb +87 -0
- data/app/controllers/concerns/effective/crud_controller/permitted_params.rb +66 -0
- data/app/controllers/concerns/effective/crud_controller/save.rb +77 -0
- data/app/controllers/concerns/effective/crud_controller/submits.rb +122 -0
- data/app/helpers/effective_resources_helper.rb +51 -52
- data/app/helpers/effective_resources_private_helper.rb +69 -0
- data/app/models/concerns/effective_resource.rb +24 -0
- data/app/models/effective/model_reader.rb +29 -0
- data/app/models/effective/resource.rb +6 -2
- data/app/models/effective/resources/actions.rb +10 -10
- data/app/models/effective/resources/associations.rb +5 -0
- data/app/models/effective/resources/attributes.rb +40 -27
- data/app/models/effective/resources/controller.rb +81 -0
- data/app/models/effective/resources/forms.rb +0 -51
- data/app/models/effective/resources/init.rb +19 -17
- data/app/models/effective/resources/klass.rb +6 -8
- data/app/models/effective/resources/model.rb +23 -0
- data/app/models/effective/resources/naming.rb +7 -3
- data/app/models/effective/resources/paths.rb +4 -63
- data/app/models/effective/resources/relation.rb +4 -1
- data/app/models/effective/resources/sql.rb +1 -1
- data/app/views/application/create.js.erb +1 -1
- data/app/views/application/edit.html.haml +2 -2
- data/app/views/application/index.html.haml +1 -1
- data/app/views/application/member_action.js.erb +1 -1
- data/app/views/application/new.html.haml +3 -1
- data/app/views/application/show.html.haml +1 -1
- data/app/views/application/update.js.erb +1 -1
- data/app/views/effective/resource/_actions.html.haml +3 -32
- data/app/views/effective/resource/_actions_dropleft.html.haml +4 -26
- data/app/views/effective/resource/_actions_glyphicons.html.haml +4 -10
- data/lib/effective_resources/engine.rb +1 -0
- data/lib/effective_resources/version.rb +1 -1
- metadata +14 -3
@@ -7,7 +7,7 @@ module Effective
|
|
7
7
|
end
|
8
8
|
|
9
9
|
def datatable_klass
|
10
|
-
|
10
|
+
if defined?(EffectiveDatatables)
|
11
11
|
"#{namespaced_class_name.pluralize}Datatable".safe_constantize ||
|
12
12
|
"#{class_name.pluralize.camelize}Datatable".safe_constantize ||
|
13
13
|
"#{name.pluralize.camelize}Datatable".safe_constantize ||
|
@@ -18,13 +18,11 @@ module Effective
|
|
18
18
|
end
|
19
19
|
|
20
20
|
def controller_klass
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
"#{initialized_name.to_s.classify}Controller".safe_constantize
|
27
|
-
)
|
21
|
+
"#{namespaced_class_name.pluralize}Controller".safe_constantize ||
|
22
|
+
"#{class_name.pluralize.classify}Controller".safe_constantize ||
|
23
|
+
"#{name.pluralize.classify}Controller".safe_constantize ||
|
24
|
+
"#{initialized_name.to_s.classify.pluralize}Controller".safe_constantize ||
|
25
|
+
"#{initialized_name.to_s.classify}Controller".safe_constantize
|
28
26
|
end
|
29
27
|
|
30
28
|
def active_record?
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Effective
|
2
|
+
module Resources
|
3
|
+
module Model
|
4
|
+
attr_accessor :model # As defined by effective_resource do block in a model file
|
5
|
+
|
6
|
+
def _initialize_model(&block)
|
7
|
+
@model = ModelReader.new(&block)
|
8
|
+
|
9
|
+
# If effective_developer is in live mode, this will cause it to refresh the class
|
10
|
+
ActiveSupport.run_load_hooks(:effective_resource, klass)
|
11
|
+
end
|
12
|
+
|
13
|
+
def model
|
14
|
+
@model || (klass.effective_resource.model if klass.respond_to?(:effective_resource) && klass.effective_resource)
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
|
22
|
+
|
23
|
+
|
@@ -4,7 +4,7 @@ module Effective
|
|
4
4
|
SPLIT = /\/|::/ # / or ::
|
5
5
|
|
6
6
|
def name # 'post'
|
7
|
-
@name ||= (klass.
|
7
|
+
@name ||= ((klass.present? ? klass.name : initialized_name).to_s.split(SPLIT).last || '').singularize.underscore
|
8
8
|
end
|
9
9
|
|
10
10
|
def plural_name # 'posts'
|
@@ -16,7 +16,7 @@ module Effective
|
|
16
16
|
end
|
17
17
|
|
18
18
|
def class_name # 'Effective::Post'
|
19
|
-
@model_klass.
|
19
|
+
@model_klass ? @model_klass.name : name.classify
|
20
20
|
end
|
21
21
|
|
22
22
|
def class_path # 'effective'
|
@@ -32,13 +32,17 @@ module Effective
|
|
32
32
|
end
|
33
33
|
|
34
34
|
def namespaces # ['admin', 'things']
|
35
|
-
@namespaces
|
35
|
+
@namespaces || []
|
36
36
|
end
|
37
37
|
|
38
38
|
def human_name
|
39
39
|
class_name.gsub('::', ' ').underscore.gsub('_', ' ')
|
40
40
|
end
|
41
41
|
|
42
|
+
def human_plural_name
|
43
|
+
class_name.pluralize.gsub('::', ' ').underscore.gsub('_', ' ')
|
44
|
+
end
|
45
|
+
|
42
46
|
end
|
43
47
|
end
|
44
48
|
end
|
@@ -2,69 +2,6 @@ module Effective
|
|
2
2
|
module Resources
|
3
3
|
module Paths
|
4
4
|
|
5
|
-
#
|
6
|
-
# TODO: Delete these. Once effective_developer is updated
|
7
|
-
#
|
8
|
-
# # Controller REST helper paths
|
9
|
-
# def index_path(check: false)
|
10
|
-
# path = [namespace, plural_name, 'path'].compact * '_'
|
11
|
-
# path if (!check || path_exists?(path))
|
12
|
-
# end
|
13
|
-
|
14
|
-
# def new_path(check: false)
|
15
|
-
# path = ['new', namespace, name, 'path'].compact * '_'
|
16
|
-
# path if (!check || path_exists?(path))
|
17
|
-
# end
|
18
|
-
|
19
|
-
# def show_path(check: false)
|
20
|
-
# path = [namespace, name, 'path'].compact * '_'
|
21
|
-
# path if (!check || path_exists?(path, 1))
|
22
|
-
# end
|
23
|
-
|
24
|
-
# def destroy_path(check: false)
|
25
|
-
# path = [namespace, name, 'path'].compact * '_'
|
26
|
-
# path if (!check || path_exists?(path, 1, :delete))
|
27
|
-
# end
|
28
|
-
|
29
|
-
# def edit_path(check: false)
|
30
|
-
# path = ['edit', namespace, name, 'path'].compact * '_'
|
31
|
-
# path if (!check || path_exists?(path, 1))
|
32
|
-
# end
|
33
|
-
|
34
|
-
# def action_path(action, check: false)
|
35
|
-
# path = [action, namespace, name, 'path'].compact * '_'
|
36
|
-
# path if (!check || path_exists?(path, 1, :any))
|
37
|
-
# end
|
38
|
-
|
39
|
-
# def action_post_path(action, check: false)
|
40
|
-
# path = [action, namespace, name, 'path'].compact * '_'
|
41
|
-
# path if (!check || path_exists?(path, 1, :post) || path_exists?(path, 1, :put) || path_exists?(path, 1, :patch))
|
42
|
-
# end
|
43
|
-
|
44
|
-
# def path_exists?(path, param = nil, verb = :get)
|
45
|
-
# routes = Rails.application.routes
|
46
|
-
|
47
|
-
# return false unless routes.url_helpers.respond_to?(path)
|
48
|
-
# (routes.recognize_path(routes.url_helpers.send(path, param), method: verb).present? rescue false)
|
49
|
-
# end
|
50
|
-
|
51
|
-
# # _helper methods also put in the (@thing)
|
52
|
-
# alias_method :index_path_helper, :index_path
|
53
|
-
# alias_method :new_path_helper, :new_path
|
54
|
-
|
55
|
-
# def show_path_helper(at: true)
|
56
|
-
# show_path + '(' + (at ? '@' : '') + name + ')'
|
57
|
-
# end
|
58
|
-
|
59
|
-
# def edit_path_helper(at: true)
|
60
|
-
# edit_path + '(' + (at ? '@' : '') + name + ')'
|
61
|
-
# end
|
62
|
-
|
63
|
-
# def action_path_helper(action, at: true)
|
64
|
-
# action_path(action) + '(' + (at ? '@' : '') + name + ')'
|
65
|
-
# end
|
66
|
-
|
67
|
-
# Default file paths
|
68
5
|
def model_file
|
69
6
|
File.join('app/models', class_path.to_s, "#{name}.rb")
|
70
7
|
end
|
@@ -81,6 +18,10 @@ module Effective
|
|
81
18
|
File.join('app/views', namespace.to_s, (namespace.present? ? '' : class_path), plural_name, "#{'_' if partial}#{action}.html.haml")
|
82
19
|
end
|
83
20
|
|
21
|
+
def flat_view_file(action = :index, partial: false)
|
22
|
+
File.join('app/views', plural_name, "#{'_' if partial}#{action}.html.haml")
|
23
|
+
end
|
24
|
+
|
84
25
|
end
|
85
26
|
end
|
86
27
|
end
|
@@ -1,7 +1,10 @@
|
|
1
1
|
module Effective
|
2
2
|
module Resources
|
3
3
|
module Relation
|
4
|
-
|
4
|
+
|
5
|
+
def relation
|
6
|
+
@relation ||= klass.where(nil)
|
7
|
+
end
|
5
8
|
|
6
9
|
# When Effective::Resource is initialized with an ActiveRecord relation, the following
|
7
10
|
# methods will be available to operate on that relation, and be chainable and such
|
@@ -1,5 +1,5 @@
|
|
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) %>";
|
4
|
+
EffectiveForm.remote_form_payload = "<%= j render_resource_form(@resource) %>";
|
5
5
|
EffectiveForm.remote_form_flash = <%= raw flash.to_json %>;
|
@@ -1,5 +1,5 @@
|
|
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) %>";
|
5
5
|
EffectiveForm.remote_form_flash = <%= raw flash.to_json %>;
|
@@ -1,5 +1,5 @@
|
|
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) %>";
|
4
|
+
EffectiveForm.remote_form_payload = "<%= j render_resource_form(@resource) %>";
|
5
5
|
EffectiveForm.remote_form_flash = <%= raw flash.to_json %>;
|
@@ -1,34 +1,5 @@
|
|
1
|
-
-
|
2
|
-
|
3
|
-
- name = effective_resource.human_name.titleize
|
4
|
-
= link_to "New #{name}", effective_resource.action_path(:new), title: "New #{name}", class: 'btn btn-primary'
|
5
|
-
|
6
|
-
- if actions.index(:edit)
|
7
|
-
- if EffectiveResources.authorized?(controller, :edit, resource)
|
8
|
-
= link_to 'Edit', effective_resource.action_path(:edit, resource), title: "Edit #{resource}", class: 'btn btn-secondary'
|
9
|
-
|
10
|
-
- if actions.index(:show)
|
11
|
-
- if EffectiveResources.authorized?(controller, :show, resource)
|
12
|
-
= link_to 'View', effective_resource.action_path(:show, resource), title: resource.to_s, class: 'btn btn-secondary'
|
13
|
-
|
14
|
-
- (actions - effective_resource.crud_actions).each do |action|
|
15
|
-
- if effective_resource.member_post_actions.include?(action)
|
16
|
-
- if EffectiveResources.authorized?(controller, action, resource)
|
17
|
-
= link_to action.to_s.titleize, effective_resource.action_path(action, resource), class: 'btn btn-secondary',
|
18
|
-
title: "#{action} #{resource}", data: { method: :post, confirm: "#{action.to_s.titleize} #{resource}?"}
|
19
|
-
|
20
|
-
- elsif effective_resource.member_get_actions.include?(action)
|
21
|
-
- if EffectiveResources.authorized?(controller, action, resource)
|
22
|
-
= link_to action.to_s.titleize, effective_resource.action_path(action, resource), class: 'btn btn-secondary',
|
23
|
-
title: "#{action.to_s.titleize} #{resource}"
|
24
|
-
- else
|
25
|
-
- if EffectiveResources.authorized?(controller, action, effective_resource.klass)
|
26
|
-
= link_to action.to_s.titleize, effective_resource.action_path(action), class: 'btn btn-secondary',
|
27
|
-
title: action.to_s.titleize
|
1
|
+
- permitted_resource_actions(resource, actions, effective_resource).each do |label, opts|
|
2
|
+
= link_to(label, (effective_resource.action_path(opts[:action], resource) || '#'), opts.except(:action))
|
28
3
|
|
4
|
+
= instance_exec(resource, &format_block) if local_assigns[:format_block]
|
29
5
|
= yield if block_given?
|
30
|
-
|
31
|
-
- if actions.index(:destroy)
|
32
|
-
- if EffectiveResources.authorized?(controller, :destroy, resource)
|
33
|
-
= link_to 'Delete', effective_resource.action_path(:destroy, resource), class: 'btn btn-danger',
|
34
|
-
title: "Delete #{resource}", data: { method: :delete, confirm: "Delete #{resource}?" }
|
@@ -1,28 +1,6 @@
|
|
1
1
|
= dropdown(variation: :dropleft) do
|
2
|
-
-
|
3
|
-
|
4
|
-
= dropdown_link_to 'Edit', effective_resource.action_path(:edit, resource), title: "Edit #{resource}"
|
2
|
+
- permitted_resource_actions(resource, actions, effective_resource).each do |label, opts|
|
3
|
+
= dropdown_link_to(label, (effective_resource.action_path(opts[:action], resource) || '#'), opts.except(:action, :class))
|
5
4
|
|
6
|
-
|
7
|
-
|
8
|
-
= dropdown_link_to 'View', effective_resource.action_path(:show, resource), title: resource.to_s
|
9
|
-
|
10
|
-
- (actions - effective_resource.crud_actions).each do |action|
|
11
|
-
- if effective_resource.member_post_actions.include?(action)
|
12
|
-
- if EffectiveResources.authorized?(controller, action, resource)
|
13
|
-
= dropdown_link_to action.to_s.titleize, effective_resource.action_path(action, resource),
|
14
|
-
title: "#{action} #{resource}", data: { method: :post, confirm: "#{action.to_s.titleize} #{resource}?"}
|
15
|
-
|
16
|
-
- elsif effective_resource.member_get_actions.include?(action)
|
17
|
-
- if EffectiveResources.authorized?(controller, action, resource)
|
18
|
-
= dropdown_link_to action.to_s.titleize, effective_resource.action_path(action, resource), title: "#{action.to_s.titleize} #{resource}"
|
19
|
-
- else
|
20
|
-
- if EffectiveResources.authorized?(controller, action, effective_resource.klass)
|
21
|
-
= dropdown_link_to action.to_s.titleize, effective_resource.action_path(action), title: action.to_s.titleize
|
22
|
-
|
23
|
-
= yield if block_given?
|
24
|
-
|
25
|
-
- if actions.index(:destroy)
|
26
|
-
- if EffectiveResources.authorized?(controller, :destroy, resource)
|
27
|
-
= dropdown_link_to 'Delete', effective_resource.action_path(:destroy, resource),
|
28
|
-
title: "Delete #{resource}", data: { method: :delete, confirm: "Delete #{resource}?" }
|
5
|
+
= instance_exec(resource, &format_block) if local_assigns[:format_block]
|
6
|
+
= yield(resource) if block_given?
|
@@ -1,11 +1,5 @@
|
|
1
|
-
-
|
2
|
-
|
3
|
-
= edit_icon_to effective_resource.action_path(:edit, resource)
|
1
|
+
- permitted_resource_actions(resource, actions, effective_resource).each do |label, opts|
|
2
|
+
= glyphicon_to(opts[:action], (effective_resource.action_path(opts[:action], resource) || '#'), opts.except(:action, :class))
|
4
3
|
|
5
|
-
|
6
|
-
|
7
|
-
= show_icon_to effective_resource.action_path(:show, resource)
|
8
|
-
|
9
|
-
- if actions.index(:destroy)
|
10
|
-
- if EffectiveResources.authorized?(controller, :destroy, resource)
|
11
|
-
= destroy_icon_to effective_resource.action_path(:destroy, resource), data: { method: :delete, confirm: "Really delete #{resource}?" }
|
4
|
+
= instance_exec(resource, &format_block) if local_assigns[:format_block]
|
5
|
+
= yield(resource) if block_given?
|
@@ -21,6 +21,7 @@ module EffectiveResources
|
|
21
21
|
ActiveSupport.on_load :active_record do
|
22
22
|
ActiveRecord::Base.extend(ActsAsTokened::ActiveRecord)
|
23
23
|
ActiveRecord::Base.extend(ActsAsSlugged::ActiveRecord)
|
24
|
+
ActiveRecord::Base.extend(EffectiveResource::ActiveRecord)
|
24
25
|
end
|
25
26
|
end
|
26
27
|
|
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
|
+
version: 0.10.0
|
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: 2018-
|
11
|
+
date: 2018-09-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -36,21 +36,32 @@ files:
|
|
36
36
|
- app/assets/javascripts/effective_resources.js
|
37
37
|
- app/assets/javascripts/effective_resources/effective_ujs.js
|
38
38
|
- app/controllers/concerns/effective/crud_controller.rb
|
39
|
+
- app/controllers/concerns/effective/crud_controller/actions.rb
|
40
|
+
- app/controllers/concerns/effective/crud_controller/dsl.rb
|
41
|
+
- app/controllers/concerns/effective/crud_controller/paths.rb
|
42
|
+
- app/controllers/concerns/effective/crud_controller/permitted_params.rb
|
43
|
+
- app/controllers/concerns/effective/crud_controller/save.rb
|
44
|
+
- app/controllers/concerns/effective/crud_controller/submits.rb
|
39
45
|
- app/controllers/concerns/effective/flash_messages.rb
|
40
46
|
- app/helpers/effective_resources_helper.rb
|
47
|
+
- app/helpers/effective_resources_private_helper.rb
|
41
48
|
- app/models/concerns/acts_as_slugged.rb
|
42
49
|
- app/models/concerns/acts_as_tokened.rb
|
50
|
+
- app/models/concerns/effective_resource.rb
|
43
51
|
- app/models/effective/access_denied.rb
|
44
52
|
- app/models/effective/attribute.rb
|
45
53
|
- app/models/effective/code_reader.rb
|
54
|
+
- app/models/effective/model_reader.rb
|
46
55
|
- app/models/effective/resource.rb
|
47
56
|
- app/models/effective/resources/actions.rb
|
48
57
|
- app/models/effective/resources/associations.rb
|
49
58
|
- app/models/effective/resources/attributes.rb
|
59
|
+
- app/models/effective/resources/controller.rb
|
50
60
|
- app/models/effective/resources/forms.rb
|
51
61
|
- app/models/effective/resources/init.rb
|
52
62
|
- app/models/effective/resources/instance.rb
|
53
63
|
- app/models/effective/resources/klass.rb
|
64
|
+
- app/models/effective/resources/model.rb
|
54
65
|
- app/models/effective/resources/naming.rb
|
55
66
|
- app/models/effective/resources/paths.rb
|
56
67
|
- app/models/effective/resources/relation.rb
|
@@ -92,7 +103,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
92
103
|
version: '0'
|
93
104
|
requirements: []
|
94
105
|
rubyforge_project:
|
95
|
-
rubygems_version: 2.
|
106
|
+
rubygems_version: 2.5.2.3
|
96
107
|
signing_key:
|
97
108
|
specification_version: 4
|
98
109
|
summary: Make any controller an effective resource controller.
|