Class: I18nScrewdriver::Translation
- Inherits:
-
String
- Object
- String
- I18nScrewdriver::Translation
- Defined in:
- lib/i18n_screwdriver/translation.rb
Instance Attribute Summary collapse
-
#options ⇒ Object
Returns the value of attribute options.
-
#text ⇒ Object
Returns the value of attribute text.
Class Method Summary collapse
Instance Method Summary collapse
Instance Attribute Details
#options ⇒ Object
Returns the value of attribute options.
3 4 5 |
# File 'lib/i18n_screwdriver/translation.rb', line 3 def @options end |
#text ⇒ Object
Returns the value of attribute text.
3 4 5 |
# File 'lib/i18n_screwdriver/translation.rb', line 3 def text @text end |
Class Method Details
.new(text, options = {}, &block) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/i18n_screwdriver/translation.rb', line 5 def self.new(text, = {}, &block) translation = super([:raw] ? text : I18n.translate(I18nScrewdriver.for_key(text), )) translation.text = text translation. = if block urls = Array(block.call) urls_to_interpolate_count = translation.scan(/<<.+?>>/).count raise ArgumentError, "too few urls specified" if urls.count < urls_to_interpolate_count if urls.count > urls_to_interpolate_count raise ArgumentError, "too many urls specified (#{urls.count} <> #{urls_to_interpolate_count})" unless urls.last.is_a?(Hash) translation = new(translation % urls.last, :raw => true) end translation.linkify(block.binding, urls) end translation end |
Instance Method Details
#linkify(binding, urls) ⇒ Object
24 25 26 27 28 29 30 31 32 33 |
# File 'lib/i18n_screwdriver/translation.rb', line 24 def linkify(binding, urls) context = binding ? eval('self', binding) : self keep_html_safety do gsub!(/<<.+?>>/).each_with_index do |text, index| context.instance_eval do link_to(text[2..-3], *urls[index]) end end end end |