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