Class: Slim::Translator::StaticTranslator Private

Inherits:
Filter
  • Object
show all
Defined in:
lib/slim/translator.rb

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Instance Method Summary collapse

Methods inherited from Filter

#on_slim_control, #on_slim_embedded, #on_slim_text

Constructor Details

#initialize(opts = {}) ⇒ StaticTranslator

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of StaticTranslator



59
60
61
62
# File 'lib/slim/translator.rb', line 59

def initialize(opts = {})
  super
  @translate = eval("proc {|string| #{options[:tr_fn]}(string) }")
end

Instance Method Details

#call(exp) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



64
65
66
67
68
69
70
71
72
73
74
# File 'lib/slim/translator.rb', line 64

def call(exp)
  @text, @captures = '', []
  result = compile(exp)

  text = @translate.call(@text)
  while text =~ /%(\d+)/
    result << [:static, $`] << @captures[$1.to_i - 1]
    text = $'
  end
  result << [:static, text]
end

#on_slim_output(escape, code, content) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



81
82
83
84
85
# File 'lib/slim/translator.rb', line 81

def on_slim_output(escape, code, content)
  @captures << [:slim, :output, escape, code, content]
  @text << "%#{@captures.size}"
  [:multi]
end

#on_static(text) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



76
77
78
79
# File 'lib/slim/translator.rb', line 76

def on_static(text)
  @text << text
  [:multi]
end