mirror of
https://github.com/KevinMidboe/linguist.git
synced 2026-01-18 23:35:51 +00:00
Kill attachment stuff, just use viewable
This commit is contained in:
@@ -62,7 +62,11 @@ module Linguist
|
||||
#
|
||||
# Returns a content disposition String.
|
||||
def disposition
|
||||
pathname.disposition
|
||||
if viewable?
|
||||
'inline'
|
||||
else
|
||||
"attachment; filename=#{EscapeUtils.escape_url(pathname.basename)}"
|
||||
end
|
||||
end
|
||||
|
||||
# Public: Is the blob text?
|
||||
|
||||
@@ -15,16 +15,6 @@ module MIME
|
||||
@encoding == 'base64'
|
||||
end
|
||||
end
|
||||
|
||||
attr_accessor :attachment
|
||||
|
||||
def attachment?
|
||||
if defined? @attachment
|
||||
@attachment
|
||||
else
|
||||
binary?
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -35,8 +25,7 @@ mime_extensions.each do |mime_type, options|
|
||||
|
||||
(options['extensions'] || []).each { |ext| mime.extensions << ext }
|
||||
|
||||
mime.binary = options['binary'] if options.key?('binary')
|
||||
mime.attachment = options['attachment'] if options.key?('attachment')
|
||||
mime.binary = options['binary'] if options.key?('binary')
|
||||
|
||||
MIME::Types.add_type_variant(mime)
|
||||
MIME::Types.index_extensions(mime)
|
||||
@@ -58,9 +47,8 @@ module Linguist
|
||||
#
|
||||
# Return mime type String otherwise falls back to 'text/plain'.
|
||||
def self.mime_for(ext)
|
||||
ext ||= ''
|
||||
guesses = ::MIME::Types.type_for(ext)
|
||||
guesses.first ? guesses.first.simplified : 'text/plain'
|
||||
mime_type = lookup_mime_type_for(ext)
|
||||
mime_type ? mime_type.simplified : 'text/plain'
|
||||
end
|
||||
|
||||
Special = YAML.load_file(File.expand_path("../content_types.yml", __FILE__))
|
||||
@@ -103,25 +91,6 @@ module Linguist
|
||||
mime_type.nil? || mime_type.binary?
|
||||
end
|
||||
|
||||
# Internal: Determine if extension or mime type is an attachment.
|
||||
#
|
||||
# ext_or_mime_type - A file extension ".txt" or mime type "text/plain".
|
||||
#
|
||||
# Attachments are files that should be downloaded rather than be
|
||||
# displayed in the browser.
|
||||
#
|
||||
# This is used to set our Content-Disposition headers.
|
||||
#
|
||||
# Attachment files should generally binary files but non-
|
||||
# attachments do not imply plain text. For an example Images are
|
||||
# not treated as attachments.
|
||||
#
|
||||
# Returns true or false
|
||||
def self.attachment?(ext_or_mime_type)
|
||||
mime_type = lookup_mime_type_for(ext_or_mime_type)
|
||||
mime_type.nil? || mime_type.attachment?
|
||||
end
|
||||
|
||||
# Internal: Lookup mime type for extension or mime type
|
||||
#
|
||||
# Returns a MIME::Type
|
||||
|
||||
@@ -110,37 +110,6 @@ module Linguist
|
||||
@content_type ||= Mime.content_type_for(extname)
|
||||
end
|
||||
|
||||
# Public: Determine if the Pathname is a binary mime type.
|
||||
#
|
||||
# Returns true or false.
|
||||
def binary?
|
||||
@binary ||= language? ? false : Mime.binary?(extname)
|
||||
end
|
||||
|
||||
# Public: Determine if the Pathname should be served as an
|
||||
# attachment.
|
||||
#
|
||||
# Returns true or false.
|
||||
def attachment?
|
||||
@attachment ||= language? ? false : 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
|
||||
|
||||
Reference in New Issue
Block a user