From a3388f9873b3920ee5481a3c0cc182fbe7b4dd9d Mon Sep 17 00:00:00 2001 From: Nathan Weizenbaum Date: Sat, 23 Feb 2008 01:37:35 -0800 Subject: [PATCH] Evaluating the ERB filter in the template context as well. --- lib/haml.rb | 3 +-- lib/haml/filters.rb | 5 +++-- test/haml/results/filters.xhtml | 26 ++++++++++++++++---------- test/haml/templates/filters.haml | 13 +++++++++---- 4 files changed, 29 insertions(+), 18 deletions(-) diff --git a/lib/haml.rb b/lib/haml.rb index ec43e202..64b9b208 100644 --- a/lib/haml.rb +++ b/lib/haml.rb @@ -564,8 +564,7 @@ $LOAD_PATH << dir unless $LOAD_PATH.include?(dir) # # [erb] Parses the filtered text with ERB, like an RHTML template. # Not available if the suppress_eval option is set to true. -# At the moment, this doesn't support access to variables -# defined by Ruby on Rails or Haml code. +# Embedded Ruby code is evaluated in the same context as the Haml template. # # [sass] Parses the filtered text with Sass to produce CSS output. # diff --git a/lib/haml/filters.rb b/lib/haml/filters.rb index 8205186a..dd149dbd 100644 --- a/lib/haml/filters.rb +++ b/lib/haml/filters.rb @@ -191,8 +191,9 @@ module Haml include Base lazy_require 'erb' - def render(text) - ::ERB.new(text).result(binding) + def compile(precompiler, text) + src = ::ERB.new(text).src.sub(/^_erbout = '';/, "").gsub("\n", ';') + precompiler.send(:push_silent, src) end end diff --git a/test/haml/results/filters.xhtml b/test/haml/results/filters.xhtml index 43c0b713..f022b68e 100644 --- a/test/haml/results/filters.xhtml +++ b/test/haml/results/filters.xhtml @@ -36,26 +36,32 @@ This pre is pretty deeply nested. Does interpolation work This one is, too. Nested, that is.

+ +
178