mirror of
https://github.com/KevinMidboe/linguist.git
synced 2025-10-29 17:50:22 +00:00
Merge name and alias index
This commit is contained in:
@@ -10,6 +10,7 @@ module Linguist
|
|||||||
# mimetypes - Mime types (application/javascript)
|
# mimetypes - Mime types (application/javascript)
|
||||||
class Lexer < Struct.new(:name, :aliases, :filenames, :mimetypes)
|
class Lexer < Struct.new(:name, :aliases, :filenames, :mimetypes)
|
||||||
@lexers = []
|
@lexers = []
|
||||||
|
@index = {}
|
||||||
@name_index = {}
|
@name_index = {}
|
||||||
@alias_index = {}
|
@alias_index = {}
|
||||||
@mimetypes_index = {}
|
@mimetypes_index = {}
|
||||||
@@ -31,6 +32,18 @@ module Linguist
|
|||||||
@lexers
|
@lexers
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Public: Look up Lexer by name or alias.
|
||||||
|
#
|
||||||
|
# name - A String name or alias
|
||||||
|
#
|
||||||
|
# Lexer['Ruby']
|
||||||
|
# => #<Lexer name="Ruby">
|
||||||
|
#
|
||||||
|
# Returns the Lexer or nil if none was found.
|
||||||
|
def self.[](name)
|
||||||
|
@index[name]
|
||||||
|
end
|
||||||
|
|
||||||
# Public: Look up Lexer by its proper name.
|
# Public: Look up Lexer by its proper name.
|
||||||
#
|
#
|
||||||
# name - The String name of the Lexer
|
# name - The String name of the Lexer
|
||||||
@@ -73,18 +86,6 @@ module Linguist
|
|||||||
@mimetypes_index[type]
|
@mimetypes_index[type]
|
||||||
end
|
end
|
||||||
|
|
||||||
# Public: Look up Lexer by name or alias.
|
|
||||||
#
|
|
||||||
# name - A String name or alias
|
|
||||||
#
|
|
||||||
# Lexer['Ruby']
|
|
||||||
# => #<Lexer name="Ruby">
|
|
||||||
#
|
|
||||||
# Returns the Lexer or nil if none was found.
|
|
||||||
def self.[](name)
|
|
||||||
find_by_name(name) || find_by_alias(name)
|
|
||||||
end
|
|
||||||
|
|
||||||
# Public: Return a alias of the Lexer to pass to Pygments.
|
# Public: Return a alias of the Lexer to pass to Pygments.
|
||||||
#
|
#
|
||||||
# The alias we choose is arbitrary.
|
# The alias we choose is arbitrary.
|
||||||
@@ -137,7 +138,7 @@ module Linguist
|
|||||||
warn "Duplicate lexer name: #{lexer.name}"
|
warn "Duplicate lexer name: #{lexer.name}"
|
||||||
end
|
end
|
||||||
|
|
||||||
@name_index[lexer.name] = lexer
|
@index[lexer.name] = @name_index[lexer.name] = lexer
|
||||||
|
|
||||||
lexer.aliases.each do |name|
|
lexer.aliases.each do |name|
|
||||||
# All Lexer aliases should be unique. Warn if there is a duplicate.
|
# All Lexer aliases should be unique. Warn if there is a duplicate.
|
||||||
@@ -145,7 +146,7 @@ module Linguist
|
|||||||
warn "Duplicate alias: #{name}"
|
warn "Duplicate alias: #{name}"
|
||||||
end
|
end
|
||||||
|
|
||||||
@alias_index[name] = lexer
|
@index[name] = @alias_index[name] = lexer
|
||||||
end
|
end
|
||||||
|
|
||||||
lexer.mimetypes.each do |type|
|
lexer.mimetypes.each do |type|
|
||||||
|
|||||||
Reference in New Issue
Block a user