# File lib/i18n/backend/interpolation_compiler.rb, line 27
27: def compile_if_an_interpolation(string)
28: if interpolated_str?(string)
29: string.instance_eval def i18n_interpolate(v = {}) "#{compiled_interpolation_body(string)}" end, __FILE__, __LINE__
30: end
31:
32: string
33: end
# File lib/i18n/backend/interpolation_compiler.rb, line 60
60: def compile_interpolation_token(key)
61: "\#{#{interpolate_or_raise_missing(key)}}"
62: end
# File lib/i18n/backend/interpolation_compiler.rb, line 49
49: def compiled_interpolation_body(str)
50: tokenize(str).map do |token|
51: (matchdata = token.match(INTERPOLATION_SYNTAX_PATTERN)) ? handle_interpolation_token(token, matchdata) : escape_plain_str(token)
52: end.join
53: end
# File lib/i18n/backend/interpolation_compiler.rb, line 73
73: def direct_key(key)
74: "((t = v[#{key}]) && t.respond_to?(:call) ? t.call : t)"
75: end
# File lib/i18n/backend/interpolation_compiler.rb, line 93
93: def escape_key_sym(key)
94: # rely on Ruby to do all the hard work :)
95: key.to_sym.inspect
96: end
# File lib/i18n/backend/interpolation_compiler.rb, line 89
89: def escape_plain_str(str)
90: str.gsub(/"|\\|#/) {|x| "\\#{x}"}
91: end
# File lib/i18n/backend/interpolation_compiler.rb, line 55
55: def handle_interpolation_token(interpolation, matchdata)
56: escaped, pattern, key = matchdata.values_at(1, 2, 3)
57: escaped ? pattern : compile_interpolation_token(key.to_sym)
58: end
# File lib/i18n/backend/interpolation_compiler.rb, line 69
69: def interpolate_key(key)
70: [direct_key(key), nil_key(key), missing_key(key)].join('||')
71: end
# File lib/i18n/backend/interpolation_compiler.rb, line 64
64: def interpolate_or_raise_missing(key)
65: escaped_key = escape_key_sym(key)
66: Base::RESERVED_KEYS.include?(key) ? reserved_key(escaped_key) : interpolate_key(escaped_key)
67: end
# File lib/i18n/backend/interpolation_compiler.rb, line 81
81: def missing_key(key)
82: "raise(MissingInterpolationArgument.new(#{key}, self))"
83: end
# File lib/i18n/backend/interpolation_compiler.rb, line 77
77: def nil_key(key)
78: "(v.has_key?(#{key}) && '')"
79: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.