Module: I18n::Backend::Fast::InterpolationCompiler

Extended by:
InterpolationCompiler
Included in:
InterpolationCompiler
Defined in:
lib/i18n/backend/fast/interpolation_compiler.rb

Constant Summary collapse

TOKENIZER =
/(\\\{\{[^\}]+\}\}|\{\{[^\}]+\}\})/
INTERPOLATION_SYNTAX_PATTERN =
/(\\)?(\{\{([^\}]+)\}\})/

Instance Method Summary collapse

Instance Method Details

#compile_if_an_interpolation(string) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
# File 'lib/i18n/backend/fast/interpolation_compiler.rb', line 10

def compile_if_an_interpolation(string)
  if interpolated_str?(string)
    string.instance_eval <<-RUBY_EVAL, __FILE__, __LINE__
      def i18n_interpolate(v = {})
        "#{compiled_interpolation_body(string)}"
      end
    RUBY_EVAL
  end

  string
end

#interpolated_str?(str) ⇒ Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/i18n/backend/fast/interpolation_compiler.rb', line 22

def interpolated_str?(str)
  str.kind_of?(String) && str =~ INTERPOLATION_SYNTAX_PATTERN
end