Make Language.[] and Language.find_by(alias|name) ignore case

This makes it easier to find a Linguist::Language for a fenced code
block in Markdown, where language names are often specified in
lowercase.
This commit is contained in:
Adam Roben
2014-11-07 09:42:17 -05:00
parent d9ed216092
commit 751360ecf1
2 changed files with 20 additions and 5 deletions

View File

@@ -62,7 +62,7 @@ module Linguist
end
# Language name index
@index[language.name] = @name_index[language.name] = language
@index[language.name.downcase] = @name_index[language.name.downcase] = language
language.aliases.each do |name|
# All Language aliases should be unique. Raise if there is a duplicate.
@@ -70,7 +70,7 @@ module Linguist
raise ArgumentError, "Duplicate alias: #{name}"
end
@index[name] = @alias_index[name] = language
@index[name.downcase] = @alias_index[name.downcase] = language
end
language.extensions.each do |extension|
@@ -164,7 +164,7 @@ module Linguist
#
# Returns the Language or nil if none was found.
def self.find_by_name(name)
@name_index[name]
@name_index[name.downcase]
end
# Public: Look up Language by one of its aliases.
@@ -178,7 +178,7 @@ module Linguist
#
# Returns the Lexer or nil if none was found.
def self.find_by_alias(name)
@alias_index[name]
@alias_index[name.downcase]
end
# Public: Look up Languages by filename.
@@ -227,7 +227,7 @@ module Linguist
#
# Returns the Language or nil if none was found.
def self.[](name)
@index[name]
@index[name.downcase]
end
# Public: A List of popular languages