aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib
diff options
context:
space:
mode:
authorDavid Heinemeier Hansson <david@loudthinking.com>2006-03-13 01:33:57 +0000
committerDavid Heinemeier Hansson <david@loudthinking.com>2006-03-13 01:33:57 +0000
commit06c2b43f36c84ddd3e17ada057b3dc621d4140f0 (patch)
treeba628a35089b46623f7d8ca3cfec68aa24cece4a /actionpack/lib
parentc5d5c4f708ab72b8ba9825017b854b02e0c8481c (diff)
downloadrails-06c2b43f36c84ddd3e17ada057b3dc621d4140f0.tar.gz
rails-06c2b43f36c84ddd3e17ada057b3dc621d4140f0.tar.bz2
rails-06c2b43f36c84ddd3e17ada057b3dc621d4140f0.zip
Rendering xml shouldnt happen inside any layout. Added class proxying to RJS, so you can call page.field.clear("my_field") to generate Field.clear("my_field");. Added :content_type option to render, so you can change the content type on the fly. Do type/subtype reordering of Accept header preferences for xml types (aka make Firefox work with respond_to). CHANGED DEFAULT: The default content type for .rxml is now application/xml instead of type/xml, see http://www.xml.com/pub/a/2004/07/21/dive.html for reason
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@3852 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'actionpack/lib')
-rwxr-xr-xactionpack/lib/action_controller/base.rb4
-rw-r--r--actionpack/lib/action_controller/layout.rb2
-rw-r--r--actionpack/lib/action_controller/mime_type.rb36
-rw-r--r--actionpack/lib/action_view/base.rb2
-rw-r--r--actionpack/lib/action_view/helpers/prototype_helper.rb42
5 files changed, 58 insertions, 28 deletions
diff --git a/actionpack/lib/action_controller/base.rb b/actionpack/lib/action_controller/base.rb
index 4663828c96..b0b6069420 100755
--- a/actionpack/lib/action_controller/base.rb
+++ b/actionpack/lib/action_controller/base.rb
@@ -634,6 +634,10 @@ module ActionController #:nodoc:
end
end
+ if content_type = options[:content_type]
+ headers["Content-Type"] = content_type
+ end
+
if text = options[:text]
render_text(text, options[:status])
diff --git a/actionpack/lib/action_controller/layout.rb b/actionpack/lib/action_controller/layout.rb
index 0934b8bfdc..66438d277e 100644
--- a/actionpack/lib/action_controller/layout.rb
+++ b/actionpack/lib/action_controller/layout.rb
@@ -245,7 +245,7 @@ module ActionController #:nodoc:
def candidate_for_layout?(options)
(options.has_key?(:layout) && options[:layout] != false) ||
- options.values_at(:text, :file, :inline, :partial, :nothing).compact.empty? &&
+ options.values_at(:text, :xml, :file, :inline, :partial, :nothing).compact.empty? &&
!template_exempt_from_layout?(default_template_name(options[:action] || options[:template]))
end
diff --git a/actionpack/lib/action_controller/mime_type.rb b/actionpack/lib/action_controller/mime_type.rb
index 54030f75cc..ba46f98ace 100644
--- a/actionpack/lib/action_controller/mime_type.rb
+++ b/actionpack/lib/action_controller/mime_type.rb
@@ -1,13 +1,31 @@
module Mime
class Type
- def self.lookup(string)
- LOOKUP[string]
- end
+ class << self
+ def lookup(string)
+ LOOKUP[string]
+ end
- def self.parse(accept_header)
- accept_header.split(",").collect! do |mime_type|
- Mime::Type.lookup(mime_type.split(";").first.strip)
+ def parse(accept_header)
+ mime_types = accept_header.split(",").collect! do |mime_type|
+ mime_type.split(";").first.strip
+ end
+
+ reorder_xml_types!(mime_types)
+ mime_types.collect! { |mime_type| Mime::Type.lookup(mime_type) }
end
+
+ private
+ def reorder_xml_types!(mime_types)
+ mime_types.delete("text/xml") if mime_types.include?("application/xml")
+
+ if index_for_generic_xml = mime_types.index("application/xml")
+ specific_xml_types = mime_types[index_for_generic_xml..-1].grep(/application\/[a-z]*\+xml/)
+
+ for specific_xml_type in specific_xml_types.reverse
+ mime_types.insert(index_for_generic_xml, mime_types.delete(specific_xml_type))
+ end
+ end
+ end
end
def initialize(string, symbol = nil, synonyms = [])
@@ -19,6 +37,10 @@ module Mime
@string
end
+ def to_str
+ to_s
+ end
+
def to_sym
@symbol || to_sym
end
@@ -39,7 +61,7 @@ module Mime
ALL = Type.new "*/*", :all
HTML = Type.new "text/html", :html, %w( application/xhtml+xml )
JS = Type.new "text/javascript", :js, %w( application/javascript application/x-javascript )
- XML = Type.new "application/xml", :xml, %w( application/x-xml )
+ XML = Type.new "application/xml", :xml, %w( text/xml application/x-xml )
RSS = Type.new "application/rss+xml", :rss
ATOM = Type.new "application/atom+xml", :atom
YAML = Type.new "application/x-yaml", :yaml
diff --git a/actionpack/lib/action_view/base.rb b/actionpack/lib/action_view/base.rb
index d2f4764575..95afff0e84 100644
--- a/actionpack/lib/action_view/base.rb
+++ b/actionpack/lib/action_view/base.rb
@@ -406,7 +406,7 @@ module ActionView #:nodoc:
body = case extension.to_sym
when :rxml
"xml = Builder::XmlMarkup.new(:indent => 2)\n" +
- "@controller.headers['Content-Type'] ||= 'text/xml'\n" +
+ "@controller.headers['Content-Type'] ||= 'application/xml'\n" +
template
when :rjs
"@controller.headers['Content-Type'] ||= 'text/javascript'\n" +
diff --git a/actionpack/lib/action_view/helpers/prototype_helper.rb b/actionpack/lib/action_view/helpers/prototype_helper.rb
index 113ddc8739..1f6aa274db 100644
--- a/actionpack/lib/action_view/helpers/prototype_helper.rb
+++ b/actionpack/lib/action_view/helpers/prototype_helper.rb
@@ -618,29 +618,33 @@ module ActionView
end
private
- def page
- self
- end
+ def page
+ self
+ end
- def record(line)
- returning line = "#{line.to_s.chomp.gsub /\;$/, ''};" do
- self << line
+ def record(line)
+ returning line = "#{line.to_s.chomp.gsub /\;$/, ''};" do
+ self << line
+ end
end
- end
- def render(*options_for_render)
- Hash === options_for_render.first ?
- @context.render(*options_for_render) :
- options_for_render.first.to_s
- end
+ def render(*options_for_render)
+ Hash === options_for_render.first ?
+ @context.render(*options_for_render) :
+ options_for_render.first.to_s
+ end
- def javascript_object_for(object)
- object.respond_to?(:to_json) ? object.to_json : object.inspect
- end
+ def javascript_object_for(object)
+ object.respond_to?(:to_json) ? object.to_json : object.inspect
+ end
- def arguments_for_call(arguments)
- arguments.map { |argument| javascript_object_for(argument) }.join ', '
- end
+ def arguments_for_call(arguments)
+ arguments.map { |argument| javascript_object_for(argument) }.join ', '
+ end
+
+ def method_missing(method, *arguments)
+ JavaScriptProxy.new(self, method.to_s.camelize)
+ end
end
end
@@ -718,7 +722,7 @@ module ActionView
if method.to_s =~ /(.*)=$/
assign($1, arguments.first)
else
- call("#{method.to_s.first}#{method.to_s.classify[1..-1]}", *arguments)
+ call("#{method.to_s.first}#{method.to_s.camelize[1..-1]}", *arguments)
end
end