aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_view/template
diff options
context:
space:
mode:
authorYehuda Katz + Carl Lerche <ykatz+clerche@engineyard.com>2009-05-21 14:22:07 -0700
committerYehuda Katz + Carl Lerche <ykatz+clerche@engineyard.com>2009-05-21 14:34:56 -0700
commite693f45e155a81b6c337b8766870b56716a05105 (patch)
tree176d94bdc8aa6e072666f1a1ef9383ff809a18df /actionpack/lib/action_view/template
parent386ff66e5ed4fbe1e060610d4226a4eb22dca766 (diff)
downloadrails-e693f45e155a81b6c337b8766870b56716a05105.tar.gz
rails-e693f45e155a81b6c337b8766870b56716a05105.tar.bz2
rails-e693f45e155a81b6c337b8766870b56716a05105.zip
Remove some response content type concepts from ActionView
Diffstat (limited to 'actionpack/lib/action_view/template')
-rw-r--r--actionpack/lib/action_view/template/handler.rb5
-rw-r--r--actionpack/lib/action_view/template/handlers/builder.rb2
-rw-r--r--actionpack/lib/action_view/template/handlers/erb.rb2
-rw-r--r--actionpack/lib/action_view/template/handlers/rjs.rb6
-rw-r--r--actionpack/lib/action_view/template/template.rb15
5 files changed, 23 insertions, 7 deletions
diff --git a/actionpack/lib/action_view/template/handler.rb b/actionpack/lib/action_view/template/handler.rb
index 672da0ed2b..3481a4a4e7 100644
--- a/actionpack/lib/action_view/template/handler.rb
+++ b/actionpack/lib/action_view/template/handler.rb
@@ -1,3 +1,5 @@
+require "active_support/core_ext/class/inheritable_attributes"
+
# Legacy TemplateHandler stub
module ActionView
module TemplateHandlers #:nodoc:
@@ -19,6 +21,9 @@ module ActionView
end
class TemplateHandler
+ extlib_inheritable_accessor :default_format
+ self.default_format = Mime::HTML
+
def self.call(template)
"#{name}.new(self).render(template, local_assigns)"
end
diff --git a/actionpack/lib/action_view/template/handlers/builder.rb b/actionpack/lib/action_view/template/handlers/builder.rb
index 788dc93326..f412228752 100644
--- a/actionpack/lib/action_view/template/handlers/builder.rb
+++ b/actionpack/lib/action_view/template/handlers/builder.rb
@@ -5,6 +5,8 @@ module ActionView
class Builder < TemplateHandler
include Compilable
+ self.default_format = Mime::XML
+
def compile(template)
"_set_controller_content_type(Mime::XML);" +
"xml = ::Builder::XmlMarkup.new(:indent => 2);" +
diff --git a/actionpack/lib/action_view/template/handlers/erb.rb b/actionpack/lib/action_view/template/handlers/erb.rb
index fdcb108ffc..95f11d6490 100644
--- a/actionpack/lib/action_view/template/handlers/erb.rb
+++ b/actionpack/lib/action_view/template/handlers/erb.rb
@@ -13,6 +13,8 @@ module ActionView
cattr_accessor :erb_trim_mode
self.erb_trim_mode = '-'
+ self.default_format = Mime::HTML
+
def compile(template)
src = ::ERB.new("<% __in_erb_template=true %>#{template.source}", nil, erb_trim_mode, '@output_buffer').src
diff --git a/actionpack/lib/action_view/template/handlers/rjs.rb b/actionpack/lib/action_view/template/handlers/rjs.rb
index 802a79b3fc..a36744c2b7 100644
--- a/actionpack/lib/action_view/template/handlers/rjs.rb
+++ b/actionpack/lib/action_view/template/handlers/rjs.rb
@@ -3,11 +3,17 @@ module ActionView
class RJS < TemplateHandler
include Compilable
+ self.default_format = Mime::JS
+
def compile(template)
"@formats = [:html];" +
"controller.response.content_type ||= Mime::JS;" +
"update_page do |page|;#{template.source}\nend"
end
+
+ def default_format
+ Mime::JS
+ end
end
end
end
diff --git a/actionpack/lib/action_view/template/template.rb b/actionpack/lib/action_view/template/template.rb
index dcc5006103..0eedc596d2 100644
--- a/actionpack/lib/action_view/template/template.rb
+++ b/actionpack/lib/action_view/template/template.rb
@@ -7,13 +7,19 @@ require "action_view/template/path"
module ActionView
class Template
extend TemplateHandlers
- attr_reader :source, :identifier, :handler
+ attr_reader :source, :identifier, :handler, :mime_type
def initialize(source, identifier, handler, details)
@source = source
@identifier = identifier
@handler = handler
@details = details
+
+ format = details[:format] || begin
+ # TODO: Clean this up
+ handler.respond_to?(:default_format) ? handler.default_format.to_sym.to_s : "html"
+ end
+ @mime_type = Mime::Type.lookup_by_extension(format.to_s)
end
def render(view, locals, &blk)
@@ -35,12 +41,7 @@ module ActionView
def partial?
@details[:partial]
end
-
- # TODO: Move out of Template
- def mime_type
- Mime::Type.lookup_by_extension(@details[:format].to_s) if @details[:format]
- end
-
+
private
def compile(locals, view)