Skip to content

Commit

Permalink
Add a SafeTemplate module that makes TiltTemplates render safe strings
Browse files Browse the repository at this point in the history
  • Loading branch information
skade committed Feb 1, 2013
1 parent 900eeb8 commit c571e75
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
10 changes: 10 additions & 0 deletions padrino-core/lib/padrino-core/application/rendering.rb
Expand Up @@ -7,6 +7,16 @@ module Padrino
# locale enabled rendering, among other features.
#
module Rendering
##
# A SafeTemplate assumes that its output is safe.
#
# @api private
module SafeTemplate
def render(*)
super.html_safe
end
end

##
# Exception responsible for when an expected template did not exist.
#
Expand Down
Expand Up @@ -125,6 +125,10 @@ def self.rails_xss_safe?
if defined? Padrino::Rendering
Padrino::Rendering.engine_configurations[:haml] =
{:escape_html => true}

class Tilt::HamlTemplate
include Padrino::Rendering::SafeTemplate
end
end
rescue LoadError
end
2 changes: 1 addition & 1 deletion padrino-core/test/test_rendering.rb
Expand Up @@ -505,7 +505,7 @@ def is; "IS."; end

get 'with_layout'
assert ok?
assert_equal '<p><div>foo</div></p>', body.strip
assert_equal '<p><div>foo</div></p>', body.gsub(/\s+/, "")
end

should 'render slim to a SafeBuffer' do
Expand Down

0 comments on commit c571e75

Please sign in to comment.