mirror of
https://github.com/KevinMidboe/linguist.git
synced 2025-10-29 17:50:22 +00:00
Merge pull request #1976 from github/path-for-fileblob
Use path for Generated?
This commit is contained in:
@@ -99,7 +99,7 @@ module Linguist
|
|||||||
elsif name.nil?
|
elsif name.nil?
|
||||||
"attachment"
|
"attachment"
|
||||||
else
|
else
|
||||||
"attachment; filename=#{EscapeUtils.escape_url(File.basename(name))}"
|
"attachment; filename=#{EscapeUtils.escape_url(name)}"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -233,7 +233,7 @@ module Linguist
|
|||||||
#
|
#
|
||||||
# Return true or false
|
# Return true or false
|
||||||
def vendored?
|
def vendored?
|
||||||
name =~ VendoredRegexp ? true : false
|
path =~ VendoredRegexp ? true : false
|
||||||
end
|
end
|
||||||
|
|
||||||
# Public: Get each line of data
|
# Public: Get each line of data
|
||||||
@@ -301,7 +301,7 @@ module Linguist
|
|||||||
#
|
#
|
||||||
# Return true or false
|
# Return true or false
|
||||||
def generated?
|
def generated?
|
||||||
@_generated ||= Generated.generated?(name, lambda { data })
|
@_generated ||= Generated.generated?(path, lambda { data })
|
||||||
end
|
end
|
||||||
|
|
||||||
# Public: Detects the Language of the blob.
|
# Public: Detects the Language of the blob.
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ require 'linguist/blob_helper'
|
|||||||
module Linguist
|
module Linguist
|
||||||
# A FileBlob is a wrapper around a File object to make it quack
|
# A FileBlob is a wrapper around a File object to make it quack
|
||||||
# like a Grit::Blob. It provides the basic interface: `name`,
|
# like a Grit::Blob. It provides the basic interface: `name`,
|
||||||
# `data`, and `size`.
|
# `data`, `path` and `size`.
|
||||||
class FileBlob
|
class FileBlob
|
||||||
include BlobHelper
|
include BlobHelper
|
||||||
|
|
||||||
@@ -14,43 +14,50 @@ module Linguist
|
|||||||
#
|
#
|
||||||
# Returns a FileBlob.
|
# Returns a FileBlob.
|
||||||
def initialize(path, base_path = nil)
|
def initialize(path, base_path = nil)
|
||||||
@path = path
|
@fullpath = path
|
||||||
@name = base_path ? path.sub("#{base_path}/", '') : path
|
@path = base_path ? path.sub("#{base_path}/", '') : path
|
||||||
end
|
end
|
||||||
|
|
||||||
# Public: Filename
|
# Public: Filename
|
||||||
#
|
#
|
||||||
# Examples
|
# Examples
|
||||||
#
|
#
|
||||||
# FileBlob.new("/path/to/linguist/lib/linguist.rb").name
|
# FileBlob.new("/path/to/linguist/lib/linguist.rb").path
|
||||||
# # => "/path/to/linguist/lib/linguist.rb"
|
# # => "/path/to/linguist/lib/linguist.rb"
|
||||||
#
|
#
|
||||||
# FileBlob.new("/path/to/linguist/lib/linguist.rb",
|
# FileBlob.new("/path/to/linguist/lib/linguist.rb",
|
||||||
# "/path/to/linguist").name
|
# "/path/to/linguist").path
|
||||||
# # => "lib/linguist.rb"
|
# # => "lib/linguist.rb"
|
||||||
#
|
#
|
||||||
# Returns a String
|
# Returns a String
|
||||||
attr_reader :name
|
attr_reader :path
|
||||||
|
|
||||||
# Public: Read file permissions
|
# Public: Read file permissions
|
||||||
#
|
#
|
||||||
# Returns a String like '100644'
|
# Returns a String like '100644'
|
||||||
def mode
|
def mode
|
||||||
File.stat(@path).mode.to_s(8)
|
File.stat(@fullpath).mode.to_s(8)
|
||||||
|
end
|
||||||
|
|
||||||
|
# Public: File name
|
||||||
|
#
|
||||||
|
# Returns a String
|
||||||
|
def name
|
||||||
|
File.basename(@fullpath)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Public: Read file contents.
|
# Public: Read file contents.
|
||||||
#
|
#
|
||||||
# Returns a String.
|
# Returns a String.
|
||||||
def data
|
def data
|
||||||
File.read(@path)
|
File.read(@fullpath)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Public: Get byte size
|
# Public: Get byte size
|
||||||
#
|
#
|
||||||
# Returns an Integer.
|
# Returns an Integer.
|
||||||
def size
|
def size
|
||||||
File.size(@path)
|
File.size(@fullpath)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Public: Get file extension.
|
# Public: Get file extension.
|
||||||
@@ -67,7 +74,7 @@ module Linguist
|
|||||||
#
|
#
|
||||||
# Returns an Array
|
# Returns an Array
|
||||||
def extensions
|
def extensions
|
||||||
basename, *segments = File.basename(name).split(".")
|
basename, *segments = name.split(".")
|
||||||
|
|
||||||
segments.map.with_index do |segment, index|
|
segments.map.with_index do |segment, index|
|
||||||
"." + segments[index..-1].join(".")
|
"." + segments[index..-1].join(".")
|
||||||
|
|||||||
@@ -14,13 +14,15 @@ module Linguist
|
|||||||
|
|
||||||
attr_reader :repository
|
attr_reader :repository
|
||||||
attr_reader :oid
|
attr_reader :oid
|
||||||
attr_reader :name
|
attr_reader :path
|
||||||
attr_reader :mode
|
attr_reader :mode
|
||||||
|
|
||||||
def initialize(repo, oid, name, mode = nil)
|
alias :name :path
|
||||||
|
|
||||||
|
def initialize(repo, oid, path, mode = nil)
|
||||||
@repository = repo
|
@repository = repo
|
||||||
@oid = oid
|
@oid = oid
|
||||||
@name = name
|
@path = path
|
||||||
@mode = mode
|
@mode = mode
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -251,8 +251,7 @@ class TestBlob < Minitest::Test
|
|||||||
assert sample_blob("Zephir/filenames/exception.zep.php").generated?
|
assert sample_blob("Zephir/filenames/exception.zep.php").generated?
|
||||||
assert !sample_blob("Zephir/Router.zep").generated?
|
assert !sample_blob("Zephir/Router.zep").generated?
|
||||||
|
|
||||||
|
assert sample_blob("node_modules/grunt/lib/grunt.js").generated?
|
||||||
assert Linguist::Generated.generated?("node_modules/grunt/lib/grunt.js", nil)
|
|
||||||
|
|
||||||
# Godep saved dependencies
|
# Godep saved dependencies
|
||||||
assert sample_blob("Godeps/Godeps.json").generated?
|
assert sample_blob("Godeps/Godeps.json").generated?
|
||||||
@@ -292,6 +291,8 @@ class TestBlob < Minitest::Test
|
|||||||
assert sample_blob("deps/http_parser/http_parser.c").vendored?
|
assert sample_blob("deps/http_parser/http_parser.c").vendored?
|
||||||
assert sample_blob("deps/v8/src/v8.h").vendored?
|
assert sample_blob("deps/v8/src/v8.h").vendored?
|
||||||
|
|
||||||
|
assert sample_blob("tools/something/else.c").vendored?
|
||||||
|
|
||||||
# Chart.js
|
# Chart.js
|
||||||
assert sample_blob("some/vendored/path/Chart.js").vendored?
|
assert sample_blob("some/vendored/path/Chart.js").vendored?
|
||||||
assert !sample_blob("some/vendored/path/chart.js").vendored?
|
assert !sample_blob("some/vendored/path/chart.js").vendored?
|
||||||
@@ -302,6 +303,9 @@ class TestBlob < Minitest::Test
|
|||||||
# Debian packaging
|
# Debian packaging
|
||||||
assert sample_blob("debian/cron.d").vendored?
|
assert sample_blob("debian/cron.d").vendored?
|
||||||
|
|
||||||
|
# Erlang
|
||||||
|
assert sample_blob("rebar").vendored?
|
||||||
|
|
||||||
# Minified JavaScript and CSS
|
# Minified JavaScript and CSS
|
||||||
assert sample_blob("foo.min.js").vendored?
|
assert sample_blob("foo.min.js").vendored?
|
||||||
assert sample_blob("foo.min.css").vendored?
|
assert sample_blob("foo.min.css").vendored?
|
||||||
@@ -310,6 +314,9 @@ class TestBlob < Minitest::Test
|
|||||||
assert !sample_blob("foomin.css").vendored?
|
assert !sample_blob("foomin.css").vendored?
|
||||||
assert !sample_blob("foo.min.txt").vendored?
|
assert !sample_blob("foo.min.txt").vendored?
|
||||||
|
|
||||||
|
#.osx
|
||||||
|
assert sample_blob(".osx").vendored?
|
||||||
|
|
||||||
# Prototype
|
# Prototype
|
||||||
assert !sample_blob("public/javascripts/application.js").vendored?
|
assert !sample_blob("public/javascripts/application.js").vendored?
|
||||||
assert sample_blob("public/javascripts/prototype.js").vendored?
|
assert sample_blob("public/javascripts/prototype.js").vendored?
|
||||||
@@ -317,6 +324,9 @@ class TestBlob < Minitest::Test
|
|||||||
assert sample_blob("public/javascripts/controls.js").vendored?
|
assert sample_blob("public/javascripts/controls.js").vendored?
|
||||||
assert sample_blob("public/javascripts/dragdrop.js").vendored?
|
assert sample_blob("public/javascripts/dragdrop.js").vendored?
|
||||||
|
|
||||||
|
# Samples
|
||||||
|
assert sample_blob("Samples/Ruby/foo.rb").vendored?
|
||||||
|
|
||||||
# jQuery
|
# jQuery
|
||||||
assert sample_blob("jquery.js").vendored?
|
assert sample_blob("jquery.js").vendored?
|
||||||
assert sample_blob("public/javascripts/jquery.js").vendored?
|
assert sample_blob("public/javascripts/jquery.js").vendored?
|
||||||
|
|||||||
Reference in New Issue
Block a user