granite 0.9.8 → 0.9.9

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: a481550ca7df8de031fb4d8c118fac213c93d5e604217a0012c33b8a9d6b38c7
4
- data.tar.gz: 10a9a6b2edce626d410095bede6c239b8745d077389570669cd0594071f127fc
3
+ metadata.gz: c916196599f14f9af76a9a550ffb51e7e4db5fd97deee1cf7cf04135c4bfb217
4
+ data.tar.gz: 6fc2f4a436734b34eb2096fa063a0d82e6fe6bf58afbb04af07b1a86d82d8727
5
5
  SHA512:
6
- metadata.gz: f05bce79f8219eebee3a527aa1cf2ac451c9bac2d5e273123fdf599e050a6ec7000b669c78513bd00124f6b09f8305436dfdbede296b0d906ff3a5e5438151ef
7
- data.tar.gz: daf3016428d057e31f14e140823278eb5b9150a43e805def99669269435ab48b1e97f2479d3dfda3c4f11d883e3fe08e7d1949ebdaefe7f47d56e867a6d3d08d
6
+ metadata.gz: 0bd7b860deb8221df8be1e1227df3c71462862a47ba9243ec7ebc3be1972aeaa95b5c14334ab45aa372f7fe45fc89ed7b3af79a9fb52c3ed5f3e3908981611af
7
+ data.tar.gz: 6f164dc00ce5e56be2bff2bd01f22b49d37996decc05b74816a129f1598451d0dbbb184c1c7d02cac90e52eca80e947e8cba6932dba6842a030ce7801864ba0d
@@ -1,9 +1,9 @@
1
- require 'granite/projector/translations/helper'
2
1
  require 'action_controller'
3
2
 
4
3
  module Granite
5
4
  class Controller < Granite.base_controller_class
6
- include Granite::Projector::Translations::Helper
5
+ include Controller::Translations
6
+ helper Controller::Translations
7
7
 
8
8
  singleton_class.__send__(:attr_accessor, :projector_class)
9
9
  singleton_class.delegate :projector_path, :projector_name, :action_class, to: :projector_class
@@ -0,0 +1,15 @@
1
+ module Granite
2
+ class Controller
3
+ module Translations
4
+ def i18n_scopes
5
+ Granite::Translations.combine_paths(projector.i18n_scopes, [*action_name, nil])
6
+ end
7
+
8
+ def translate(*args, **options)
9
+ super(*Granite::Translations.scope_translation_args(i18n_scopes, *args, **options))
10
+ end
11
+
12
+ alias t translate
13
+ end
14
+ end
15
+ end
@@ -12,6 +12,7 @@ require 'granite/action/preconditions'
12
12
  require 'granite/action/policies'
13
13
  require 'granite/action/projectors'
14
14
  require 'granite/action/subject'
15
+ require 'granite/action/translations'
15
16
 
16
17
  module Granite
17
18
  class Action
@@ -39,6 +40,7 @@ module Granite
39
40
  end
40
41
 
41
42
  include Base
43
+ include Translations
42
44
  include Performing
43
45
  include Subject
44
46
  include Performer
@@ -65,10 +67,6 @@ module Granite
65
67
  end
66
68
  end
67
69
 
68
- def self.i18n_scope
69
- :granite_action
70
- end
71
-
72
70
  # Almost the same as Dirty `#changed?` method, but
73
71
  # doesn't check subject reference key
74
72
  def attributes_changed?(except: [])
@@ -0,0 +1,24 @@
1
+ module Granite
2
+ class Action
3
+ module Translations
4
+ extend ActiveSupport::Concern
5
+
6
+ module ClassMethods
7
+ def i18n_scope
8
+ :granite_action
9
+ end
10
+
11
+ def i18n_scopes
12
+ lookup_ancestors.flat_map do |klass|
13
+ :"#{klass.i18n_scope}.#{klass.model_name.i18n_key}"
14
+ end + [nil]
15
+ end
16
+ end
17
+
18
+ def translate(*args, **options)
19
+ I18n.translate(*Granite::Translations.scope_translation_args(self.class.i18n_scopes, *args, **options))
20
+ end
21
+ alias t translate
22
+ end
23
+ end
24
+ end
data/lib/granite/base.rb CHANGED
@@ -19,7 +19,6 @@ module Granite
19
19
  include ActiveModel::Validations::Callbacks
