lib/clutterbuck/erb.rb in clutterbuck-erb-0.1.1 vs lib/clutterbuck/erb.rb in clutterbuck-erb-0.2.0

- old
+ new

@@ -1,6 +1,7 @@ require 'erb' +require 'rack' #:nodoc: module Clutterbuck; end # Render an ERB template and return it as a Rack-compatible response. @@ -49,12 +50,13 @@ mod.extend(ClassMethods) end #:nodoc: # - # A special (very, *very* special) class which only defines methods for the - # vars that are passed into it. + # A special (very, *very* special) class which only defines methods for + # the vars that are passed into it, as well as fundamental HTML escaping + # methods. # class EvalBinding < BasicObject def initialize(vars) unless vars.is_a?(::Hash) ::Kernel.raise ::ArgumentError, @@ -74,9 +76,15 @@ "Invalid key in vars list: #{k.inspect}" end instance_eval "def #{k}; @vars[#{k.inspect}]; end" end + end + + # HTML-escape the provided string. + # + def h(s) + ::Rack::Utils.escape_html(s) end end # Render an ERB template as a Rack response. #