Permalink
Browse files

Added support for Erubis <%== tag

<%== x %> is syntactic sugar for <%= raw(x) %>

Signed-off-by: Michael Koziarski <michael@koziarski.com>
[#5918 status:committed]
  • Loading branch information...
1 parent 697f485 commit f04ec6a227b702342d2fb841f94915499bf6101a @Fjan Fjan committed with NZKoz Nov 6, 2010
@@ -40,7 +40,11 @@ def add_expr_literal(src, code)
end
def add_expr_escaped(src, code)
- src << '@output_buffer.append= ' << escaped_expr(code) << ';'
+ if code =~ BLOCK_EXPR
+ src << "@output_buffer.safe_append= " << code
+ else
+ src << "@output_buffer.safe_concat((" << code << ").to_s);"
+ end
end
def add_postamble(src)
@@ -9,6 +9,7 @@ class WithoutLayoutController < ActionController::Base
"locals.html.erb" => "The secret is <%= secret %>",
"xml_template.xml.builder" => "xml.html do\n xml.p 'Hello'\nend",
"with_raw.html.erb" => "Hello <%=raw '<strong>this is raw</strong>' %>",
+ "with_implicit_raw.html.erb"=> "Hello <%== '<strong>this is also raw</strong>' %>",
"test/with_json.html.erb" => "<%= render :template => 'test/with_json.json' %>",
"test/with_json.json.erb" => "<%= render :template => 'test/final' %>",
"test/final.json.erb" => "{ final: json }",
@@ -51,6 +52,10 @@ def with_raw
render :template => "with_raw"
end
+ def with_implicit_raw
+ render :template => "with_implicit_raw"
+ end
+
def with_error
render :template => "test/with_error"
end
@@ -99,6 +104,11 @@ class TestWithoutLayout < Rack::TestCase
assert_body "Hello <strong>this is raw</strong>"
assert_status 200
+
+ get :with_implicit_raw
+
+ assert_body "Hello <strong>this is also raw</strong>"
+ assert_status 200
end
test "rendering a template with renders another template with other format that renders other template in the same format" do
@@ -73,6 +73,7 @@ def html_safe?
module ActiveSupport #:nodoc:
class SafeBuffer < String
alias safe_concat concat
+ alias safe_append= concat
def concat(value)
if value.html_safe?

0 comments on commit f04ec6a

Please sign in to comment.