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.



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

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.



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

def call(exp)
  @text, @captures = ''.dup, []
  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.



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

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.



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

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