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] = [] } | ||||
|     @interpreter_index        = Hash.new { |h,k| h[k] = [] } | ||||
|     @filename_index           = Hash.new { |h,k| h[k] = [] } | ||||
|     @primary_extension_index  = {} | ||||
|  | ||||
|     # Valid Languages types | ||||
|     TYPES = [:data, :markup, :programming, :prose] | ||||
| @@ -80,12 +79,6 @@ module Linguist | ||||
|         @extension_index[extension] << language | ||||
|       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| | ||||
|         @interpreter_index[interpreter] << language | ||||
|       end | ||||
| @@ -191,8 +184,7 @@ module Linguist | ||||
|     # Returns all matching Languages or [] if none were found. | ||||
|     def self.find_by_filename(filename) | ||||
|       basename, extname = File.basename(filename), File.extname(filename) | ||||
|       langs = [@primary_extension_index[extname]] + | ||||
|               @filename_index[basename] + | ||||
|       langs = @filename_index[basename] + | ||||
|               @extension_index[extname] | ||||
|       langs.compact.uniq | ||||
|     end | ||||
| @@ -299,15 +291,6 @@ module Linguist | ||||
|       @interpreters = attributes[:interpreters]   || [] | ||||
|       @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 | ||||
|       @popular    = attributes.key?(:popular)    ? attributes[:popular]    : false | ||||
|       @searchable = attributes.key?(:searchable) ? attributes[:searchable] : true | ||||
| @@ -395,20 +378,6 @@ module Linguist | ||||
|     # Returns the extensions Array | ||||
|     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 | ||||
|     # | ||||
|     # Examples | ||||
| @@ -432,6 +401,22 @@ module Linguist | ||||
|       (extensions + [primary_extension]).uniq | ||||
|     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. | ||||
|     # | ||||
|     # Examples | ||||
| @@ -573,9 +558,8 @@ module Linguist | ||||
|       :group_name        => options['group'], | ||||
|       :searchable        => options.key?('searchable') ? options['searchable'] : true, | ||||
|       :search_term       => options['search_term'], | ||||
|       :extensions        => options['extensions'].sort, | ||||
|       :extensions        => [options['extensions'].first] + options['extensions'][1..-1].sort, | ||||
|       :interpreters      => options['interpreters'].sort, | ||||
|       :primary_extension => options['primary_extension'], | ||||
|       :filenames         => options['filenames'], | ||||
|       :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| | ||||
|       if line =~ /^  extensions:$/ | ||||
|         extensions = [] | ||||
|       elsif extensions && line =~ /^  - \.(\w+)$/ | ||||
|       elsif extensions && line =~ /^  - \.([\w-]+)( *#.*)?$/ | ||||
|         extensions << $1 | ||||
|       else | ||||
|         assert_sorted extensions if extensions | ||||
|         assert_sorted extensions[1..-1] if extensions | ||||
|         extensions = nil | ||||
|       end | ||||
|     end | ||||
|   | ||||
		Reference in New Issue
	
	Block a user