20
20
 
21
21
  include Granite::Util
22
- include Granite::Translations
23
22
  include Granite::Represents
24
23
  end
25
24
  end
@@ -1,52 +1,17 @@
1
1
  module Granite
2
2
  class Projector
3
3
  module Translations
4
- extend ActiveSupport::Concern
4
+ include ActionView::Helpers::TranslationHelper
5
5
 
6
- class TranslationsWrapper
7
- include ActionView::Helpers::TranslationHelper
6
+ def i18n_scopes
7
+ Granite::Translations.combine_paths(action_class.i18n_scopes, [:"#{projector_name}"])
8
8
  end
9
9
 
10
- def translate(*args)
11
- TranslationsWrapper.new.translate(*self.class.scope_translation_args_by_projector(args))
10
+ def translate(*args, **options)
11
+ super(*Granite::Translations.scope_translation_args(i18n_scopes, *args, **options))
12
12
  end
13
- alias t translate
14
-
15
- module ClassMethods
16
- def scope_translation_args_by_projector(args, action_name: nil)
17
- options = args.extract_options!
18
-
19
- lookups = expand_relative_key(args.first, action_name).map(&:to_sym)
20
- lookups += [options[:default]]
21
- lookups = lookups.flatten.compact
22
-
23
- key = lookups.shift
24
- options[:default] = lookups
25
-
26
- [key, options]
27
- end
28
-
29
- private
30
13
 
31
- def expand_relative_key(key, action_name = nil)
32
- return [key] unless key.is_a?(String) && key.start_with?('.')
33
-
34
- base_keys = extract_base_keys(key, action_name)
35
-
36
- action_class.lookup_ancestors.map do |klass|
37
- base_keys.map do |base_key|
38
- :"#{klass.i18n_scope}.#{klass.model_name.i18n_key}.#{base_key}"
39
- end
40
- end.flatten + base_keys
41
- end
42
-
43
- def extract_base_keys(key, action_name)
44
- undotted_key = key.sub(/^\./, '')
45
- base_keys = [:"#{projector_name}.#{undotted_key}"]
46
- base_keys.unshift :"#{projector_name}.#{action_name}.#{undotted_key}" if action_name
47
- base_keys
48
- end
49
- end
14
+ alias t translate
50
15
  end
51
16
  end
52
17
  end
@@ -5,8 +5,8 @@ module Granite
5
5
  module Routing
6
6
  module Mapper
7
7
  def granite(projector_path, **options)
8
- route = Route.new(projector_path, options.extract!(:path, :as, :projector_prefix))
9
- Declarer.declare(self, route, options)
8
+ route = Route.new(projector_path, **options.extract!(:path, :as, :projector_prefix))
9
+ Declarer.declare(self, route, **options)
10
10
  end
11
11
  end
12
12
  end
@@ -1,19 +1,14 @@
1
1
  module Granite
2
- module Translations
3
- extend ActiveSupport::Concern
4
-
5
- def translate(*args)
6
- I18n.translate(*self.class.scope_translation_args(args))
7
- end
8
- alias t translate
9
-
10
- module ClassMethods
11
- def scope_translation_args(args)
12
- options = args.extract_options!
2
+ class Translations
3
+ class << self
4
+ def combine_paths(paths1, paths2)
5
+ paths1.flat_map do |path1|
6
+ paths2.map { |path2| [*path1, *path2].join('.') }
7
+ end
8
+ end
13
9
 
