simple_helpers 2.0.0.beta → 2.0.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/Gemfile +1 -1
- data/README.md +1 -1
- data/lib/simple_helpers/config.rb +2 -0
- data/lib/simple_helpers/railtie.rb +0 -1
- data/lib/simple_helpers/support.rb +61 -35
- data/lib/simple_helpers/version.rb +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ad5106d5e8ba4e9bb0e42eef4e4a105734d9933f
|
4
|
+
data.tar.gz: 095713110ea60c96ec9d0fa8eea86b73ce323021
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4fa4003a2dd23424a253b7c160e85142dd2bb6bff361bd6fc065ee40e6509e07e89205f652e7a5613df3be6fd6c3008b7da9572b37abb3d5f83a1ed6a0450ea8
|
7
|
+
data.tar.gz: aa0a33dece45792fa98a62137c181848aee560be67b5a7e35dbe9d712b1cbc27afe8b0100c9ed5a73904a58a3ebc7045a3486ad3025093c640cfa3759c348088
|
data/Gemfile
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
source
|
1
|
+
source 'https://rubygems.org'
|
2
2
|
gemspec
|
data/README.md
CHANGED
@@ -24,27 +24,10 @@ module SimpleHelpers
|
|
24
24
|
}
|
25
25
|
end
|
26
26
|
|
27
|
-
def self.
|
28
|
-
context
|
29
|
-
parts = key.delete("{}").split(".")
|
30
|
-
|
27
|
+
def self.parser(controller, context)
|
28
|
+
entries(context).each do |key|
|
31
29
|
begin
|
32
|
-
|
33
|
-
if first_argument.start_with? "@"
|
34
|
-
instance_variable = controller.instance_variable_get(first_argument)
|
35
|
-
|
36
|
-
value = if parts.empty?
|
37
|
-
instance_variable
|
38
|
-
else
|
39
|
-
thing = parts.shift.to_sym
|
40
|
-
instance_variable[thing] if instance_variable.respond_to?(thing)
|
41
|
-
end
|
42
|
-
else
|
43
|
-
value = controller.send first_argument
|
44
|
-
end
|
45
|
-
value = "" unless value
|
46
|
-
rescue
|
47
|
-
value = ""
|
30
|
+
value = simple_helper_value(controller, key)
|
48
31
|
ensure
|
49
32
|
context.sub!(key, value)
|
50
33
|
end
|
@@ -61,7 +44,9 @@ module SimpleHelpers
|
|
61
44
|
end
|
62
45
|
end
|
63
46
|
|
64
|
-
def self.
|
47
|
+
def self.get_i18n_content(controller, key, options)
|
48
|
+
scopes = SimpleHelpers::Support.scopes(controller, key)
|
49
|
+
|
65
50
|
result = SimpleHelpers::Support.translate(scopes[:first], options)
|
66
51
|
if result.empty?
|
67
52
|
result = SimpleHelpers::Support.translate(scopes[:second], options)
|
@@ -84,23 +69,64 @@ module SimpleHelpers
|
|
84
69
|
end
|
85
70
|
|
86
71
|
define_method("#{name}_get") do |*args|
|
87
|
-
|
88
|
-
|
89
|
-
result = SimpleHelpers::Support.get_content(scopes, options_hash)
|
90
|
-
helper_options = SimpleHelpers::Config.helpers[name.to_sym]
|
91
|
-
|
92
|
-
prefix = helper_options.fetch(:prefix, "")
|
93
|
-
content = SimpleHelpers::Support.template(controller, result)
|
94
|
-
separator = if prefix.empty? || content.empty?
|
95
|
-
""
|
96
|
-
else
|
97
|
-
helper_options.fetch(:separator, " - ")
|
98
|
-
end
|
99
|
-
|
100
|
-
"#{prefix}#{separator}#{content}"
|
72
|
+
"%{prefix}%{prefix_separator}%{content}%{suffix_separator}%{suffix}" %
|
73
|
+
SimpleHelpers::Support.simple_helper_parts(controller, name)
|
101
74
|
end
|
102
75
|
end
|
103
76
|
end
|
104
77
|
|
78
|
+
private
|
79
|
+
|
80
|
+
def self.entries(context)
|
81
|
+
context.scan(/{{.*?}}/i)
|
82
|
+
end
|
83
|
+
|
84
|
+
def self.simple_helper_value(controller, key)
|
85
|
+
tag = key.delete("{}")
|
86
|
+
if tag.start_with? "@"
|
87
|
+
get_instance_variable(controller, tag)
|
88
|
+
else
|
89
|
+
get_from_controller(controller, tag)
|
90
|
+
end || ""
|
91
|
+
end
|
92
|
+
|
93
|
+
def self.get_instance_variable(controller, key)
|
94
|
+
parts = key.split(".")
|
95
|
+
first_argument = parts.shift
|
96
|
+
instance_variable = controller.instance_variable_get(first_argument)
|
97
|
+
|
98
|
+
if parts.empty?
|
99
|
+
instance_variable
|
100
|
+
else
|
101
|
+
thing = parts.shift.to_sym
|
102
|
+
instance_variable[thing] if instance_variable.respond_to?(thing)
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
def self.get_from_controller(controller, key)
|
107
|
+
controller.send key
|
108
|
+
end
|
109
|
+
|
110
|
+
def self.simple_helper_parts(controller, name)
|
111
|
+
name_options = controller.instance_variable_get("@#{name}_options") || {}
|
112
|
+
text_raw = SimpleHelpers::Support.get_i18n_content(controller, name, name_options)
|
113
|
+
content = SimpleHelpers::Support.parser(controller, text_raw)
|
114
|
+
|
115
|
+
helper_options = SimpleHelpers::Config.helpers[name.to_sym].merge(name_options)
|
116
|
+
prefix = helper_options.fetch(:prefix, "")
|
117
|
+
suffix = helper_options.fetch(:suffix, "")
|
118
|
+
separator = helper_options.fetch(:separator, SimpleHelpers::Config::DEFAULT_SEPARATOR)
|
119
|
+
|
120
|
+
{
|
121
|
+
prefix: prefix,
|
122
|
+
suffix: suffix,
|
123
|
+
separator: separator,
|
124
|
+
content: content,
|
125
|
+
prefix_separator: prefix.empty? || content.empty? ? "" : separator,
|
126
|
+
suffix_separator: suffix.empty? || content.empty? ? "" : separator
|
127
|
+
}
|
128
|
+
end
|
129
|
+
|
105
130
|
end
|
131
|
+
|
106
132
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: simple_helpers
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.0
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Vitor Oliveira
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-05-
|
11
|
+
date: 2013-05-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -114,9 +114,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
114
114
|
version: '0'
|
115
115
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
116
116
|
requirements:
|
117
|
-
- - '
|
117
|
+
- - '>='
|
118
118
|
- !ruby/object:Gem::Version
|
119
|
-
version:
|
119
|
+
version: '0'
|
120
120
|
requirements: []
|
121
121
|
rubyforge_project:
|
122
122
|
rubygems_version: 2.0.3
|