aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_view/template/handlers/erb.rb
diff options
context:
space:
mode:
Diffstat (limited to 'actionpack/lib/action_view/template/handlers/erb.rb')
-rw-r--r--actionpack/lib/action_view/template/handlers/erb.rb11
1 files changed, 8 insertions, 3 deletions
diff --git a/actionpack/lib/action_view/template/handlers/erb.rb b/actionpack/lib/action_view/template/handlers/erb.rb
index a780ab8d85..88aeb4b053 100644
--- a/actionpack/lib/action_view/template/handlers/erb.rb
+++ b/actionpack/lib/action_view/template/handlers/erb.rb
@@ -37,11 +37,16 @@ module ActionView
self.erb_trim_mode = '-'
self.default_format = Mime::HTML
+
+ cattr_accessor :erubis_implementation
+ self.erubis_implementation = Erubis
def compile(template)
- magic = $1 if template.source =~ /\A(<%#.*coding[:=]\s*(\S+)\s*-?%>)/
- erb = "#{magic}<% __in_erb_template=true %>#{template.source}"
- Erubis.new(erb, :trim=>(self.class.erb_trim_mode == "-")).src
+ source = template.source.gsub(/\A(<%(#.*coding[:=]\s*(\S+)\s*)-?%>)\s*\n?/, '')
+ erb = "<% __in_erb_template=true %>#{source}"
+ result = self.class.erubis_implementation.new(erb, :trim=>(self.class.erb_trim_mode == "-")).src
+ result = "#{$2}\n#{result}" if $2
+ result
end
end
end