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

Ticket #7707: mime_constants.patch

File mime_constants.patch, 10.4 kB (added by dkubb, 2 years ago)
  • lib/action_controller/request.rb

    old new  
    6464      @content_type ||= 
    6565        begin 
    6666          content_type = @env['CONTENT_TYPE'].to_s.downcase 
    67            
     67 
    6868          if x_post_format = @env['HTTP_X_POST_DATA_FORMAT'] 
    6969            case x_post_format.to_s.downcase 
    7070            when 'yaml' 
    71               content_type = 'application/x-yaml' 
     71              content_type = Mime::YAML.to_s 
    7272            when 'xml' 
    73               content_type = 'application/xml' 
     73              content_type = Mime::XML.to_s 
    7474            end 
    7575          end 
    76            
     76 
    7777          Mime::Type.lookup(content_type) 
    7878        end 
    7979    end 
  • lib/action_controller/test_process.rb

    old new  
    325325  class TestUploadedFile 
    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 
    335335      @original_filename = path.sub(/^.*#{File::SEPARATOR}([^#{File::SEPARATOR}]+)$/) { $1 } 
    336336      @tempfile = Tempfile.new(@original_filename) 
    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) 
    353353      # execute the request simulating a specific http method and set/volley the response 
  • lib/action_controller/mime_type.rb

    old new  
    2424      def initialize(order, name, q=nil) 
    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 
    3030 
     
    7070 
    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 
    7676          # set the q value to the max of the two 
     
    8484 
    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 
    9292        # Look for more specific xml-based types and sort them ahead of app/xml 
  • lib/action_controller/deprecated_request_methods.rb

    old new  
    66    # For backward compatibility, the post format is extracted from the 
    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 
    1515        :url_encoded 
  • lib/action_controller/response.rb

    old new  
    2020    end 
    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     
    2626    def charset 
  • lib/action_view/helpers/url_helper.rb

    old new  
    295295          for i in 0...tmp.length 
    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 = '' 
    301301          email_address_obfuscated.each_byte do |c| 
  • lib/action_view/helpers/javascript_helper.rb

    old new  
    132132      # public/javascripts/ directory, and use +javascript_include_tag+ to  
    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  
    138138        prototype_libs = Dir.glob(File.join(JAVASCRIPT_PATH, 'prototype*')).sort.reverse 
     
    166166      # +html_options+ may be a hash of attributes for the <script> tag. Example: 
    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 
    172172      def javascript_cdata_section(content) #:nodoc: 
  • lib/action_view/helpers/java_script_macros_helper.rb

    old new  
    198198        content_tag("div", "", :id => "#{object}_#{method}_auto_complete", :class => "auto_complete") + 
    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; 
    207207              background: #fff; 
     
    217217              margin:0; 
    218218              padding:3px; 
    219219            } 
    220             div.auto_complete ul li.selected {  
    221               background-color: #ffb;  
     220            div.auto_complete ul li.selected { 
     221              background-color: #ffb; 
    222222            } 
    223             div.auto_complete ul strong.highlight {  
     223            div.auto_complete ul strong.highlight { 
    224224              color: #800;  
    225225              margin:0; 
    226226              padding:0; 
    227227            } 
    228228          EOT 
    229229        end 
    230        
     230 
    231231    end 
    232232  end 
    233233end 
  • lib/action_view/helpers/asset_tag_helper.rb

    old new  
    149149          if !File.exists?(joined_javascript_path) 
    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 
    155155              cache.write(join_asset_file_contents(javascript_paths)) 
    156156            end 
    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 
    167167      end 
     
    252252          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)) 
    258258        else 
    259259          options.delete("cache") 
    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") 
    266266        end 
  • lib/action_view/base.rb

    old new  
    470470        if template_requires_setup?(extension) 
    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 
    480480        else