Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Changeset 6350

Show
Ignore:
Timestamp:
03/06/07 09:46:04 (2 years ago)
Author:
bitsweat
Message:

Prefer MIME constants to strings. Closes #7707.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/actionpack/CHANGELOG

    r6343 r6350  
    11*SVN* 
     2 
     3* Prefer MIME constants to strings.  #7707 [Dan Kubb] 
    24 
    35* Allow array and hash query parameters. Array route parameters are converted/to/a/path as before.  #6765, #7047, #7462 [bgipsy, Jeremy McAnally, Dan Kubb, brendan] 
  • trunk/actionpack/lib/action_controller/deprecated_request_methods.rb

    r3847 r6350  
    77    # X-Post-Data-Format HTTP header if present. 
    88    def post_format 
    9       case content_type.to_s 
    10       when 'application/xml' 
     9      case content_type 
     10      when Mime::XML 
    1111        :xml 
    12       when 'application/x-yaml' 
     12      when Mime::YAML 
    1313        :yaml 
    1414      else 
  • trunk/actionpack/lib/action_controller/mime_type.rb

    r6152 r6350  
    2525        @order = order 
    2626        @name = name.strip 
    27         q ||= 0.0 if @name == "*/*" # default "*/*" to end of list 
     27        q ||= 0.0 if @name == Mime::ALL # default wilcard match to end of list 
    2828        @q = ((q || 1.0).to_f * 100).to_i 
    2929      end 
     
    7171        # Take care of the broken text/xml entry by renaming or deleting it 
    7272        text_xml = list.index("text/xml") 
    73         app_xml = list.index("application/xml"
     73        app_xml = list.index(Mime::XML.to_s
    7474 
    7575        if text_xml && app_xml 
     
    8585          # delete text_xml from the list 
    8686          list.delete_at(text_xml) 
    87    
     87 
    8888        elsif text_xml 
    89           list[text_xml].name = "application/xml" 
     89          list[text_xml].name = Mime::XML.to_s 
    9090        end 
    9191 
  • trunk/actionpack/lib/action_controller/request.rb

    r6340 r6350  
    6161          # Receive header sans any charset information. 
    6262          content_type = @env['CONTENT_TYPE'].to_s.sub(/\s*\;.*$/, '').strip.downcase 
    63            
     63 
    6464          if x_post_format = @env['HTTP_X_POST_DATA_FORMAT'] 
    6565            case x_post_format.to_s.downcase 
    6666            when 'yaml' 
    67               content_type = 'application/x-yaml' 
     67              content_type = Mime::YAML.to_s 
    6868            when 'xml' 
    69               content_type = 'application/xml' 
     69              content_type = Mime::XML.to_s 
    7070            end 
    7171          end 
    72            
     72 
    7373          Mime::Type.lookup(content_type) 
    7474        end 
  • trunk/actionpack/lib/action_controller/response.rb

    r6169 r6350  
    2121     
    2222    def charset=(encoding) 
    23       self.headers["Content-Type"] = "#{content_type || "text/html"}; charset=#{encoding}" 
     23      self.headers["Content-Type"] = "#{content_type || Mime::HTML}; charset=#{encoding}" 
    2424    end 
    2525     
  • trunk/actionpack/lib/action_controller/test_process.rb

    r6145 r6350  
    326326    # The filename, *not* including the path, of the "uploaded" file 
    327327    attr_reader :original_filename 
    328      
     328 
    329329    # The content type of the "uploaded" file 
    330330    attr_reader :content_type 
    331      
    332     def initialize(path, content_type = 'text/plain'
     331 
     332    def initialize(path, content_type = Mime::TEXT
    333333      raise "#{path} file does not exist" unless File.exist?(path) 
    334334      @content_type = content_type 
     
    337337      FileUtils.copy_file(path, @tempfile.path) 
    338338    end 
    339      
     339 
    340340    def path #:nodoc: 
    341341      @tempfile.path 
    342342    end 
    343      
     343 
    344344    alias local_path path 
    345      
     345 
    346346    def method_missing(method_name, *args, &block) #:nodoc: 
    347347      @tempfile.send(method_name, *args, &block) 
    348348    end 
    349349  end 
    350    
     350 
    351351  module TestProcess 
    352352    def self.included(base) 
  • trunk/actionpack/lib/action_view/base.rb

    r6178 r6350  
    471471          body = case extension.to_sym 
    472472            when :rxml, :builder 
    473               "controller.response.content_type ||= 'application/xml'\n" + 
     473              "controller.response.content_type ||= Mime::XML\n" + 
    474474              "xml = Builder::XmlMarkup.new(:indent => 2)\n" + 
    475475              template 
    476476            when :rjs 
    477               "controller.response.content_type ||= 'text/javascript'\n" + 
     477              "controller.response.content_type ||= Mime::JS\n" + 
    478478              "update_page do |page|\n#{template}\nend" 
    479479          end 
  • trunk/actionpack/lib/action_view/helpers/asset_tag_helper.rb

    r6308 r6350  
    150150            File.open(joined_javascript_path, "w+") do |cache| 
    151151              javascript_paths = expand_javascript_sources(sources).collect do |source| 
    152                 compute_public_path(source, 'javascripts', 'js', false)  
     152                compute_public_path(source, 'javascripts', 'js', false) 
    153153              end 
    154154 
     
    157157          end 
    158158 
    159           content_tag("script", "", {  
    160             "type" => "text/javascript", "src" => javascript_path(joined_javascript_name) 
     159          content_tag("script", "", { 
     160            "type" => Mime::JS, "src" => javascript_path(joined_javascript_name) 
    161161          }.merge(options)) 
    162162        else 
    163163          expand_javascript_sources(sources).collect do |source| 
    164             content_tag("script", "", { "type" => "text/javascript", "src" => javascript_path(source) }.merge(options)) 
     164            content_tag("script", "", { "type" => Mime::JS, "src" => javascript_path(source) }.merge(options)) 
    165165          end.join("\n") 
    166166        end 
     
    253253 
    254254          tag("link", { 
    255             "rel" => "Stylesheet", "type" => "text/css", "media" => "screen", 
     255            "rel" => "Stylesheet", "type" => Mime::CSS, "media" => "screen", 
    256256            "href" => stylesheet_path(joined_stylesheet_name) 
    257257          }.merge(options)) 
     
    260260 
    261261          expand_stylesheet_sources(sources).collect do |source| 
    262             tag("link", {  
    263               "rel" => "Stylesheet", "type" => "text/css", "media" => "screen", "href" => stylesheet_path(source) 
     262            tag("link", { 
     263              "rel" => "Stylesheet", "type" => Mime::CSS, "media" => "screen", "href" => stylesheet_path(source) 
    264264            }.merge(options)) 
    265265          end.join("\n") 
  • trunk/actionpack/lib/action_view/helpers/java_script_macros_helper.rb

    r6057 r6350  
    199199        auto_complete_field("#{object}_#{method}", { :url => { :action => "auto_complete_for_#{object}_#{method}" } }.update(completion_options)) 
    200200      end 
    201        
     201 
    202202      private 
    203203        def auto_complete_stylesheet 
    204           content_tag('style', <<-EOT, :type => 'text/css'
     204          content_tag('style', <<-EOT, :type => Mime::CSS
    205205            div.auto_complete { 
    206206              width: 350px; 
     
    218218              padding:3px; 
    219219            } 
    220             div.auto_complete ul li.selected {  
    221               background-color: #ffb;  
    222             } 
    223             div.auto_complete ul strong.highlight {  
     220            div.auto_complete ul li.selected { 
     221              background-color: #ffb; 
     222            } 
     223            div.auto_complete ul strong.highlight { 
    224224              color: #800;  
    225225              margin:0; 
     
    228228          EOT 
    229229        end 
    230        
     230 
    231231    end 
    232232  end 
  • trunk/actionpack/lib/action_view/helpers/javascript_helper.rb

    r6057 r6350  
    133133      # create remote <script> links. 
    134134      def define_javascript_functions 
    135         javascript = '<script type="text/javascript">' 
     135        javascript = "<script type=\"#{Mime::JS}\">" 
    136136         
    137137        # load prototype.js and its extensions first  
     
    167167      #   javascript_tag "alert('All is good')", :defer => 'true' # => <script defer="true" type="text/javascript">alert('All is good')</script> 
    168168      def javascript_tag(content, html_options = {}) 
    169         content_tag("script", javascript_cdata_section(content), html_options.merge(:type => "text/javascript")) 
     169        content_tag("script", javascript_cdata_section(content), html_options.merge(:type => Mime::JS)) 
    170170      end 
    171171 
  • trunk/actionpack/lib/action_view/helpers/url_helper.rb

    r6070 r6350  
    296296            string << sprintf("%%%x",tmp[i]) 
    297297          end 
    298           "<script type=\"text/javascript\">eval(unescape('#{string}'))</script>" 
     298          "<script type=\"#{Mime::JS}\">eval(unescape('#{string}'))</script>" 
    299299        elsif encode == "hex" 
    300300          email_address_encoded = ''