effective_resources 1.7.8 → 1.8.4
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/flash_messages.rb +2 -2
- data/app/helpers/effective_resources_helper.rb +1 -0
- data/app/models/concerns/acts_as_slugged.rb +5 -0
- data/app/models/concerns/effective_devise_user.rb +1 -2
- data/app/models/concerns/has_many_rich_texts.rb +54 -0
- data/app/models/effective/resource.rb +1 -0
- 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 +9 -8
- data/app/models/effective/resources/paths.rb +32 -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: 33448d396358208a6585b8beeff84f22b659bfc3676acbf9ed087d647acc56d3
|
4
|
+
data.tar.gz: 56b33689f40c4988cb600175623f5b3a3a4dde6192630d86188080244f5333ee
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d8e3d0a86b310e31d991deb85b090c62167ba713e986d8a6c8ba30b3c3fa5583014d406af6e7d21cdbcc1f34fe5c8e8ec541d29e25835b724ebaa87e13b4cae1
|
7
|
+
data.tar.gz: 5908aa0138e84275ad07dcb500ccce0601a9ba7864ee98711eab0712a0075ea4fd0ad9adc33842fd423d3f6bc71d7f4d53319c3fbced1ec2ff90f28d8e27b527
|
@@ -36,8 +36,8 @@ module Effective
|
|
36
36
|
raise 'expected an ActiveRecord resource' unless resource.respond_to?(:errors)
|
37
37
|
|
38
38
|
messages = resource.errors.map do |error|
|
39
|
-
attribute = error.respond_to?(:attribute) ? error.attribute : error
|
40
|
-
message = error.respond_to?(:message) ? error.message :
|
39
|
+
attribute = error.respond_to?(:attribute) ? error.attribute : error
|
40
|
+
message = error.respond_to?(:message) ? error.message : resource.errors[attribute].to_sentence
|
41
41
|
|
42
42
|
if message[0] == message[0].upcase # If the error begins with a capital letter
|
43
43
|
message
|
@@ -196,6 +196,7 @@ module EffectiveResourcesHelper
|
|
196
196
|
|
197
197
|
render(resource, atts) # Will raise the regular error
|
198
198
|
end
|
199
|
+
alias_method :render_resource, :render_resource_partial
|
199
200
|
|
200
201
|
# Tableize attributes
|
201
202
|
# This is used by effective_orders, effective_logging, effective_trash and effective_mergery
|
@@ -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
|
@@ -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,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
|
@@ -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
|
@@ -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
|
@@ -50,14 +50,6 @@ module Effective
|
|
50
50
|
class_name.split('::')[0...-1].map { |name| name.underscore } * '/'
|
51
51
|
end
|
52
52
|
|
53
|
-
def namespaced_class_name # 'Admin::Effective::Post'
|
54
|
-
(Array(namespaces).map { |name| name.to_s.classify } + [class_name]) * '::'
|
55
|
-
end
|
56
|
-
|
57
|
-
def namespaced_module_name # 'Admin::EffectivePosts'
|
58
|
-
Array(namespaces).map { |name| name.to_s.classify }.join('::') + '::' + class_name.gsub('::', '')
|
59
|
-
end
|
60
|
-
|
61
53
|
def namespace # 'admin/things'
|
62
54
|
(namespaces.join('/') if namespaces.present?)
|
63
55
|
end
|
@@ -74,6 +66,15 @@ module Effective
|
|
74
66
|
name.pluralize.gsub('::', ' ').underscore.gsub('_', ' ')
|
75
67
|
end
|
76
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
|
+
|
77
78
|
end
|
78
79
|
end
|
79
80
|
end
|
@@ -1,25 +1,52 @@
|
|
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)
|
23
50
|
end
|
24
51
|
|
25
52
|
# Used by render_resource_partial and render_resource_form to guess the view path
|
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.4
|
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-08 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
|