Module: Haml::Filters::Ruby

Includes:
Base
Defined in:
lib/haml/filters.rb

Overview

Parses the filtered text with the normal Ruby interpreter. All output sent to $stdout, such as with puts, is output into the Haml document. Not available if the :suppress_eval option is set to true. The Ruby code is evaluated in the same context as the Haml template.

Instance Method Summary collapse

Methods included from Base

included, #internal_compile, #lazy_require, #render, #render_with_options

Instance Method Details

#compile(precompiler, text) ⇒ Object

See Also:



234
235
236
237
238
239
240
241
242
243
244
245
# File 'lib/haml/filters.rb', line 234

def compile(precompiler, text)
  return if precompiler.options[:suppress_eval]
  precompiler.instance_eval do
    push_silent <<-FIRST.gsub("\n", ';') + text + <<-LAST.gsub("\n", ';')
      _haml_old_stdout = $stdout
      $stdout = StringIO.new(_hamlout.buffer, 'a')
    FIRST
      _haml_old_stdout, $stdout = $stdout, _haml_old_stdout
      _haml_old_stdout.close
    LAST
  end
end