From eb9af20b7cc0e374277cf330bdd404f9daab28ec Mon Sep 17 00:00:00 2001 From: Yehuda Katz Date: Thu, 22 Jan 2009 16:18:10 -0600 Subject: Begin unifying the interface between ActionController and ActionView --- .../lib/action_view/template/handlers/builder.rb | 17 +++++++++++++++++ .../lib/action_view/template/handlers/erb.rb | 22 ++++++++++++++++++++++ .../lib/action_view/template/handlers/rjs.rb | 13 +++++++++++++ 3 files changed, 52 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..788dc93326 --- /dev/null +++ b/actionpack/lib/action_view/template/handlers/builder.rb @@ -0,0 +1,17 @@ +require 'builder' + +module ActionView + module TemplateHandlers + class Builder < TemplateHandler + include Compilable + + def compile(template) + "_set_controller_content_type(Mime::XML);" + + "xml = ::Builder::XmlMarkup.new(:indent => 2);" + + "self.output_buffer = xml.target!;" + + template.source + + ";xml.target!;" + 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..e3120ba267 --- /dev/null +++ b/actionpack/lib/action_view/template/handlers/erb.rb @@ -0,0 +1,22 @@ +module ActionView + module TemplateHandlers + class ERB < TemplateHandler + include Compilable + + ## + # :singleton-method: + # Specify trim mode for the ERB compiler. Defaults to '-'. + # See ERb documentation for suitable values. + cattr_accessor :erb_trim_mode + self.erb_trim_mode = '-' + + def compile(template) + src = ::ERB.new("<% __in_erb_template=true %>#{template.source}", nil, erb_trim_mode, '@output_buffer').src + + # Ruby 1.9 prepends an encoding to the source. However this is + # useless because you can only set an encoding on the first line + RUBY_VERSION >= '1.9' ? src.sub(/\A#coding:.*\n/, '') : 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..802a79b3fc --- /dev/null +++ b/actionpack/lib/action_view/template/handlers/rjs.rb @@ -0,0 +1,13 @@ +module ActionView + module TemplateHandlers + class RJS < TemplateHandler + include Compilable + + def compile(template) + "@formats = [:html];" + + "controller.response.content_type ||= Mime::JS;" + + "update_page do |page|;#{template.source}\nend" + end + end + end +end -- cgit v1.2.3