Separate registry content type and content disposition

This commit is contained in:
Joshua Peek
2011-06-02 12:14:19 -05:00
parent 8fc89d1d4f
commit bcc2042768
8 changed files with 298 additions and 21 deletions

View File

@@ -1,6 +1,8 @@
require 'linguist/language'
require 'linguist/mime'
require 'escape_utils'
module Linguist
# Similar to ::Pathname, Linguist::Pathname wraps a path string and
# provides helpful query methods. Its useful when you only have a
@@ -99,6 +101,30 @@ module Linguist
@content_type ||= Mime.content_type_for(extname)
end
# Public: Determine if the Pathname should be served as an
# attachment.
#
# Returns true or false.
def attachment?
@attachment ||= Mime.attachment?(extname)
end
# Public: Get the Content-Disposition header value
#
# This value is used when serving raw blobs.
#
# # => "attachment; filename=file.tar"
# # => "inline"
#
# Returns a content disposition String.
def disposition
if attachment?
"attachment; filename=#{EscapeUtils.escape_url(basename)}"
else
'inline'
end
end
def to_s
@path.dup
end