effective_resources 1.7.7 → 1.8.3
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/controllers/concerns/effective/crud_controller/actions.rb +7 -4
- data/app/controllers/concerns/effective/crud_controller/save.rb +4 -0
- data/app/controllers/concerns/effective/flash_messages.rb +16 -3
- data/app/helpers/effective_resources_helper.rb +27 -16
- data/app/models/concerns/acts_as_slugged.rb +9 -2
- data/app/models/concerns/effective_devise_user.rb +1 -2
- data/app/models/concerns/has_many_rich_texts.rb +57 -0
- data/app/models/effective/resource.rb +1 -0
- data/app/models/effective/resources/actions.rb +4 -13
- data/app/models/effective/resources/forms.rb +2 -1
- data/app/models/effective/resources/generator.rb +31 -0
- data/app/models/effective/resources/init.rb +1 -2
- data/app/models/effective/resources/naming.rb +29 -9
- data/app/models/effective/resources/paths.rb +48 -5
- data/lib/effective_resources.rb +15 -0
- data/lib/effective_resources/engine.rb +1 -0
- data/lib/effective_resources/version.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3e9efd79bdfd45a008026c4df5eb078e141ce8291c01942aea6b40565434be38
|
4
|
+
data.tar.gz: 8f31ee7e20b727cab52b580a470a74c00d64e1f830e76153d080dab7f9788645
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0e7bd31331526a1f9bd7d68022d5cf8587c21ed142c06e8353e2b14ea1d3acc5a26af54d69dacdce1469159b0e55c4698b381fa027067dbcf1b688d47ad42f2b
|
7
|
+
data.tar.gz: ac2ffd7ccd01c8f016a99bf2f7dc6472b356a4dc489d1cdf5109fbb96bba36b642859bd28b14216b60b03309c830905b828e7f422dbc924325bd74fb9d6442b6
|
@@ -53,7 +53,7 @@ module Effective
|
|
53
53
|
|
54
54
|
respond_to do |format|
|
55
55
|
format.html { }
|
56
|
-
format.js { render('new
|
56
|
+
format.js { render('new', formats: :js) }
|
57
57
|
end
|
58
58
|
end
|
59
59
|
|
@@ -95,7 +95,7 @@ module Effective
|
|
95
95
|
|
96
96
|
respond_to do |format|
|
97
97
|
format.html { }
|
98
|
-
format.js { render('show
|
98
|
+
format.js { render('show', formats: :js) }
|
99
99
|
end
|
100
100
|
|
101
101
|
end
|
@@ -112,7 +112,7 @@ module Effective
|
|
112
112
|
|
113
113
|
respond_to do |format|
|
114
114
|
format.html { }
|
115
|
-
format.js { render('edit
|
115
|
+
format.js { render('edit', formats: :js) }
|
116
116
|
end
|
117
117
|
|
118
118
|
end
|
@@ -176,7 +176,10 @@ module Effective
|
|
176
176
|
|
177
177
|
respond_to do |format|
|
178
178
|
format.html { }
|
179
|
-
format.js
|
179
|
+
format.js do
|
180
|
+
template = template_present?(action) ? action : 'member_action'
|
181
|
+
render(template, formats: :js, locals: { action: action })
|
182
|
+
end
|
180
183
|
end
|
181
184
|
|
182
185
|
return
|
@@ -76,6 +76,7 @@ module Effective
|
|
76
76
|
def resource_flash(status, resource, action, e: nil)
|
77
77
|
submit = commit_action(action)
|
78
78
|
message = submit[status].respond_to?(:call) ? instance_exec(&submit[status]) : submit[status]
|
79
|
+
|
79
80
|
return message.gsub('@resource', resource.to_s) if message.present?
|
80
81
|
return nil if message.blank? && submit.key?(status)
|
81
82
|
|
@@ -93,6 +94,9 @@ module Effective
|
|
93
94
|
|
94
95
|
# Should return a new resource based on the passed one
|
95
96
|
def duplicate_resource(resource)
|
97
|
+
return resource.duplicate if resource.respond_to?(:duplicate)
|
98
|
+
return resource.duplicate! if resource.respond_to?(:duplicate!)
|
99
|
+
return resource.deep_dup if resource.respond_to?(:deep_dup)
|
96
100
|
resource.dup
|
97
101
|
end
|
98
102
|
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Effective
|
2
4
|
module FlashMessages
|
3
5
|
extend ActiveSupport::Concern
|
@@ -6,7 +8,11 @@ module Effective
|
|
6
8
|
def flash_success(resource, action = nil, name: nil)
|
7
9
|
raise 'expected an ActiveRecord resource' unless (name || resource.class.respond_to?(:model_name))
|
8
10
|
|
9
|
-
|
11
|
+
name ||= begin
|
12
|
+
resource.destroyed? ? resource.class.model_name.to_s.downcase.split('::').last : resource.to_s.presence
|
13
|
+
end
|
14
|
+
|
15
|
+
"Successfully #{action_verb(action)} #{name || 'resource'}".html_safe
|
10
16
|
end
|
11
17
|
|
12
18
|
# flash.now[:danger] = flash_danger(@post)
|
@@ -18,7 +24,9 @@ module Effective
|
|
18
24
|
|
19
25
|
messages = flash_errors(resource, e: e)
|
20
26
|
|
21
|
-
name ||=
|
27
|
+
name ||= begin
|
28
|
+
resource.destroyed? ? resource.class.model_name.to_s.downcase.split('::').last : resource.to_s.presence
|
29
|
+
end
|
22
30
|
|
23
31
|
["Unable to #{action}", (" #{name}" if name), (": #{messages}" if messages)].compact.join.html_safe
|
24
32
|
end
|
@@ -27,7 +35,10 @@ module Effective
|
|
27
35
|
def flash_errors(resource, e: nil)
|
28
36
|
raise 'expected an ActiveRecord resource' unless resource.respond_to?(:errors)
|
29
37
|
|
30
|
-
messages = resource.errors.map do |
|
38
|
+
messages = resource.errors.map do |error|
|
39
|
+
attribute = error.respond_to?(:attribute) ? error.attribute : error
|
40
|
+
message = error.respond_to?(:message) ? error.message : resource.errors[attribute].to_sentence
|
41
|
+
|
31
42
|
if message[0] == message[0].upcase # If the error begins with a capital letter
|
32
43
|
message
|
33
44
|
elsif attribute == :base
|
@@ -52,6 +63,8 @@ module Effective
|
|
52
63
|
'deleted'
|
53
64
|
elsif word == 'undo'
|
54
65
|
'undid'
|
66
|
+
elsif word == 'run'
|
67
|
+
'ran'
|
55
68
|
elsif word.end_with?('e')
|
56
69
|
action.sub(word, word + 'd')
|
57
70
|
elsif ['a', 'i', 'o', 'u'].include?(word[-1])
|
@@ -151,16 +151,24 @@ module EffectiveResourcesHelper
|
|
151
151
|
atts = { :namespace => (effective_resource.namespace.to_sym if effective_resource.namespace), effective_resource.name.to_sym => resource }.compact.merge(atts)
|
152
152
|
|
153
153
|
if lookup_context.template_exists?("form_#{action}", controller._prefixes, :partial)
|
154
|
-
render
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
render
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
154
|
+
return render("form_#{action}", atts)
|
155
|
+
end
|
156
|
+
|
157
|
+
if lookup_context.template_exists?('form', controller._prefixes, :partial)
|
158
|
+
return render('form', atts)
|
159
|
+
end
|
160
|
+
|
161
|
+
effective_resource.view_paths.each do |view_path|
|
162
|
+
if lookup_context.template_exists?("form_#{action}", [view_path], :partial)
|
163
|
+
return render(view_path + '/' + "form_#{action}", atts)
|
164
|
+
end
|
165
|
+
|
166
|
+
if lookup_context.template_exists?('form', [view_path], :partial)
|
167
|
+
return render(view_path + '/' + 'form', atts)
|
168
|
+
end
|
163
169
|
end
|
170
|
+
|
171
|
+
render('form', atts) # Will raise the regular error
|
164
172
|
end
|
165
173
|
|
166
174
|
# Similar to render_resource_form
|
@@ -177,15 +185,18 @@ module EffectiveResourcesHelper
|
|
177
185
|
atts = { :namespace => (effective_resource.namespace.to_sym if effective_resource.namespace), effective_resource.name.to_sym => resource }.compact.merge(atts)
|
178
186
|
|
179
187
|
if lookup_context.template_exists?(effective_resource.name, controller._prefixes, :partial)
|
180
|
-
render(effective_resource.name, atts)
|
181
|
-
elsif lookup_context.template_exists?(effective_resource.name, [effective_resource.plural_name], :partial)
|
182
|
-
render(effective_resource.plural_name + '/' + effective_resource.name, atts)
|
183
|
-
elsif lookup_context.template_exists?(effective_resource.name, [effective_resource.name], :partial)
|
184
|
-
render(effective_resource.name + '/' + effective_resource.name, atts)
|
185
|
-
else
|
186
|
-
render(resource, atts) # Will raise the regular error
|
188
|
+
return render(effective_resource.name, atts)
|
187
189
|
end
|
190
|
+
|
191
|
+
effective_resource.view_paths.each do |view_path|
|
192
|
+
if lookup_context.template_exists?(effective_resource.name, [view_path], :partial)
|
193
|
+
return render(view_path + '/' + effective_resource.name, atts)
|
194
|
+
end
|
195
|
+
end
|
196
|
+
|
197
|
+
render(resource, atts) # Will raise the regular error
|
188
198
|
end
|
199
|
+
alias_method :render_resource, :render_resource_partial
|
189
200
|
|
190
201
|
# Tableize attributes
|
191
202
|
# This is used by effective_orders, effective_logging, effective_trash and effective_mergery
|
@@ -16,7 +16,9 @@ module ActsAsSlugged
|
|
16
16
|
included do
|
17
17
|
extend FinderMethods
|
18
18
|
|
19
|
-
before_validation
|
19
|
+
before_validation do
|
20
|
+
assign_attributes(slug: build_slug) if slug.blank?
|
21
|
+
end
|
20
22
|
|
21
23
|
validates :slug,
|
22
24
|
presence: true, uniqueness: true, exclusion: { in: excluded_slugs }, length: { maximum: 255 },
|
@@ -40,11 +42,16 @@ module ActsAsSlugged
|
|
40
42
|
|
41
43
|
where(slug: args.first).or(where(id: args.first)).first || raise(::ActiveRecord::RecordNotFound.new("Couldn't find #{name} with 'slug'=#{args.first}"))
|
42
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
|
+
|
43
50
|
end
|
44
51
|
|
45
52
|
# Instance Methods
|
46
53
|
def build_slug
|
47
|
-
slug =
|
54
|
+
slug = to_s.parameterize.downcase[0, 250]
|
48
55
|
|
49
56
|
if self.class.excluded_slugs.include?(slug)
|
50
57
|
slug = "#{slug}-#{self.class.name.demodulize.parameterize}"
|
@@ -66,6 +66,7 @@ module EffectiveDeviseUser
|
|
66
66
|
|
67
67
|
module ClassMethods
|
68
68
|
def permitted_sign_up_params # Should contain all fields as per views/users/_sign_up_fields
|
69
|
+
raise('please define a self.permitted_sign_up_params')
|
69
70
|
[:email, :password, :password_confirmation, :first_name, :last_name, :name, :login]
|
70
71
|
end
|
71
72
|
|
@@ -152,8 +153,6 @@ module EffectiveDeviseUser
|
|
152
153
|
def send_devise_notification(notification, *args)
|
153
154
|
raise('expected args Hash') unless args.respond_to?(:last) && args.last.kind_of?(Hash)
|
154
155
|
|
155
|
-
|
156
|
-
|
157
156
|
if defined?(Tenant)
|
158
157
|
tenant = Tenant.current || raise('expected a current tenant')
|
159
158
|
args.last[:tenant] ||= tenant
|
@@ -0,0 +1,57 @@
|
|
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
|
+
super if block_given?
|
43
|
+
super unless respond_to?(method)
|
44
|
+
|
45
|
+
method = method.to_s
|
46
|
+
name = method.chomp('=').sub('rich_text_', '')
|
47
|
+
|
48
|
+
if method.end_with?('=')
|
49
|
+
send(:assign_rich_text_body, name, *args)
|
50
|
+
elsif args.length == 0
|
51
|
+
send(:rich_text, name, *args)
|
52
|
+
else
|
53
|
+
super
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
end
|
@@ -7,6 +7,7 @@ module Effective
|
|
7
7
|
include Effective::Resources::Init
|
8
8
|
include Effective::Resources::Instance
|
9
9
|
include Effective::Resources::Forms
|
10
|
+
include Effective::Resources::Generator
|
10
11
|
include Effective::Resources::Klass
|
11
12
|
include Effective::Resources::Model
|
12
13
|
include Effective::Resources::Naming
|
@@ -9,7 +9,7 @@ module Effective
|
|
9
9
|
|
10
10
|
# This will have been set by init from crud_controller, or from a class and namespace
|
11
11
|
def controller_path
|
12
|
-
@controller_path ||=
|
12
|
+
@controller_path ||= route_name #[namespace, plural_name].compact * '/')
|
13
13
|
end
|
14
14
|
|
15
15
|
def routes
|
@@ -20,7 +20,7 @@ module Effective
|
|
20
20
|
# Check from controller_path. This is generally correct.
|
21
21
|
engines.each do |engine|
|
22
22
|
routes = engine.routes.routes.select do |route|
|
23
|
-
controller_path == route.defaults[:controller] && !route.name.
|
23
|
+
controller_path == route.defaults[:controller] && !(route.name || '').end_with?('root')
|
24
24
|
end
|
25
25
|
|
26
26
|
if routes.present?
|
@@ -29,20 +29,11 @@ module Effective
|
|
29
29
|
end
|
30
30
|
|
31
31
|
if routes.blank?
|
32
|
-
matches =
|
33
|
-
[namespace, route_name.pluralize].compact.join('/'),
|
34
|
-
[namespace, route_name].compact.join('/'),
|
35
|
-
['effective', namespace, route_name.pluralize].compact.join('/'),
|
36
|
-
['effective', namespace, route_name].compact.join('/'),
|
37
|
-
[namespace, plural_name].compact.join('/'),
|
38
|
-
[namespace, name].compact.join('/'),
|
39
|
-
['effective', namespace, plural_name].compact.join('/'),
|
40
|
-
['effective', namespace, name].compact.join('/')
|
41
|
-
]
|
32
|
+
matches = route_name_fallbacks()
|
42
33
|
|
43
34
|
engines.each do |engine|
|
44
35
|
routes = engine.routes.routes.select do |route|
|
45
|
-
(matches & [route.defaults[:controller]]).present? && !route.name.
|
36
|
+
(matches & [route.defaults[:controller]]).present? && !(route.name || '').end_with?('root')
|
46
37
|
end
|
47
38
|
|
48
39
|
if routes.present?
|
@@ -7,6 +7,7 @@ module Effective
|
|
7
7
|
case (type || sql_type(name))
|
8
8
|
when :belongs_to
|
9
9
|
{ as: :select }.merge(search_form_field_collection(belongs_to(name)))
|
10
|
+
|
10
11
|
when :belongs_to_polymorphic
|
11
12
|
constant_pluralized = name.to_s.upcase
|
12
13
|
constant = name.to_s.pluralize.upcase
|
@@ -18,7 +19,7 @@ module Effective
|
|
18
19
|
collection ||= (klass.const_get(constant_pluralized) rescue nil) if defined?("#{klass.name}::#{constant_pluralized}")
|
19
20
|
end
|
20
21
|
|
21
|
-
{ as: :select, polymorphic: true, collection: collection }.compact
|
22
|
+
{ as: :select, polymorphic: true, collection: (collection || []) }.compact
|
22
23
|
when :has_and_belongs_to_many
|
23
24
|
{ as: :select }.merge(search_form_field_collection(has_and_belongs_to_many(name)))
|
24
25
|
when :has_many
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module Effective
|
2
|
+
module Resources
|
3
|
+
module Generator
|
4
|
+
|
5
|
+
def module_name
|
6
|
+
return nil unless class_name.split('::').length > 1
|
7
|
+
class_name.split('::').first
|
8
|
+
end
|
9
|
+
|
10
|
+
# Acpa
|
11
|
+
def module_namespace
|
12
|
+
return nil unless namespaces.present?
|
13
|
+
Array(namespaces + [nil]).map { |name| name.to_s.classify } * '::'
|
14
|
+
end
|
15
|
+
|
16
|
+
# Admin::Courses
|
17
|
+
def module_namespaced
|
18
|
+
(Array(namespaces).map { |name| name.to_s.classify } + [plural_name.classify.pluralize]) * '::'
|
19
|
+
end
|
20
|
+
|
21
|
+
def namespaced_class_name # 'Admin::Effective::Post'
|
22
|
+
(Array(namespaces).map { |name| name.to_s.classify } + [class_name]) * '::'
|
23
|
+
end
|
24
|
+
|
25
|
+
def namespaced_module_name # 'Admin::EffectivePosts'
|
26
|
+
Array(namespaces).map { |name| name.to_s.classify }.join('::') + '::' + class_name.gsub('::', '')
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -19,8 +19,27 @@ module Effective
|
|
19
19
|
@initialized_name
|
20
20
|
end
|
21
21
|
|
22
|
+
# There could be a few, this is the best guess.
|
22
23
|
def route_name # 'post' initialized from the controller_path/initialized_name and not the class
|
23
|
-
|
24
|
+
names = class_name.split('::')
|
25
|
+
|
26
|
+
if names.length > 1
|
27
|
+
Array(names[0]) + namespaces + Array(names[1..-1])
|
28
|
+
else
|
29
|
+
namespaces + names
|
30
|
+
end.compact.map(&:downcase).join('/').pluralize
|
31
|
+
end
|
32
|
+
|
33
|
+
def route_name_fallbacks
|
34
|
+
mod = class_name.split('::').first.downcase
|
35
|
+
|
36
|
+
matches = [
|
37
|
+
route_name.singularize,
|
38
|
+
[*namespace, plural_name].join('/'),
|
39
|
+
[*namespace, name].join('/'),
|
40
|
+
[mod, *namespace, plural_name].join('/'),
|
41
|
+
[mod, *namespace, name].join('/')
|
42
|
+
]
|
24
43
|
end
|
25
44
|
|
26
45
|
def class_name # 'Effective::Post'
|
@@ -31,14 +50,6 @@ module Effective
|
|
31
50
|
class_name.split('::')[0...-1].map { |name| name.underscore } * '/'
|
32
51
|
end
|
33
52
|
|
34
|
-
def namespaced_class_name # 'Admin::Effective::Post'
|
35
|
-
(Array(namespaces).map { |name| name.to_s.classify } + [class_name]) * '::'
|
36
|
-
end
|
37
|
-
|
38
|
-
def namespaced_module_name # 'Admin::EffectivePosts'
|
39
|
-
Array(namespaces).map { |name| name.to_s.classify }.join('::') + '::' + class_name.gsub('::', '')
|
40
|
-
end
|
41
|
-
|
42
53
|
def namespace # 'admin/things'
|
43
54
|
(namespaces.join('/') if namespaces.present?)
|
44
55
|
end
|
@@ -55,6 +66,15 @@ module Effective
|
|
55
66
|
name.pluralize.gsub('::', ' ').underscore.gsub('_', ' ')
|
56
67
|
end
|
57
68
|
|
69
|
+
def tenant
|
70
|
+
return nil unless defined?(Tenant)
|
71
|
+
return nil unless klass.present?
|
72
|
+
return nil unless class_name.include?('::')
|
73
|
+
|
74
|
+
name = class_name.split('::').first.downcase.to_sym
|
75
|
+
name if Rails.application.config.tenants[name].present?
|
76
|
+
end
|
77
|
+
|
58
78
|
end
|
59
79
|
end
|
60
80
|
end
|
@@ -1,25 +1,68 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Effective
|
2
4
|
module Resources
|
3
5
|
module Paths
|
4
6
|
|
7
|
+
def tenant_path
|
8
|
+
return unless tenant.present?
|
9
|
+
Tenant.engine_path(tenant).sub("#{Rails.root}/", '')
|
10
|
+
end
|
11
|
+
|
5
12
|
def model_file
|
6
|
-
File.join('app/models', class_path
|
13
|
+
File.join(*[tenant_path, 'app/models', class_path, "#{name}.rb"].compact)
|
7
14
|
end
|
8
15
|
|
9
16
|
def controller_file
|
10
|
-
File.join('app/controllers', namespace
|
17
|
+
File.join(*[tenant_path, 'app/controllers', class_path, namespace, "#{plural_name}_controller.rb"].compact)
|
11
18
|
end
|
12
19
|
|
13
20
|
def datatable_file
|
14
|
-
File.join('app/datatables', namespace
|
21
|
+
File.join(*[tenant_path, 'app/datatables', class_path, namespace, "#{plural_name}_datatable.rb"].compact)
|
15
22
|
end
|
16
23
|
|
17
24
|
def view_file(action = :index, partial: false)
|
18
|
-
File.join('app/views',
|
25
|
+
File.join(*[tenant_path, 'app/views', class_path, namespace, plural_name, "#{'_' if partial}#{action}.html.haml"].compact)
|
26
|
+
end
|
27
|
+
|
28
|
+
def view_file_path(action = :index)
|
29
|
+
File.join(*[class_path, namespace, plural_name, action].compact)
|
19
30
|
end
|
20
31
|
|
21
32
|
def flat_view_file(action = :index, partial: false)
|
22
|
-
File.join('app/views', plural_name, "#{'_' if partial}#{action}.html.haml")
|
33
|
+
File.join(*[tenant_path, 'app/views', class_path, plural_name, "#{'_' if partial}#{action}.html.haml"].compact)
|
34
|
+
end
|
35
|
+
|
36
|
+
def routes_file
|
37
|
+
File.join(*[tenant_path, 'config/routes.rb'].compact)
|
38
|
+
end
|
39
|
+
|
40
|
+
def abilities_file
|
41
|
+
File.join(*[tenant_path, 'app/models/', class_path, 'ability.rb'].compact)
|
42
|
+
end
|
43
|
+
|
44
|
+
def menu_file
|
45
|
+
File.join(*[tenant_path, 'app/views/layouts', class_path, '_navbar.html.haml'].compact)
|
46
|
+
end
|
47
|
+
|
48
|
+
def admin_menu_file
|
49
|
+
File.join(*[tenant_path, 'app/views/layouts', class_path, '_navbar_admin.html.haml'].compact)
|
50
|
+
end
|
51
|
+
|
52
|
+
# Used by render_resource_partial and render_resource_form to guess the view path
|
53
|
+
def view_paths
|
54
|
+
mod = class_name.split('::').first.downcase
|
55
|
+
|
56
|
+
[
|
57
|
+
[mod, *namespace, plural_name].join('/'),
|
58
|
+
[mod, *namespace, name].join('/'),
|
59
|
+
[*namespace, mod, plural_name].join('/'),
|
60
|
+
[*namespace, mod, name].join('/'),
|
61
|
+
[mod, plural_name].join('/'),
|
62
|
+
[mod, name].join('/'),
|
63
|
+
[*namespace, plural_name].join('/'),
|
64
|
+
[*namespace, name].join('/')
|
65
|
+
]
|
23
66
|
end
|
24
67
|
|
25
68
|
end
|
data/lib/effective_resources.rb
CHANGED
@@ -31,4 +31,19 @@ module EffectiveResources
|
|
31
31
|
(['Save', 'Continue', 'Add New'] & Array(config.default_submits)).inject({}) { |h, v| h[v] = true; h }
|
32
32
|
end
|
33
33
|
|
34
|
+
# Utilities
|
35
|
+
|
36
|
+
def self.truthy?(value)
|
37
|
+
if defined?(::ActiveRecord::ConnectionAdapters::Column::TRUE_VALUES) # Rails <5
|
38
|
+
::ActiveRecord::ConnectionAdapters::Column::TRUE_VALUES.include?(value)
|
39
|
+
else
|
40
|
+
::ActiveRecord::Type::Boolean.new.cast(value)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def self.deliver_method
|
45
|
+
config = Rails.application.config
|
46
|
+
(config.respond_to?(:active_job) && config.active_job.queue_adapter) ? :deliver_later : :deliver_now
|
47
|
+
end
|
48
|
+
|
34
49
|
end
|
@@ -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.
|
4
|
+
version: 1.8.3
|
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-
|
11
|
+
date: 2021-03-05 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
|
@@ -155,6 +156,7 @@ files:
|
|
155
156
|
- app/models/effective/resources/attributes.rb
|
156
157
|
- app/models/effective/resources/controller.rb
|
157
158
|
- app/models/effective/resources/forms.rb
|
159
|
+
- app/models/effective/resources/generator.rb
|
158
160
|
- app/models/effective/resources/init.rb
|
159
161
|
- app/models/effective/resources/instance.rb
|
160
162
|
- app/models/effective/resources/klass.rb
|