mirror of
				https://github.com/KevinMidboe/linguist.git
				synced 2025-10-29 17:50:22 +00:00 
			
		
		
		
	Separate special_mime_type method
This commit is contained in:
		| @@ -11,11 +11,18 @@ module Linguist | ||||
|     end | ||||
|  | ||||
|     def mime_type | ||||
|       @mime_type ||= Mime.lookup(pathname.extname) | ||||
|       @mime_type ||= begin | ||||
|         guesses = MIME::Types.type_for(pathname.extname) | ||||
|         guesses.first ? guesses.first.simplified : 'text/plain' | ||||
|       end | ||||
|     end | ||||
|  | ||||
|     def special_mime_type | ||||
|       Mime.lookup(pathname.extname) | ||||
|     end | ||||
|  | ||||
|     def disposition | ||||
|       case mime_type | ||||
|       case special_mime_type | ||||
|       when 'application/octet-stream', 'application/java-archive' | ||||
|         "attachment; filename=#{EscapeUtils.escape_url(pathname.basename)}" | ||||
|       else | ||||
| @@ -36,7 +43,7 @@ module Linguist | ||||
|     end | ||||
|  | ||||
|     def binary? | ||||
|       mime_type == 'octet-stream' || !(text? || image?) | ||||
|       special_mime_type == 'octet-stream' || !(text? || image?) | ||||
|     end | ||||
|  | ||||
|     def file? | ||||
|   | ||||
| @@ -38,9 +38,15 @@ class TestBlob < Test::Unit::TestCase | ||||
|   end | ||||
|  | ||||
|   def test_mime_type | ||||
|     assert_equal "text/plain; charset=utf-8", blob("grit.rb").mime_type | ||||
|     assert_equal "text/plain; charset=utf-8", blob("bar.xml").mime_type | ||||
|     assert_equal "application/octet-stream", blob("dog.o").mime_type | ||||
|     assert_equal "text/plain", blob("grit.rb").mime_type | ||||
|     assert_equal "application/xml", blob("bar.xml").mime_type | ||||
|     assert_equal "text/plain", blob("dog.o").mime_type | ||||
|   end | ||||
|  | ||||
|   def test_special_mime_type | ||||
|     assert_equal "text/plain; charset=utf-8", blob("grit.rb").special_mime_type | ||||
|     assert_equal "text/plain; charset=utf-8", blob("bar.xml").special_mime_type | ||||
|     assert_equal "application/octet-stream", blob("dog.o").special_mime_type | ||||
|   end | ||||
|  | ||||
|   def test_disposition | ||||
|   | ||||
		Reference in New Issue
	
	Block a user