Changeset 3852
- Timestamp:
- 03/13/06 01:33:57 (3 years ago)
- Files:
-
- trunk/actionpack/CHANGELOG (modified) (1 diff)
- trunk/actionpack/lib/action_controller/base.rb (modified) (1 diff)
- trunk/actionpack/lib/action_controller/layout.rb (modified) (1 diff)
- trunk/actionpack/lib/action_controller/mime_type.rb (modified) (3 diffs)
- trunk/actionpack/lib/action_view/base.rb (modified) (1 diff)
- trunk/actionpack/lib/action_view/helpers/prototype_helper.rb (modified) (2 diffs)
- trunk/actionpack/test/controller/action_pack_assertions_test.rb (modified) (1 diff)
- trunk/actionpack/test/template/prototype_helper_test.rb (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/actionpack/CHANGELOG
r3842 r3852 1 1 *SVN* 2 3 * Added :content_type option to render, so you can change the content type on the fly [DHH]. Example: render :action => "atom.rxml", :content_type => "application/atom+xml" 4 5 * 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 [DHH] 2 6 3 7 * Added option to render action/template/file of a specific extension (and here by template type). This means you can have multiple templates with the same name but a different extension [DHH]. Example: trunk/actionpack/lib/action_controller/base.rb
r3847 r3852 635 635 end 636 636 637 if content_type = options[:content_type] 638 headers["Content-Type"] = content_type 639 end 640 637 641 if text = options[:text] 638 642 render_text(text, options[:status]) trunk/actionpack/lib/action_controller/layout.rb
r3551 r3852 246 246 def candidate_for_layout?(options) 247 247 (options.has_key?(:layout) && options[:layout] != false) || 248 options.values_at(:text, : file, :inline, :partial, :nothing).compact.empty? &&248 options.values_at(:text, :xml, :file, :inline, :partial, :nothing).compact.empty? && 249 249 !template_exempt_from_layout?(default_template_name(options[:action] || options[:template])) 250 250 end trunk/actionpack/lib/action_controller/mime_type.rb
r3850 r3852 1 1 module Mime 2 2 class Type 3 def self.lookup(string) 4 LOOKUP[string] 5 end 3 class << self 4 def lookup(string) 5 LOOKUP[string] 6 end 6 7 7 def self.parse(accept_header) 8 accept_header.split(",").collect! do |mime_type| 9 Mime::Type.lookup(mime_type.split(";").first.strip) 8 def parse(accept_header) 9 mime_types = accept_header.split(",").collect! do |mime_type| 10 mime_type.split(";").first.strip 11 end 12 13 reorder_xml_types!(mime_types) 14 mime_types.collect! { |mime_type| Mime::Type.lookup(mime_type) } 10 15 end 16 17 private 18 def reorder_xml_types!(mime_types) 19 mime_types.delete("text/xml") if mime_types.include?("application/xml") 20 21 if index_for_generic_xml = mime_types.index("application/xml") 22 specific_xml_types = mime_types[index_for_generic_xml..-1].grep(/application\/[a-z]*\+xml/) 23 24 for specific_xml_type in specific_xml_types.reverse 25 mime_types.insert(index_for_generic_xml, mime_types.delete(specific_xml_type)) 26 end 27 end 28 end 11 29 end 12 30 … … 18 36 def to_s 19 37 @string 38 end 39 40 def to_str 41 to_s 20 42 end 21 43 … … 40 62 HTML = Type.new "text/html", :html, %w( application/xhtml+xml ) 41 63 JS = Type.new "text/javascript", :js, %w( application/javascript application/x-javascript ) 42 XML = Type.new "application/xml", :xml, %w( application/x-xml )64 XML = Type.new "application/xml", :xml, %w( text/xml application/x-xml ) 43 65 RSS = Type.new "application/rss+xml", :rss 44 66 ATOM = Type.new "application/atom+xml", :atom trunk/actionpack/lib/action_view/base.rb
r3841 r3852 407 407 when :rxml 408 408 "xml = Builder::XmlMarkup.new(:indent => 2)\n" + 409 "@controller.headers['Content-Type'] ||= ' text/xml'\n" +409 "@controller.headers['Content-Type'] ||= 'application/xml'\n" + 410 410 template 411 411 when :rjs trunk/actionpack/lib/action_view/helpers/prototype_helper.rb
r3814 r3852 619 619 620 620 private 621 def page 622 self 623 end 624 625 def record(line) 626 returning line = "#{line.to_s.chomp.gsub /\;$/, ''};" do 627 self << line 621 def page 622 self 628 623 end 629 end 630 631 def render(*options_for_render) 632 Hash === options_for_render.first ? 633 @context.render(*options_for_render) : 634 options_for_render.first.to_s 635 end 636 637 def javascript_object_for(object) 638 object.respond_to?(:to_json) ? object.to_json : object.inspect 639 end 640 641 def arguments_for_call(arguments) 642 arguments.map { |argument| javascript_object_for(argument) }.join ', ' 643 end 624 625 def record(line) 626 returning line = "#{line.to_s.chomp.gsub /\;$/, ''};" do 627 self << line 628 end 629 end 630 631 def render(*options_for_render) 632 Hash === options_for_render.first ? 633 @context.render(*options_for_render) : 634 options_for_render.first.to_s 635 end 636 637 def javascript_object_for(object) 638 object.respond_to?(:to_json) ? object.to_json : object.inspect 639 end 640 641 def arguments_for_call(arguments) 642 arguments.map { |argument| javascript_object_for(argument) }.join ', ' 643 end 644 645 def method_missing(method, *arguments) 646 JavaScriptProxy.new(self, method.to_s.camelize) 647 end 644 648 end 645 649 end … … 719 723 assign($1, arguments.first) 720 724 else 721 call("#{method.to_s.first}#{method.to_s.c lassify[1..-1]}", *arguments)725 call("#{method.to_s.first}#{method.to_s.camelize[1..-1]}", *arguments) 722 726 end 723 727 end trunk/actionpack/test/controller/action_pack_assertions_test.rb
r3563 r3852 480 480 @request, @response = ActionController::TestRequest.new, ActionController::TestResponse.new 481 481 end 482 482 483 def test_rendering_xml_sets_content_type 483 484 process :hello_xml_world 484 assert_equal('text/xml', @controller.headers['Content-Type']) 485 end 485 assert_equal('application/xml', @controller.headers['Content-Type']) 486 end 487 486 488 def test_rendering_xml_respects_content_type 487 489 @response.headers['Content-Type'] = 'application/pdf' trunk/actionpack/test/template/prototype_helper_test.rb
r3814 r3852 381 381 EOS 382 382 end 383 384 def test_class_proxy 385 @generator.form.focus('my_field') 386 assert_equal "Form.focus(\"my_field\");", @generator.to_s 387 end 383 388 end