mirror of
https://github.com/KevinMidboe/linguist.git
synced 2025-10-29 17:50:22 +00:00
Add Blob#disposition
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
require 'linguist/mime'
|
||||
require 'linguist/pathname'
|
||||
|
||||
require 'escape_utils'
|
||||
|
||||
module Linguist
|
||||
class Blob
|
||||
def initialize(blob)
|
||||
@@ -18,6 +20,15 @@ module Linguist
|
||||
Mime.lookup(name.extname)
|
||||
end
|
||||
|
||||
def disposition
|
||||
case mime_type
|
||||
when 'application/octet-stream', 'application/java-archive'
|
||||
"attachment; filename=#{EscapeUtils.escape_url(name.to_s)}"
|
||||
else
|
||||
'inline'
|
||||
end
|
||||
end
|
||||
|
||||
def size
|
||||
@blob.size
|
||||
end
|
||||
|
||||
@@ -39,6 +39,13 @@ class TestBlob < Test::Unit::TestCase
|
||||
assert_equal "application/octet-stream", blob("dog.o").mime_type
|
||||
end
|
||||
|
||||
def test_disposition
|
||||
assert_equal "attachment; filename=foo.bin", blob("foo.bin").disposition
|
||||
assert_equal "attachment; filename=foo+bar.jar", blob("foo bar.jar").disposition
|
||||
assert_equal "inline", blob("foo.txt").disposition
|
||||
assert_equal "inline", blob("grit.rb").disposition
|
||||
end
|
||||
|
||||
def test_data
|
||||
assert_equal "module Foo\nend\n", blob("foo.rb").data
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user