simple_helpers 2.0.0 → 2.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +1 -0
- data/README.md +1 -1
- data/lib/simple_helpers/config.rb +1 -1
- data/lib/simple_helpers/support.rb +33 -33
- data/lib/simple_helpers/version.rb +1 -1
- data/templates/initializer.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 75600df7a0ae09aa8c1b237125e570b7f2ed9d85
|
4
|
+
data.tar.gz: 09011776669374e42cb13f8be960c804b1e83901
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 836d425d56ecb1d515164c81c4715bf29521070350c3902a7d1dd3a53256328ff1ae50179e2fe019d7f21e5cd47041c8f5cee881597d401ec311049ff5739806
|
7
|
+
data.tar.gz: 4400234e48e51e905ff601a66566bebeee24fcef2cba71101d80245d2d2a7dcb2734b3bfc4c58188761be4fcb29857eacbfa6d47c568d2008d19a21d4797c2ab
|
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -5,6 +5,29 @@ module SimpleHelpers
|
|
5
5
|
array.collect{|item| item.to_s}
|
6
6
|
end
|
7
7
|
|
8
|
+
def self.create_method(controller, name)
|
9
|
+
controller.class_eval do
|
10
|
+
define_method(name) do |*args|
|
11
|
+
if args.empty?
|
12
|
+
send "#{name}_get"
|
13
|
+
else
|
14
|
+
send "#{name}_set", args.first
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
define_method("#{name}_set") do |*args|
|
19
|
+
instance_variable_set "@#{name}", args.first
|
20
|
+
end
|
21
|
+
|
22
|
+
define_method("#{name}_get") do |*args|
|
23
|
+
"%{prefix}%{prefix_separator}%{content}%{suffix_separator}%{suffix}" %
|
24
|
+
SimpleHelpers::Support.simple_helper_parts(controller, name)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
8
31
|
def self.scopes(controller, method_name)
|
9
32
|
controller_name = controller.class.name.underscore
|
10
33
|
controller_name.gsub!(/\//, "_")
|
@@ -24,12 +47,12 @@ module SimpleHelpers
|
|
24
47
|
}
|
25
48
|
end
|
26
49
|
|
27
|
-
def self.
|
28
|
-
|
50
|
+
def self.replace_tags(controller, context)
|
51
|
+
tags(context).each do |tag|
|
29
52
|
begin
|
30
|
-
value = simple_helper_value(controller,
|
53
|
+
value = simple_helper_value(controller, tag)
|
31
54
|
ensure
|
32
|
-
context.sub!(
|
55
|
+
context.sub!(tag, value)
|
33
56
|
end
|
34
57
|
end
|
35
58
|
context
|
@@ -44,7 +67,7 @@ module SimpleHelpers
|
|
44
67
|
end
|
45
68
|
end
|
46
69
|
|
47
|
-
def self.
|
70
|
+
def self.get_text_from_locale(controller, key, options)
|
48
71
|
scopes = SimpleHelpers::Support.scopes(controller, key)
|
49
72
|
|
50
73
|
result = SimpleHelpers::Support.translate(scopes[:first], options)
|
@@ -54,43 +77,20 @@ module SimpleHelpers
|
|
54
77
|
result
|
55
78
|
end
|
56
79
|
|
57
|
-
def self.
|
58
|
-
controller.class_eval do
|
59
|
-
define_method(name) do |*args|
|
60
|
-
if args.empty?
|
61
|
-
send "#{name}_get"
|
62
|
-
else
|
63
|
-
send "#{name}_set", args.first
|
64
|
-
end
|
65
|
-
end
|
66
|
-
|
67
|
-
define_method("#{name}_set") do |*args|
|
68
|
-
instance_variable_set "@#{name}", args.first
|
69
|
-
end
|
70
|
-
|
71
|
-
define_method("#{name}_get") do |*args|
|
72
|
-
"%{prefix}%{prefix_separator}%{content}%{suffix_separator}%{suffix}" %
|
73
|
-
SimpleHelpers::Support.simple_helper_parts(controller, name)
|
74
|
-
end
|
75
|
-
end
|
76
|
-
end
|
77
|
-
|
78
|
-
private
|
79
|
-
|
80
|
-
def self.entries(context)
|
80
|
+
def self.tags(context)
|
81
81
|
context.scan(/{{.*?}}/i)
|
82
82
|
end
|
83
83
|
|
84
84
|
def self.simple_helper_value(controller, key)
|
85
85
|
tag = key.delete("{}")
|
86
86
|
if tag.start_with? "@"
|
87
|
-
|
87
|
+
get_from_instance_variable(controller, tag)
|
88
88
|
else
|
89
89
|
get_from_controller(controller, tag)
|
90
90
|
end || ""
|
91
91
|
end
|
92
92
|
|
93
|
-
def self.
|
93
|
+
def self.get_from_instance_variable(controller, key)
|
94
94
|
parts = key.split(".")
|
95
95
|
first_argument = parts.shift
|
96
96
|
instance_variable = controller.instance_variable_get(first_argument)
|
@@ -109,8 +109,8 @@ module SimpleHelpers
|
|
109
109
|
|
110
110
|
def self.simple_helper_parts(controller, name)
|
111
111
|
name_options = controller.instance_variable_get("@#{name}_options") || {}
|
112
|
-
text_raw = SimpleHelpers::Support.
|
113
|
-
content = SimpleHelpers::Support.
|
112
|
+
text_raw = SimpleHelpers::Support.get_text_from_locale(controller, name, name_options)
|
113
|
+
content = SimpleHelpers::Support.replace_tags(controller, text_raw)
|
114
114
|
|
115
115
|
helper_options = SimpleHelpers::Config.helpers[name.to_sym].merge(name_options)
|
116
116
|
prefix = helper_options.fetch(:prefix, "")
|
data/templates/initializer.rb
CHANGED