Class Index [+]

Quicksearch

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

Protected Instance Methods

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

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

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

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.