metazilla 1.1.0 → 1.2.0
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/lib/metazilla/version.rb +1 -1
- data/lib/metazilla/view_helper.rb +9 -7
- data/lib/metazilla.rb +1 -0
- metadata +1 -2
- data/lib/metazilla/translator.rb +0 -51
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2b437234b4e8f5b090d18e3be3071d10160e4e3d
|
4
|
+
data.tar.gz: fa633ca88fdb42169dd22ad3a1b2aa3bf7d5bd5c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 28307cce118017453d89d9623c1a550aafdb1578583a5dbfe7130bce34ae3d8e75a48f73ccd3a705eb97c24ff89980ec197ea030f82f7a778b3f77a71779fa83
|
7
|
+
data.tar.gz: a09ad92e0c29397da5d8a196bef3ef7b4259b5c134116945a110cacebe9b5824ffcd881beba7713564b95cadb16fd3a122089ef6809a290ba694ffe45a2b33d1
|
data/lib/metazilla/version.rb
CHANGED
@@ -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] ||
|
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] ||
|
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] ||
|
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
|
48
|
-
|
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
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.
|
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
|
data/lib/metazilla/translator.rb
DELETED
@@ -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
|