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?
|
||||
"attachment"
|
||||
else
|
||||
"attachment; filename=#{EscapeUtils.escape_url(File.basename(name))}"
|
||||
"attachment; filename=#{EscapeUtils.escape_url(name)}"
|
||||
end
|
||||
end
|
||||
|
||||
@@ -233,7 +233,7 @@ module Linguist
|
||||
#
|
||||
# Return true or false
|
||||
def vendored?
|
||||
name =~ VendoredRegexp ? true : false
|
||||
path =~ VendoredRegexp ? true : false
|
||||
end
|
||||
|
||||
# Public: Get each line of data
|
||||
@@ -301,7 +301,7 @@ module Linguist
|
||||
#
|
||||
# Return true or false
|
||||
def generated?
|
||||
@_generated ||= Generated.generated?(name, lambda { data })
|
||||
@_generated ||= Generated.generated?(path, lambda { data })
|
||||
end
|
||||
|
||||
# Public: Detects the Language of the blob.
|
||||
|
||||
@@ -3,7 +3,7 @@ require 'linguist/blob_helper'
|
||||
module Linguist
|
||||
# A FileBlob is a wrapper around a File object to make it quack
|
||||
# like a Grit::Blob. It provides the basic interface: `name`,
|
||||
# `data`, and `size`.
|
||||
# `data`, `path` and `size`.
|
||||
class FileBlob
|
||||
include BlobHelper
|
||||
|
||||
@@ -14,43 +14,50 @@ module Linguist
|
||||
#
|
||||
# Returns a FileBlob.
|
||||
def initialize(path, base_path = nil)
|
||||
@path = path
|
||||
@name = base_path ? path.sub("#{base_path}/", '') : path
|
||||
@fullpath = path
|
||||
@path = base_path ? path.sub("#{base_path}/", '') : path
|
||||
end
|
||||
|
||||
# Public: Filename
|
||||
#
|
||||
# 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"
|
||||
#
|
||||
# FileBlob.new("/path/to/linguist/lib/linguist.rb",
|
||||
# "/path/to/linguist").name
|
||||
# "/path/to/linguist").path
|
||||
# # => "lib/linguist.rb"
|
||||
#
|
||||
# Returns a String
|
||||
attr_reader :name
|
||||
attr_reader :path
|
||||
|
||||
# Public: Read file permissions
|
||||
#
|
||||
# Returns a String like '100644'
|
||||
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
|
||||
|
||||
# Public: Read file contents.
|
||||
#
|
||||
# Returns a String.
|
||||
def data
|
||||
File.read(@path)
|
||||
File.read(@fullpath)
|
||||
end
|
||||
|
||||
# Public: Get byte size
|
||||
#
|
||||
# Returns an Integer.
|
||||
def size
|
||||
File.size(@path)
|
||||
File.size(@fullpath)
|
||||
end
|
||||
|
||||
# Public: Get file extension.
|
||||
@@ -67,7 +74,7 @@ module Linguist
|
||||
#
|
||||
# Returns an Array
|
||||
def extensions
|
||||
basename, *segments = File.basename(name).split(".")
|
||||
basename, *segments = name.split(".")
|
||||
|
||||
segments.map.with_index do |segment, index|
|
||||
"." + segments[index..-1].join(".")
|
||||
|
||||
@@ -14,13 +14,15 @@ module Linguist
|
||||
|
||||
attr_reader :repository
|
||||
attr_reader :oid
|
||||
attr_reader :name
|
||||
attr_reader :path
|
||||
attr_reader :mode
|
||||
|
||||
def initialize(repo, oid, name, mode = nil)
|
||||
alias :name :path
|
||||
|
||||
def initialize(repo, oid, path, mode = nil)
|
||||
@repository = repo
|
||||
@oid = oid
|
||||
@name = name
|
||||
@path = path
|
||||
@mode = mode
|
||||
end
|
||||
|
||||
|
||||
@@ -251,8 +251,7 @@ class TestBlob < Minitest::Test
|
||||
assert sample_blob("Zephir/filenames/exception.zep.php").generated?
|
||||
assert !sample_blob("Zephir/Router.zep").generated?
|
||||
|
||||
|
||||
assert Linguist::Generated.generated?("node_modules/grunt/lib/grunt.js", nil)
|
||||
assert sample_blob("node_modules/grunt/lib/grunt.js").generated?
|
||||
|
||||
# Godep saved dependencies
|
||||
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/v8/src/v8.h").vendored?
|
||||
|
||||
assert sample_blob("tools/something/else.c").vendored?
|
||||
|
||||
# Chart.js
|
||||
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
|
||||
assert sample_blob("debian/cron.d").vendored?
|
||||
|
||||
# Erlang
|
||||
assert sample_blob("rebar").vendored?
|
||||
|
||||
# Minified JavaScript and CSS
|
||||
assert sample_blob("foo.min.js").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("foo.min.txt").vendored?
|
||||
|
||||
#.osx
|
||||
assert sample_blob(".osx").vendored?
|
||||
|
||||
# Prototype
|
||||
assert !sample_blob("public/javascripts/application.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/dragdrop.js").vendored?
|
||||
|
||||
# Samples
|
||||
assert sample_blob("Samples/Ruby/foo.rb").vendored?
|
||||
|
||||
# jQuery
|
||||
assert sample_blob("jquery.js").vendored?
|
||||
assert sample_blob("public/javascripts/jquery.js").vendored?
|
||||
|
||||
Reference in New Issue
Block a user