mirror of
https://github.com/haml/haml.git
synced 2022-11-09 12:33:31 -05:00
Evaluate the :ruby filter in the document context.
This commit is contained in:
parent
bbdb5882fd
commit
491306ce52
3 changed files with 14 additions and 9 deletions
|
@ -555,6 +555,7 @@ $LOAD_PATH << dir unless $LOAD_PATH.include?(dir)
|
|||
# All output sent to <tt>$stdout</tt>, like with +puts+,
|
||||
# is output into the Haml document.
|
||||
# Not available if the <tt>suppress_eval</tt> option is set to true.
|
||||
# The Ruby code is evaluated in the same context as the Haml template.
|
||||
#
|
||||
# [preserve] Inserts the filtered text into the template with whitespace preserved.
|
||||
# <tt>preserve</tt>d blocks of text aren't indented,
|
||||
|
|
|
@ -146,13 +146,16 @@ module Haml
|
|||
include Base
|
||||
lazy_require 'stringio'
|
||||
|
||||
def render(text)
|
||||
old_stdout = $stdout
|
||||
$stdout = StringIO.new
|
||||
Object.new.instance_eval(text)
|
||||
old_stdout, $stdout = $stdout, old_stdout
|
||||
old_stdout.pos = 0
|
||||
old_stdout.read
|
||||
def compile(precompiler, text)
|
||||
precompiler.instance_eval do
|
||||
push_silent <<-END.gsub("\n", ';')
|
||||
_haml_old_stdout = $stdout
|
||||
$stdout = StringIO.new(_hamlout.buffer, 'a')
|
||||
#{text}
|
||||
_haml_old_stdout, $stdout = $stdout, _haml_old_stdout
|
||||
_haml_old_stdout.close
|
||||
END
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -64,6 +64,7 @@
|
|||
|
||||
= "Text!"
|
||||
|
||||
- var = "Hello"
|
||||
:ruby
|
||||
puts "Hello, World!"
|
||||
puts "How are you doing today?"
|
||||
printf "%s, World!\n", var
|
||||
print "How are you doing today?\n"
|
||||
|
|
Loading…
Add table
Reference in a new issue