diff options
author | Jeremy Kemper <jeremy@bitsweat.net> | 2007-12-09 22:11:11 +0000 |
---|---|---|
committer | Jeremy Kemper <jeremy@bitsweat.net> | 2007-12-09 22:11:11 +0000 |
commit | 3fab196da37ef76cfce040717d4176945212aea8 (patch) | |
tree | f024c48e7c85a2304d050d652e0ea52966c757d4 /actionpack/lib/action_view/template_handlers | |
parent | ef57b93a82acab5a79620e405af5534cdf0e89c3 (diff) | |
download | rails-3fab196da37ef76cfce040717d4176945212aea8.tar.gz rails-3fab196da37ef76cfce040717d4176945212aea8.tar.bz2 rails-3fab196da37ef76cfce040717d4176945212aea8.zip |
Refactor Action View template handlers. Closes #10437.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@8341 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'actionpack/lib/action_view/template_handlers')
-rw-r--r-- | actionpack/lib/action_view/template_handlers/builder.rb | 15 | ||||
-rw-r--r-- | actionpack/lib/action_view/template_handlers/erb.rb | 21 | ||||
-rw-r--r-- | actionpack/lib/action_view/template_handlers/rjs.rb | 10 |
3 files changed, 46 insertions, 0 deletions
diff --git a/actionpack/lib/action_view/template_handlers/builder.rb b/actionpack/lib/action_view/template_handlers/builder.rb new file mode 100644 index 0000000000..a9fc069f88 --- /dev/null +++ b/actionpack/lib/action_view/template_handlers/builder.rb @@ -0,0 +1,15 @@ +require 'builder' + +module ActionView + module TemplateHandlers + class Builder < TemplateHandler + def compile(template) + content_type_handler = (@view.send!(:controller).respond_to?(:response) ? "controller.response" : "controller") + "#{content_type_handler}.content_type ||= Mime::XML\n" + + "xml = Builder::XmlMarkup.new(:indent => 2)\n" + + template + + "\nxml.target!\n" + end + end + end +end diff --git a/actionpack/lib/action_view/template_handlers/erb.rb b/actionpack/lib/action_view/template_handlers/erb.rb new file mode 100644 index 0000000000..f1b800cb53 --- /dev/null +++ b/actionpack/lib/action_view/template_handlers/erb.rb @@ -0,0 +1,21 @@ +require 'erb' + +class ERB + module Util + HTML_ESCAPE = { '&' => '&', '"' => '"', '>' => '>', '<' => '<' } + + def html_escape(s) + s.to_s.gsub(/[&\"><]/) { |special| HTML_ESCAPE[special] } + end + end +end + +module ActionView + module TemplateHandlers + class ERB < TemplateHandler + def compile(template) + ::ERB.new(template, nil, @view.erb_trim_mode).src + end + end + end +end diff --git a/actionpack/lib/action_view/template_handlers/rjs.rb b/actionpack/lib/action_view/template_handlers/rjs.rb new file mode 100644 index 0000000000..300f9890e9 --- /dev/null +++ b/actionpack/lib/action_view/template_handlers/rjs.rb @@ -0,0 +1,10 @@ +module ActionView + module TemplateHandlers + class RJS < TemplateHandler + def compile(template) + "controller.response.content_type ||= Mime::JS\n" + + "update_page do |page|\n#{template}\nend" + end + end + end +end |