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.
@@ -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)).tap do |translation|
7
- translation.text = text
8
- translation.options = options
9
- translation.linkify(block.binding, *block.call) if block
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, *urls)
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 text[2..-3], *urls[index]
29
+ link_to(text[2..-3], *urls[index])
19
30
  end
20
31
  end
21
32
  end
@@ -1,4 +1,4 @@
1
1
  module I18nScrewdriver
2
- VERSION = "2.2.0"
2
+ VERSION = "3.0.0"
3
3
  end
4
4
 
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: i18n_screwdriver
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 2.2.0
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-01-23 00:00:00.000000000 Z
13
+ date: 2013-02-06 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  type: :development