i18n_screwdriver 2.2.0 → 3.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/i18n_screwdriver/translation.rb +17 -6
- data/lib/i18n_screwdriver/version.rb +1 -1
- metadata +2 -2
@@ -3,19 +3,30 @@ module I18nScrewdriver
|
|
3
3
|
attr_accessor :text, :options
|
4
4
|
|
5
5
|
def self.new(text, options = {}, &block)
|
6
|
-
super(I18n.translate(I18nScrewdriver.for_key(text), options))
|
7
|
-
|
8
|
-
|
9
|
-
|
6
|
+
translation = super(options[:raw] ? text : I18n.translate(I18nScrewdriver.for_key(text), options))
|
7
|
+
translation.text = text
|
8
|
+
translation.options = options
|
9
|
+
|
10
|
+
if block
|
11
|
+
urls = Array(block.call)
|
12
|
+
urls_to_interpolate_count = translation.scan(/<<.+?>>/).count
|
13
|
+
raise ArgumentError, "too few urls specified" if urls.count < urls_to_interpolate_count
|
14
|
+
if urls.count > urls_to_interpolate_count
|
15
|
+
raise ArgumentError, "expected extra url to be a hash intended for variable interpolation" unless urls.last.is_a?(Hash)
|
16
|
+
translation = new(translation % urls.last, :raw => true)
|
17
|
+
end
|
18
|
+
translation.linkify(block.binding, urls)
|
10
19
|
end
|
20
|
+
|
21
|
+
translation
|
11
22
|
end
|
12
23
|
|
13
|
-
def linkify(binding,
|
24
|
+
def linkify(binding, urls)
|
14
25
|
context = binding ? eval('self', binding) : self
|
15
26
|
keep_html_safety do
|
16
27
|
gsub!(/<<.+?>>/).each_with_index do |text, index|
|
17
28
|
context.instance_eval do
|
18
|
-
link_to
|
29
|
+
link_to(text[2..-3], *urls[index])
|
19
30
|
end
|
20
31
|
end
|
21
32
|
end
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: i18n_screwdriver
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version:
|
5
|
+
version: 3.0.0
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Tobias Miesel
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2013-
|
13
|
+
date: 2013-02-06 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
type: :development
|