I18n::Backend::InterpolationCompiler::Compiler

Constants

TOKENIZER
INTERPOLATION_SYNTAX_PATTERN

Public Instance Methods

compile_if_an_interpolation(string) click to toggle source
    # 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
interpolated_str?(str) click to toggle source
    # File lib/i18n/backend/interpolation_compiler.rb, line 39
39:         def interpolated_str?(str)
40:           str.kind_of?(::String) && str =~ INTERPOLATION_SYNTAX_PATTERN
41:         end

Protected Instance Methods

compile_interpolation_token(key) click to toggle source
    # File lib/i18n/backend/interpolation_compiler.rb, line 60
60:         def compile_interpolation_token(key)
61:           "\#{#{interpolate_or_raise_missing(key)}}"
62:         end
compiled_interpolation_body(str) click to toggle source
    # 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
direct_key(key) click to toggle source
    # 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
escape_key_sym(key) click to toggle source
    # 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
escape_plain_str(str) click to toggle source
    # File lib/i18n/backend/interpolation_compiler.rb, line 89
89:         def escape_plain_str(str)
90:           str.gsub(/"|\\|#/) {|x| "\\#{x}"}
91:         end
handle_interpolation_token(interpolation, matchdata) click to toggle source
    # 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
interpolate_key(key) click to toggle source
    # 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
interpolate_or_raise_missing(key) click to toggle source
    # 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
missing_key(key) click to toggle source
    # File lib/i18n/backend/interpolation_compiler.rb, line 81
81:         def missing_key(key)
82:           "raise(MissingInterpolationArgument.new(#{key}, self))"
83:         end
nil_key(key) click to toggle source
    # File lib/i18n/backend/interpolation_compiler.rb, line 77
77:         def nil_key(key)
78:           "(v.has_key?(#{key}) && '')"
79:         end
reserved_key(key) click to toggle source
    # File lib/i18n/backend/interpolation_compiler.rb, line 85
85:         def reserved_key(key)
86:           "raise(ReservedInterpolationKey.new(#{key}, self))"
87:         end
tokenize(str) click to toggle source

tokenize(“foo %{bar} baz %%{buz}”) # => [“foo “, “%{bar}”, “ baz “, “%%{buz}”]

    # File lib/i18n/backend/interpolation_compiler.rb, line 45
45:         def tokenize(str)
46:           str.split(TOKENIZER)
47:         end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.