mirror of
https://github.com/KevinMidboe/linguist.git
synced 2026-02-11 18:59:35 +00:00
Load extensions from samples
This commit is contained in:
@@ -2,6 +2,8 @@ require 'escape_utils'
|
|||||||
require 'pygments'
|
require 'pygments'
|
||||||
require 'yaml'
|
require 'yaml'
|
||||||
|
|
||||||
|
require 'linguist/sample'
|
||||||
|
|
||||||
module Linguist
|
module Linguist
|
||||||
# Language names that are recognizable by GitHub. Defined languages
|
# Language names that are recognizable by GitHub. Defined languages
|
||||||
# can be highlighted, searched and listed under the Top Languages page.
|
# can be highlighted, searched and listed under the Top Languages page.
|
||||||
@@ -444,10 +446,25 @@ module Linguist
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
extensions = Sample.extensions
|
||||||
popular = YAML.load_file(File.expand_path("../popular.yml", __FILE__))
|
popular = YAML.load_file(File.expand_path("../popular.yml", __FILE__))
|
||||||
|
|
||||||
YAML.load_file(File.expand_path("../languages.yml", __FILE__)).each do |name, options|
|
YAML.load_file(File.expand_path("../languages.yml", __FILE__)).each do |name, options|
|
||||||
Language.create(
|
aliases = [name.downcase.gsub(/\s/, '-') ] + (options[:aliases] || [])
|
||||||
|
options['extensions'] ||= []
|
||||||
|
aliases.each do |name|
|
||||||
|
if extnames = extensions[name]
|
||||||
|
extnames.each do |extname|
|
||||||
|
if !options['extensions'].include?(extname)
|
||||||
|
options['extensions'] << extname
|
||||||
|
else
|
||||||
|
warn "#{name} #{extname.inspect} is already defined in samples/. Remove from languages.yml."
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
lang = Language.create(
|
||||||
:name => name,
|
:name => name,
|
||||||
:color => options['color'],
|
:color => options['color'],
|
||||||
:type => options['type'],
|
:type => options['type'],
|
||||||
@@ -457,7 +474,7 @@ 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'],
|
:extensions => options['extensions'].sort,
|
||||||
:primary_extension => options['primary_extension'],
|
:primary_extension => options['primary_extension'],
|
||||||
:overrides => options['overrides'],
|
:overrides => options['overrides'],
|
||||||
:filenames => options['filenames'],
|
:filenames => options['filenames'],
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
require 'set'
|
||||||
|
|
||||||
module Linguist
|
module Linguist
|
||||||
# Model for accessing classifier training data.
|
# Model for accessing classifier training data.
|
||||||
module Sample
|
module Sample
|
||||||
@@ -27,6 +29,22 @@ module Linguist
|
|||||||
nil
|
nil
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Get all extensions listed in samples/
|
||||||
|
#
|
||||||
|
# Returns Hash of sample language keys with a Set of extension
|
||||||
|
# Strings.
|
||||||
|
def self.extensions
|
||||||
|
extensions = {}
|
||||||
|
each do |sample|
|
||||||
|
extname = File.extname(sample[:path])
|
||||||
|
# TODO: For now skip empty extnames
|
||||||
|
next if extname == ""
|
||||||
|
extensions[sample[:language]] ||= Set.new
|
||||||
|
extensions[sample[:language]] << extname
|
||||||
|
end
|
||||||
|
extensions
|
||||||
|
end
|
||||||
|
|
||||||
# Public: Build Classifier from all samples.
|
# Public: Build Classifier from all samples.
|
||||||
#
|
#
|
||||||
# Returns trained Classifier.
|
# Returns trained Classifier.
|
||||||
|
|||||||
Reference in New Issue
Block a user