effective_resources 2.2.11 → 2.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: cd09d6add5f00d00573d998139d60d3fb29d7ef34af02f0e6a0edc3493480d80
4
- data.tar.gz: 24a8993ebecfdc5204f34e370bca4c4a970a65a5ebb9ac7f5d412a00403c786b
3
+ metadata.gz: 0acfffc4958a2a571f0776a9f4e159c88ac9763df2309ed9b18e1a34c9b67fd1
4
+ data.tar.gz: f38964444f684fbf6d4a57291b24f8fcaac909f64ee88ef5120a6a1cc4109d5f
5
5
  SHA512:
6
- metadata.gz: 6fa8aa630baa7d68b8c66e22fa9a3700179ebf593e267640216b4138789518064c1097bd0449231a2abb11153f0de93dbd2e7bf69fc9df770064fe6934ce0896
7
- data.tar.gz: cd135c29a2f6cbea33eafe561e062e9b6659522403c781099aa23e9f17e0b860590eb0fea2f54d995ab42e63cb01abe92ac1304305bcfa7b8c7342e2d00b528b
6
+ metadata.gz: 66181b2e24aefa2ea7117a1feb0fb044c5b70a745276b9f0b39d28a9849cb1a0c772e5370742f3ed82e6f5d8886da9635398236076dd6fd8a3997aee52a49ea1
7
+ data.tar.gz: cd024fafd913cf073b390e07e4f85298315e55efd1bc8a7fc813bb17472acee7a1a7c33942c4951448c98bff7e3e43bdc57be8e6006656025585329b4d40619d
@@ -6,7 +6,7 @@ module Effective
6
6
  Rails.logger.info 'Processed by Effective::CrudController#index'
7
7
 
8
8
  EffectiveResources.authorize!(self, :index, resource_klass)
9
- @page_title ||= resource_plural_name.titleize
9
+ @page_title ||= resource_human_plural_name
10
10
 
11
11
  self.resources ||= resource_scope.all if resource_scope.respond_to?(:all)
12
12
  @datatable = resource_datatable()
@@ -42,12 +42,12 @@ module Effective
42
42
 
43
43
  if (message = flash[:success].to_s).present?
44
44
  flash.delete(:success)
45
- flash.now[:success] = "#{message.chomp('.')}. Adding another #{resource_name.titleize} based on previous."
45
+ flash.now[:success] = "#{message.chomp('.')}. Adding another #{resource_human_name} based on previous."
46
46
  end
47
47
  end
48
48
 
49
49
  EffectiveResources.authorize!(self, :new, resource)
50
- @page_title ||= "New #{resource_name.titleize}"
50
+ @page_title ||= "New #{resource_human_name}"
51
51
 
52
52
  run_callbacks(:resource_render)
53
53
 
@@ -74,7 +74,7 @@ module Effective
74
74
  resource.assign_attributes(send(resource_params_method_name))
75
75
 
76
76
  EffectiveResources.authorize!(self, action, resource)
77
- @page_title ||= "New #{resource_name.titleize}"
77
+ @page_title ||= "New #{resource_human_name}"
78
78
 
79
79
  if save_resource(resource, action)
80
80
  respond_with_success(resource, action)
@@ -211,7 +211,7 @@ module Effective
211
211
  self.resources ||= resource_scope.all
212
212
 
213
213
  EffectiveResources.authorize!(self, action, resource_klass)
214
- @page_title ||= "#{action.to_s.titleize} #{resource_plural_name.titleize}"
214
+ @page_title ||= "#{action.to_s.titleize} #{resource_human_name}"
215
215
 
216
216
  if request.get?
217
217
  @datatable = resource_datatable()
@@ -238,7 +238,7 @@ module Effective
238
238
  end.length
239
239
  end
240
240
 
241
- render json: { status: 200, message: "Successfully #{action_verb(action)} #{successes} / #{resources.length} selected #{resource_plural_name}" }
241
+ render json: { status: 200, message: "Successfully #{action_verb(action)} #{successes} / #{resources.length} selected #{resource_human_plural_name.downcase}" }
242
242
  end
243
243
  end
244
244
 
@@ -21,7 +21,17 @@ module Effective
21
21
  # This is used for the buttons/submits/ons
22
22
  # It doesn't really work with the resource_scope correctly but the routes are important here
23
23
  def effective_resource
