mirror of
https://github.com/KevinMidboe/linguist.git
synced 2025-10-29 17:50:22 +00:00
Return nil if no Language is found
This commit is contained in:
@@ -256,7 +256,7 @@ module Linguist
|
|||||||
language
|
language
|
||||||
|
|
||||||
# See if there is a Language for the extension
|
# See if there is a Language for the extension
|
||||||
elsif language = Language.find_by_filename(pathname.to_s)
|
elsif language = pathname.language
|
||||||
language
|
language
|
||||||
|
|
||||||
# Try to detect Language from shebang line
|
# Try to detect Language from shebang line
|
||||||
|
|||||||
@@ -52,25 +52,16 @@ module Linguist
|
|||||||
# Pathname.new('file.rb').language
|
# Pathname.new('file.rb').language
|
||||||
# # => Language['Ruby']
|
# # => Language['Ruby']
|
||||||
#
|
#
|
||||||
# Returns a Langauge.
|
# Returns a Langauge or nil if none was found.
|
||||||
def language
|
def language
|
||||||
Language.find_by_filename(@path) || Language['Text']
|
@language ||= Language.find_by_filename(@path)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Internal: Has a language.
|
# Internal: Get the lexer of the path
|
||||||
#
|
|
||||||
# Will return false if language was guessed to be Text.
|
|
||||||
#
|
|
||||||
# Returns true or false.
|
|
||||||
def language?
|
|
||||||
Language.find_by_filename(@path) ? true : false
|
|
||||||
end
|
|
||||||
|
|
||||||
# Deprecated: Get the lexer of the path
|
|
||||||
#
|
#
|
||||||
# Returns a Lexer.
|
# Returns a Lexer.
|
||||||
def lexer
|
def lexer
|
||||||
language.lexer
|
language ? language.lexer : Lexer['Text only']
|
||||||
end
|
end
|
||||||
|
|
||||||
# Public: Get the mime type
|
# Public: Get the mime type
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ class TestPathname < Test::Unit::TestCase
|
|||||||
end
|
end
|
||||||
|
|
||||||
def test_language
|
def test_language
|
||||||
assert_equal Language['Text'], Pathname.new(".rb").language
|
assert_nil Pathname.new(".rb").language
|
||||||
|
|
||||||
assert_equal Language['Ruby'], Pathname.new("file.rb").language
|
assert_equal Language['Ruby'], Pathname.new("file.rb").language
|
||||||
assert_equal Language['Ruby'], Pathname.new("./file.rb").language
|
assert_equal Language['Ruby'], Pathname.new("./file.rb").language
|
||||||
@@ -37,7 +37,8 @@ class TestPathname < Test::Unit::TestCase
|
|||||||
assert_equal Language['Gentoo Ebuild'], Pathname.new("file.ebuild").language
|
assert_equal Language['Gentoo Ebuild'], Pathname.new("file.ebuild").language
|
||||||
assert_equal Language['Python'], Pathname.new("itty.py").language
|
assert_equal Language['Python'], Pathname.new("itty.py").language
|
||||||
assert_equal Language['Nu'], Pathname.new("itty.nu").language
|
assert_equal Language['Nu'], Pathname.new("itty.nu").language
|
||||||
assert_equal Language['Text'], Pathname.new("defun.kt").language
|
|
||||||
|
assert_nil Pathname.new("defun.kt").language
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_lexer
|
def test_lexer
|
||||||
|
|||||||
Reference in New Issue
Block a user