2007-12-21 08:48:59 +01:00
|
|
|
module ActionView
|
|
|
|
module TemplateHandlers
|
|
|
|
class ERB < TemplateHandler
|
2008-05-18 06:22:34 +02:00
|
|
|
include Compilable
|
|
|
|
|
2009-02-04 21:26:08 +01:00
|
|
|
##
|
|
|
|
# :singleton-method:
|
2008-10-27 07:47:01 +01:00
|
|
|
# Specify trim mode for the ERB compiler. Defaults to '-'.
|
|
|
|
# See ERb documentation for suitable values.
|
|
|
|
cattr_accessor :erb_trim_mode
|
|
|
|
self.erb_trim_mode = '-'
|
|
|
|
|
2007-12-21 08:48:59 +01:00
|
|
|
def compile(template)
|
2010-05-25 19:45:45 +02:00
|
|
|
magic = $1 if template.source =~ /\A(<%#.*coding[:=]\s*(\S+)\s*-?%>)/
|
|
|
|
erb = "#{magic}<% __in_erb_template=true %>#{template.source}"
|
2008-05-18 06:22:34 +02:00
|
|
|
|
2010-05-25 19:45:45 +02:00
|
|
|
if erb.respond_to?(:force_encoding)
|
2011-06-15 07:43:38 +02:00
|
|
|
erb.force_encoding(template.source.encoding)
|
2010-05-25 19:45:45 +02:00
|
|
|
# erb.force_encoding(template.source.encoding)
|
|
|
|
erb.force_encoding('UTF-8')
|
|
|
|
end
|
|
|
|
|
|
|
|
::ERB.new(erb, nil, erb_trim_mode, '@output_buffer').src
|
2007-12-21 08:48:59 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|