24
- @_effective_resource ||= Effective::Resource.new(controller_path)
24
+ @_effective_resource ||= begin
25
+ controller = new()
26
+ klass = (controller.resource_scope_relation.call().try(:klass) rescue false) if controller.respond_to?(:resource_scope_relation)
27
+
28
+ if klass.present?
29
+ namespace = controller_path.split('/')[0...-1].join('/').presence
30
+ Effective::Resource.new(klass, namespace: namespace)
31
+ else
32
+ Effective::Resource.new(controller_path)
33
+ end
34
+ end
25
35
  end
26
36
  end
27
37
 
@@ -84,6 +94,10 @@ module Effective
84
94
  effective_resource.relation
85
95
  end
86
96
 
97
+ def resource_klass # Thing
98
+ effective_resource.klass
99
+ end
100
+
87
101
  def resource_name # 'thing'
88
102
  effective_resource.name
89
103
  end
@@ -92,16 +106,16 @@ module Effective
92
106
  (effective_resource.name + '_id').to_sym
93
107
  end
94
108
 
95
- def resource_klass # Thing
96
- effective_resource.klass
109
+ def resource_plural_name # 'things'
110
+ effective_resource.plural_name
97
111
  end
98
112
 
99
- def resource_human_name
113
+ def resource_human_name # I18n
100
114
  effective_resource.human_name
101
115
  end
102
116
 
103
- def resource_plural_name # 'things'
104
- effective_resource.plural_name
117
+ def resource_human_plural_name # I18n
118
+ effective_resource.human_plural_name
105
119
  end
106
120
 
107
121
  def resource_datatable_attributes
@@ -301,4 +301,23 @@ module EffectiveResourcesHelper
301
301
  path || '/'
302
302
  end
303
303
 
304
+ def effective_translate(resource, attribute = nil)
305
+ return translate(resource) unless resource.respond_to?(:model_name)
306
+
307
+ if attribute.blank?
308
+ resource.model_name.human
309
+ elsif resource.respond_to?(:human_attribute_name)
310
+ resource.human_attribute_name(attribute)
311
+ else
312
+ resource.class.human_attribute_name(attribute)
313
+ end
314
+ end
315
+
316
+ def effective_translates(resource, attribute = nil)
317
+ effective_translate(resource, attribute).pluralize
318
+ end
319
+
320
+ alias_method :et, :effective_translate
321
+ alias_method :ets, :effective_translates
322
+
304
323
  end
@@ -8,6 +8,7 @@ module Effective
8
8
  include Effective::Resources::Instance
9
9
  include Effective::Resources::Forms
10
10
  include Effective::Resources::Generator
11
+ include Effective::Resources::I18n
11
12
  include Effective::Resources::Klass
12
13
  include Effective::Resources::Model
13
14
  include Effective::Resources::Naming
@@ -31,7 +32,7 @@ module Effective
31
32
  end
32
33
 
33
34
  def to_s
34
- name
35
+ human_name
35
36
  end
36
37
 
37
38
  end
@@ -7,11 +7,11 @@ module Effective
7
7
  # This is the attributes as defined by ActiveRecord table
8
8
  # { :name => [:string], ... }
9
9
  def attributes
10
- (klass_attributes.presence || model_attributes.presence)
10
+ klass_attributes.presence || model_attributes.presence
11
11
  end
12
12
 
13
13
  def primary_key_attribute
14
- {klass.primary_key.to_sym => [:integer]}
14
+ { klass.primary_key.to_sym => [:integer] }
15
15
  end
16
16
 
17
17
  # The attributes for each belongs_to
@@ -54,11 +54,11 @@ module Effective
54
54
  end
55
55
 
56
56
  if collection_get_actions.find { |a| a == :index }
57
- buttons["All #{human_plural_name}".titleize] = { action: :index, default: true }
57
+ buttons["All #{human_plural_name}"] = { action: :index, default: true }
58
58
  end
59
59
 
60
60
  if collection_get_actions.find { |a| a == :new }
61
- buttons["New #{human_name}".titleize] = { action: :new, default: true }
61
+ buttons["New #{human_name}"] = { action: :new, default: true }
62
62
  end
63
63
 
64
64
  (collection_get_actions - crud_actions).each do |action|
@@ -122,11 +122,11 @@ module Effective
122
122
  def resource_klass_actions
123
123
  {}.tap do |buttons|
124
124
  if collection_get_actions.find { |a| a == :index }
125
- buttons["All #{human_plural_name}".titleize] = { action: :index, default: true }
125
+ buttons["All #{human_plural_name}"] = { action: :index, default: true }
126
126
  end
127
127
 
128
128
  if collection_get_actions.find { |a| a == :new }
129
- buttons["New #{human_name}".titleize] = { action: :new, default: true }
129
+ buttons["New #{human_name}"] = { action: :new, default: true }
130
130
  end
