metazilla 1.1.0 → 1.2.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
  SHA1:
3
- metadata.gz: b73475d91bed1c7be91b5b4f04098e4fe29fba77
4
- data.tar.gz: f98750b74d3174646714fee94e41699e4ec916c4
3
+ metadata.gz: 2b437234b4e8f5b090d18e3be3071d10160e4e3d
4
+ data.tar.gz: fa633ca88fdb42169dd22ad3a1b2aa3bf7d5bd5c
5
5
  SHA512:
6
- metadata.gz: ce6e2680705523bad3777ef5e76c72f67c11e4c235ed54169a917722035278d2c651d05e42338554468f1f095cfb21089443ec82a35da0155235e7b548a7a2ab
7
- data.tar.gz: 15179e16b9d06ea2dafa6b2a1794e21dbabdc2f99fefee92d0952dba4181bd2cf1c8f50d93ac67d2baff1d44b15f521f4d6ab7874b2433df1ba77669ab036620
6
+ metadata.gz: 28307cce118017453d89d9623c1a550aafdb1578583a5dbfe7130bce34ae3d8e75a48f73ccd3a705eb97c24ff89980ec197ea030f82f7a778b3f77a71779fa83
7
+ data.tar.gz: a09ad92e0c29397da5d8a196bef3ef7b4259b5c134116945a110cacebe9b5824ffcd881beba7713564b95cadb16fd3a122089ef6809a290ba694ffe45a2b33d1
@@ -1,3 +1,3 @@
1
1
  module Metazilla
2
- VERSION = "1.1.0"
2
+ VERSION = "1.2.0"
3
3
  end
@@ -1,12 +1,10 @@
1
- require "metazilla/translator"
2
-
3
1
  module Metazilla
4
2
  module ViewHelper
5
3
  def title(value = nil)
6
4
  if value.present?
7
5
  _meta_store[:page_title] = value
8
6
  else
9
- _meta_store[:page_title] || _translator.lookup_for_current_path(:title)
7
+ _meta_store[:page_title] || _meta_lookup("title")
10
8
  end
11
9
  end
12
10
 
@@ -14,7 +12,7 @@ module Metazilla
14
12
  if value.present?
15
13
  _meta_store[:app_title] = value
16
14
  else
17
- _meta_store[:app_title] || _translator.lookup(:app)
15
+ _meta_store[:app_title] || _meta_lookup("app")
18
16
  end
19
17
  end
20
18
 
@@ -30,7 +28,7 @@ module Metazilla
30
28
  if content.present?
31
29
  _meta_store[name] = content
32
30
  else
33
- _meta_store[name] || _translator.lookup_for_current_path(:"meta.#{name}")
31
+ _meta_store[name] || _meta_lookup("meta_#{name}")
34
32
  end
35
33
  end
36
34
 
@@ -44,8 +42,12 @@ module Metazilla
44
42
  @_meta_store ||= {}
45
43
  end
46
44
 
47
- def _translator
48
- @_translator ||= Translator.new(controller_path, action_name, controller.view_assigns.symbolize_keys)
45
+ def _meta_lookup(key)
46
+ options = controller.view_assigns.symbolize_keys
47
+ options[:cascade] = true
48
+ mapped_action = (Metazilla.configuration.mapping[action_name.to_sym] || action_name)
49
+
50
+ t [controller_path.split("/"), mapped_action, key].flatten.join("."), options
49
51
  end
50
52
  end
51
53
  end
data/lib/metazilla.rb CHANGED
@@ -25,4 +25,5 @@ module Metazilla
25
25
  end
26
26
  end
27
27
 
28
+ I18n.backend.class.send :include, I18n::Backend::Cascade
28
29
  ActionView::Base.send :include, Metazilla::ViewHelper
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: metazilla
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eugene Likholetov
@@ -68,7 +68,6 @@ files:
68
68
  - bin/console
69
69
  - bin/setup
70
70
  - lib/metazilla.rb
71
- - lib/metazilla/translator.rb
72
71
  - lib/metazilla/version.rb
73
72
  - lib/metazilla/view_helper.rb
74
73
  - metazilla.gemspec
@@ -1,51 +0,0 @@
1
- module Metazilla
2
- class Translator
3
- attr_reader :namespace, :controller, :action, :context
4
-
5
- def initialize(controller_path, action, context = {})
6
- @namespace, @controller = parse_namespace_and_controller(controller_path)
7
- @action = action.to_s.freeze
8
- @context = context
9
- end
10
-
11
- def lookup(key)
12
- lookup_recursively key, namespace
13
- end
14
-
15
- def lookup_for_current_path(key)
16
- lookup_recursively(key, [namespace, controller, mapped_action].flatten)
17
- end
18
-
19
- private
20
-
21
- def parse_namespace_and_controller(controller_path)
22
- parts = controller_path.to_s.split("/")
23
- if parts.size > 1
24
- [parts[0...-1], parts[-1]]
25
- else
26
- [[], parts[0]]
27
- end
28
- end
29
-
30
- def lookup_recursively(key, namespace)
31
- namespace.size.downto(0).each do |depth|
32
- result = lookup_in_namespace(key, namespace.first(depth))
33
- return result if result
34
- end
35
- nil
36
- end
37
-
38
- def mapped_action
39
- (Metazilla.configuration.mapping[action.to_sym] || action).to_s.freeze
40
- end
41
-
42
- def lookup_in_namespace(key, namespace = [])
43
- t_key = [namespace, key].flatten.compact.join('.')
44
- i18n_set?(t_key) ? I18n.t(t_key, context) : nil
45
- end
46
-
47
- def i18n_set?(key)
48
- I18n.t(key, raise: true) rescue false
49
- end
50
- end
51
- end