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/mime'
|
||||||
require 'linguist/pathname'
|
require 'linguist/pathname'
|
||||||
|
|
||||||
|
require 'escape_utils'
|
||||||
|
|
||||||
module Linguist
|
module Linguist
|
||||||
class Blob
|
class Blob
|
||||||
def initialize(blob)
|
def initialize(blob)
|
||||||
@@ -18,6 +20,15 @@ module Linguist
|
|||||||
Mime.lookup(name.extname)
|
Mime.lookup(name.extname)
|
||||||
end
|
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
|
def size
|
||||||
@blob.size
|
@blob.size
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -39,6 +39,13 @@ class TestBlob < Test::Unit::TestCase
|
|||||||
assert_equal "application/octet-stream", blob("dog.o").mime_type
|
assert_equal "application/octet-stream", blob("dog.o").mime_type
|
||||||
end
|
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
|
def test_data
|
||||||
assert_equal "module Foo\nend\n", blob("foo.rb").data
|
assert_equal "module Foo\nend\n", blob("foo.rb").data
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user