From 3fab196da37ef76cfce040717d4176945212aea8 Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Sun, 9 Dec 2007 22:11:11 +0000 Subject: Refactor Action View template handlers. Closes #10437. git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@8341 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- .../lib/action_view/template_handlers/builder.rb | 15 +++++++++++++++ actionpack/lib/action_view/template_handlers/erb.rb | 21 +++++++++++++++++++++ actionpack/lib/action_view/template_handlers/rjs.rb | 10 ++++++++++ 3 files changed, 46 insertions(+) create mode 100644 actionpack/lib/action_view/template_handlers/builder.rb create mode 100644 actionpack/lib/action_view/template_handlers/erb.rb create mode 100644 actionpack/lib/action_view/template_handlers/rjs.rb (limited to 'actionpack/lib/action_view/template_handlers') 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 -- cgit v1.2.3