mirror of
https://github.com/KevinMidboe/linguist.git
synced 2025-10-29 17:50:22 +00:00
Delete primary_extension from language data
The language attribute is still maintained as the first extension found. This allows Mercury to be properly detected by Linguist, as per #748.
This commit is contained in:
@@ -24,7 +24,6 @@ module Linguist
|
|||||||
@extension_index = Hash.new { |h,k| h[k] = [] }
|
@extension_index = Hash.new { |h,k| h[k] = [] }
|
||||||
@interpreter_index = Hash.new { |h,k| h[k] = [] }
|
@interpreter_index = Hash.new { |h,k| h[k] = [] }
|
||||||
@filename_index = Hash.new { |h,k| h[k] = [] }
|
@filename_index = Hash.new { |h,k| h[k] = [] }
|
||||||
@primary_extension_index = {}
|
|
||||||
|
|
||||||
# Valid Languages types
|
# Valid Languages types
|
||||||
TYPES = [:data, :markup, :programming, :prose]
|
TYPES = [:data, :markup, :programming, :prose]
|
||||||
@@ -80,12 +79,6 @@ module Linguist
|
|||||||
@extension_index[extension] << language
|
@extension_index[extension] << language
|
||||||
end
|
end
|
||||||
|
|
||||||
if @primary_extension_index.key?(language.primary_extension)
|
|
||||||
raise ArgumentError, "Duplicate primary extension: #{language.primary_extension}"
|
|
||||||
end
|
|
||||||
|
|
||||||
@primary_extension_index[language.primary_extension] = language
|
|
||||||
|
|
||||||
language.interpreters.each do |interpreter|
|
language.interpreters.each do |interpreter|
|
||||||
@interpreter_index[interpreter] << language
|
@interpreter_index[interpreter] << language
|
||||||
end
|
end
|
||||||
@@ -191,8 +184,7 @@ module Linguist
|
|||||||
# Returns all matching Languages or [] if none were found.
|
# Returns all matching Languages or [] if none were found.
|
||||||
def self.find_by_filename(filename)
|
def self.find_by_filename(filename)
|
||||||
basename, extname = File.basename(filename), File.extname(filename)
|
basename, extname = File.basename(filename), File.extname(filename)
|
||||||
langs = [@primary_extension_index[extname]] +
|
langs = @filename_index[basename] +
|
||||||
@filename_index[basename] +
|
|
||||||
@extension_index[extname]
|
@extension_index[extname]
|
||||||
langs.compact.uniq
|
langs.compact.uniq
|
||||||
end
|
end
|
||||||
@@ -299,15 +291,6 @@ module Linguist
|
|||||||
@interpreters = attributes[:interpreters] || []
|
@interpreters = attributes[:interpreters] || []
|
||||||
@filenames = attributes[:filenames] || []
|
@filenames = attributes[:filenames] || []
|
||||||
|
|
||||||
unless @primary_extension = attributes[:primary_extension]
|
|
||||||
raise ArgumentError, "#{@name} is missing primary extension"
|
|
||||||
end
|
|
||||||
|
|
||||||
# Prepend primary extension unless its already included
|
|
||||||
if primary_extension && !extensions.include?(primary_extension)
|
|
||||||
@extensions = [primary_extension] + extensions
|
|
||||||
end
|
|
||||||
|
|
||||||
# Set popular, and searchable flags
|
# Set popular, and searchable flags
|
||||||
@popular = attributes.key?(:popular) ? attributes[:popular] : false
|
@popular = attributes.key?(:popular) ? attributes[:popular] : false
|
||||||
@searchable = attributes.key?(:searchable) ? attributes[:searchable] : true
|
@searchable = attributes.key?(:searchable) ? attributes[:searchable] : true
|
||||||
@@ -395,20 +378,6 @@ module Linguist
|
|||||||
# Returns the extensions Array
|
# Returns the extensions Array
|
||||||
attr_reader :extensions
|
attr_reader :extensions
|
||||||
|
|
||||||
# Deprecated: Get primary extension
|
|
||||||
#
|
|
||||||
# Defaults to the first extension but can be overridden
|
|
||||||
# in the languages.yml.
|
|
||||||
#
|
|
||||||
# The primary extension can not be nil. Tests should verify this.
|
|
||||||
#
|
|
||||||
# This attribute is only used by app/helpers/gists_helper.rb for
|
|
||||||
# creating the language dropdown. It really should be using `name`
|
|
||||||
# instead. Would like to drop primary extension.
|
|
||||||
#
|
|
||||||
# Returns the extension String.
|
|
||||||
attr_reader :primary_extension
|
|
||||||
|
|
||||||
# Public: Get interpreters
|
# Public: Get interpreters
|
||||||
#
|
#
|
||||||
# Examples
|
# Examples
|
||||||
@@ -432,6 +401,22 @@ module Linguist
|
|||||||
(extensions + [primary_extension]).uniq
|
(extensions + [primary_extension]).uniq
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Deprecated: Get primary extension
|
||||||
|
#
|
||||||
|
# Defaults to the first extension but can be overridden
|
||||||
|
# in the languages.yml.
|
||||||
|
#
|
||||||
|
# The primary extension can not be nil. Tests should verify this.
|
||||||
|
#
|
||||||
|
# This method is only used by app/helpers/gists_helper.rb for creating
|
||||||
|
# the language dropdown. It really should be using `name` instead.
|
||||||
|
# Would like to drop primary extension.
|
||||||
|
#
|
||||||
|
# Returns the extension String.
|
||||||
|
def primary_extension
|
||||||
|
extensions.first
|
||||||
|
end
|
||||||
|
|
||||||
# Public: Get URL escaped name.
|
# Public: Get URL escaped name.
|
||||||
#
|
#
|
||||||
# Examples
|
# Examples
|
||||||
@@ -573,9 +558,8 @@ module Linguist
|
|||||||
:group_name => options['group'],
|
:group_name => options['group'],
|
||||||
:searchable => options.key?('searchable') ? options['searchable'] : true,
|
:searchable => options.key?('searchable') ? options['searchable'] : true,
|
||||||
:search_term => options['search_term'],
|
:search_term => options['search_term'],
|
||||||
:extensions => options['extensions'].sort,
|
:extensions => [options['extensions'].first] + options['extensions'][1..-1].sort,
|
||||||
:interpreters => options['interpreters'].sort,
|
:interpreters => options['interpreters'].sort,
|
||||||
:primary_extension => options['primary_extension'],
|
|
||||||
:filenames => options['filenames'],
|
:filenames => options['filenames'],
|
||||||
:popular => popular.include?(name)
|
:popular => popular.include?(name)
|
||||||
)
|
)
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -22,10 +22,10 @@ class TestPedantic < Test::Unit::TestCase
|
|||||||
file("languages.yml").lines.each do |line|
|
file("languages.yml").lines.each do |line|
|
||||||
if line =~ /^ extensions:$/
|
if line =~ /^ extensions:$/
|
||||||
extensions = []
|
extensions = []
|
||||||
elsif extensions && line =~ /^ - \.(\w+)$/
|
elsif extensions && line =~ /^ - \.([\w-]+)( *#.*)?$/
|
||||||
extensions << $1
|
extensions << $1
|
||||||
else
|
else
|
||||||
assert_sorted extensions if extensions
|
assert_sorted extensions[1..-1] if extensions
|
||||||
extensions = nil
|
extensions = nil
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user