14
- lookups = expand_relative_key(args.first).map(&:to_sym)
15
- lookups += [options[:default]]
16
- lookups = lookups.flatten.compact
10
+ def scope_translation_args(scopes, key, *, **options)
11
+ lookups = expand_relative_key(scopes, key) + Array(options[:default])
17
12
 
18
13
  key = lookups.shift
19
14
  options[:default] = lookups
@@ -23,14 +18,10 @@ module Granite
23
18
 
24
19
  private
25
20
 
26
- def expand_relative_key(key)
21
+ def expand_relative_key(scopes, key)
27
22
  return [key] unless key.is_a?(String) && key.start_with?('.')
28
23
 
29
- base_key = key.sub(/^\./, '')
30
-
31
- lookup_ancestors.map do |klass|
32
- :"#{klass.i18n_scope}.#{klass.model_name.i18n_key}.#{base_key}"
33
- end.flatten + [base_key]
24
+ combine_paths(scopes, [key.sub(/^\./, '')]).map(&:to_sym)
34
25
  end
35
26
  end
36
27
  end
@@ -1,3 +1,3 @@
1
1
  module Granite
2
- VERSION = '0.9.8'.freeze
2
+ VERSION = '0.9.9'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: granite
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.8
4
+ version: 0.9.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Arkadiy Zabazhanov & friends
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-05-28 00:00:00.000000000 Z
11
+ date: 2021-06-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: actionpack
@@ -302,6 +302,7 @@ extra_rdoc_files: []
302
302
  files:
303
303
  - LICENSE
304
304
  - app/controllers/granite/controller.rb
305
+ - app/controllers/granite/controller/translations.rb
305
306
  - config/rubocop-default.yml
306
307
  - lib/generators/USAGE
307
308
  - lib/generators/granite/install_controller_generator.rb
@@ -330,6 +331,7 @@ files:
330
331
  - lib/granite/action/transaction.rb
331
332
  - lib/granite/action/transaction_manager.rb
332
333
  - lib/granite/action/transaction_manager/transactions_stack.rb
334
+ - lib/granite/action/translations.rb
333
335
  - lib/granite/action/types.rb
334
336
  - lib/granite/action/types/collection.rb
335
337
  - lib/granite/base.rb
@@ -344,8 +346,6 @@ files:
344
346
  - lib/granite/projector/error.rb
345
347
  - lib/granite/projector/helpers.rb
346
348
  - lib/granite/projector/translations.rb
347
- - lib/granite/projector/translations/helper.rb
348
- - lib/granite/projector/translations/view_helper.rb
349
349
  - lib/granite/rails.rb
350
350
  - lib/granite/represents.rb
351
351
  - lib/granite/represents/attribute.rb
@@ -389,7 +389,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
389
389
  - !ruby/object:Gem::Version
390
390
  version: '0'
391
391
  requirements: []
392
- rubygems_version: 3.0.6
392
+ rubygems_version: 3.0.9
393
393
  signing_key:
394
394
  specification_version: 4
395
395
  summary: Another business actions architecture for Rails apps
@@ -1,22 +0,0 @@
1
- require 'granite/projector/translations/view_helper'
2
-
3
- module Granite
4
- class Projector
5
- module Translations
6
- module Helper
7
- extend ActiveSupport::Concern
8
-
9
- included do
10
- delegate :scope_translation_args_by_projector, to: :projector_class
11
- helper_method :scope_translation_args_by_projector
12
- helper ViewHelper
13
- end
14
-
15
- def translate(*args)
16
- super(*scope_translation_args_by_projector(args, action_name: action_name))
17
- end
18
- alias t translate
19
- end
20
- end
21
- end
22
- end
@@ -1,12 +0,0 @@
1
- module Granite
2
- class Projector
3
- module Translations
4
- module ViewHelper
5
- def translate(*args)
6
- super(*scope_translation_args_by_projector(args, action_name: action_name))
7
- end
8
- alias t translate
9
- end
10
- end
11
- end
12
- end