mirror of
https://github.com/KevinMidboe/linguist.git
synced 2025-10-29 17:50:22 +00:00
Use mime binary
This commit is contained in:
@@ -62,18 +62,25 @@ module Linguist
|
||||
#
|
||||
# Returns a content disposition String.
|
||||
def disposition
|
||||
if viewable?
|
||||
if image? || viewable?
|
||||
'inline'
|
||||
else
|
||||
"attachment; filename=#{EscapeUtils.escape_url(pathname.basename)}"
|
||||
end
|
||||
end
|
||||
|
||||
# Public: Is the blob binary?
|
||||
#
|
||||
# Return true or false
|
||||
def binary?
|
||||
pathname.binary?
|
||||
end
|
||||
|
||||
# Public: Is the blob text?
|
||||
#
|
||||
# Return true or false
|
||||
def text?
|
||||
content_type[/(text|json)/]
|
||||
!binary?
|
||||
end
|
||||
|
||||
# Public: Is the blob a supported image format?
|
||||
@@ -83,13 +90,6 @@ module Linguist
|
||||
['.png', '.jpg', '.jpeg', '.gif'].include?(extname)
|
||||
end
|
||||
|
||||
# Public: Is the blob binary?
|
||||
#
|
||||
# Return true or false
|
||||
def binary?
|
||||
content_type.include?('octet') || !(text? || image?)
|
||||
end
|
||||
|
||||
MEGABYTE = 1024 * 1024
|
||||
|
||||
# Public: Is the blob too big to load?
|
||||
@@ -105,7 +105,7 @@ module Linguist
|
||||
#
|
||||
# Return true or false
|
||||
def viewable?
|
||||
!image? && !binary? && !large?
|
||||
text? && !large?
|
||||
end
|
||||
|
||||
vendored_paths = YAML.load_file(File.expand_path("../vendor.yml", __FILE__))
|
||||
|
||||
@@ -110,6 +110,13 @@ module Linguist
|
||||
@content_type ||= Mime.content_type_for(extname)
|
||||
end
|
||||
|
||||
# Public: Is the path binary?
|
||||
#
|
||||
# Return true or false
|
||||
def binary?
|
||||
@binary ||= Mime.binary?(extname)
|
||||
end
|
||||
|
||||
def to_s
|
||||
@path.dup
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user