131
131
 
132
132
  (collection_get_actions - crud_actions).each do |action|
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Effective
4
+ module Resources
5
+ module I18n
6
+
7
+ def human_name
8
+ if klass.respond_to?(:model_name)
9
+ klass.model_name.human
10
+ else
11
+ name.gsub('::', ' ').underscore.gsub('_', ' ')
12
+ end
13
+ end
14
+
15
+ def human_plural_name
16
+ if klass.respond_to?(:model_name)
17
+ klass.model_name.human.pluralize
18
+ else
19
+ name.pluralize.gsub('::', ' ').underscore.gsub('_', ' ')
20
+ end
21
+ end
22
+
23
+ end
24
+ end
25
+ end
@@ -10,7 +10,7 @@ module Effective
10
10
  @model.read(&block)
11
11
 
12
12
  # If effective_developer is in live mode, this will cause it to refresh the class
13
- ActiveSupport.run_load_hooks(:effective_resource, self)
13
+ # ActiveSupport.run_load_hooks(:effective_resource, self)
14
14
  end
15
15
 
16
16
  def model
@@ -63,13 +63,6 @@ module Effective
63
63
  @namespaces || []
64
64
  end
65
65
 
66
- def human_name
67
- name.gsub('::', ' ').underscore.gsub('_', ' ')
68
- end
69
-
70
- def human_plural_name
71
- name.pluralize.gsub('::', ' ').underscore.gsub('_', ' ')
72
- end
73
66
  end
74
67
  end
75
68
  end
@@ -8,18 +8,34 @@ module Effective
8
8
  Tenant.engine_path(tenant).sub("#{Rails.root}/", '') if tenant?
9
9
  end
10
10
 
11
+ # Model
11
12
  def model_file
12
13
  File.join(*[tenant_path, 'app/models', class_path, "#{name}.rb"].compact)
13
14
  end
14
15
 
16
+ # Controller
15
17
  def controller_file
16
18
  File.join(*[tenant_path, 'app/controllers', class_path, namespace, "#{plural_name}_controller.rb"].compact)
17
19
  end
18
20
 
21
+ def admin_effective_controller_file
22
+ File.join(*[tenant_path, 'app/controllers', namespace, "#{plural_name}_controller.rb"].compact)
23
+ end
24
+
25
+ # Datatable
19
26
  def datatable_file
20
27
  File.join(*[tenant_path, 'app/datatables', class_path, namespace, "#{plural_name}_datatable.rb"].compact)
21
28
  end
22
29
 
30
+ def effective_datatable_file
31
+ File.join(*[tenant_path, 'app/datatables', namespace, "effective_#{plural_name}_datatable.rb"].compact)
32
+ end
33
+
34
+ def admin_effective_datatable_file
35
+ File.join(*[tenant_path, 'app/datatables', namespace, "effective_#{plural_name}_datatable.rb"].compact)
36
+ end
37
+
38
+ # Views
23
39
  def view_file(action = :index, partial: false)
24
40
  File.join(*[tenant_path, 'app/views', class_path, namespace, plural_name, "#{'_' if partial}#{action}.html.haml"].compact)
25
41
  end
@@ -28,8 +44,8 @@ module Effective
28
44
  File.join(*[class_path, namespace, plural_name, action].compact)
29
45
  end
30
46
 
31
- def flat_view_file(action = :index, partial: false)
32
- File.join(*[tenant_path, 'app/views', class_path, plural_name, "#{'_' if partial}#{action}.html.haml"].compact)
47
+ def admin_effective_view_file(action = :index, partial: false)
48
+ File.join(*[tenant_path, 'app/views', namespace, plural_name, "#{'_' if partial}#{action}.html.haml"].compact)
33
49
  end
34
50
 
35
51
  def routes_file
@@ -1,3 +1,3 @@
1
1
  module EffectiveResources
2
- VERSION = '2.2.11'.freeze
2
+ VERSION = '2.3.0'.freeze
3
3
  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: 2.2.11
4
+ version: 2.3.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: 2023-01-31 00:00:00.000000000 Z
11
+ date: 2023-02-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -182,6 +182,7 @@ files:
182
182
  - app/models/effective/resources/controller.rb
183
183
  - app/models/effective/resources/forms.rb
184
184
  - app/models/effective/resources/generator.rb
185
+ - app/models/effective/resources/i18n.rb
185
186
  - app/models/effective/resources/init.rb
186
187
  - app/models/effective/resources/instance.rb
187
188
  - app/models/effective/resources/klass.rb