mirror of
https://github.com/KevinMidboe/linguist.git
synced 2025-10-29 17:50:22 +00:00
Move specific filename samples into their own dir
This commit is contained in:
@@ -442,11 +442,13 @@ module Linguist
|
||||
end
|
||||
|
||||
extensions = Sample.extensions
|
||||
filenames = Sample.filenames
|
||||
popular = YAML.load_file(File.expand_path("../popular.yml", __FILE__))
|
||||
|
||||
YAML.load_file(File.expand_path("../languages.yml", __FILE__)).each do |name, options|
|
||||
aliases = [name.downcase.gsub(/\s/, '-') ] + (options[:aliases] || [])
|
||||
options['extensions'] ||= []
|
||||
options['filenames'] ||= []
|
||||
aliases.each do |name|
|
||||
if extnames = extensions[name]
|
||||
extnames.each do |extname|
|
||||
@@ -457,6 +459,16 @@ module Linguist
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if fns = filenames[name]
|
||||
fns.each do |filename|
|
||||
if !options['filenames'].include?(filename)
|
||||
options['filenames'] << filename
|
||||
else
|
||||
warn "#{name} #{filename.inspect} is already defined in samples/. Remove from languages.yml."
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
lang = Language.create(
|
||||
|
||||
@@ -1064,11 +1064,9 @@ Ruby:
|
||||
- .thor
|
||||
- .watchr
|
||||
filenames:
|
||||
- Capfile
|
||||
- Gemfile
|
||||
- Guardfile
|
||||
- Podfile
|
||||
- Rakefile
|
||||
- Thorfile
|
||||
- Vagrantfile
|
||||
|
||||
@@ -1151,7 +1149,6 @@ Shell:
|
||||
- .zshrc
|
||||
- bashrc
|
||||
- zshrc
|
||||
- PKGBUILD
|
||||
|
||||
Smalltalk:
|
||||
type: programming
|
||||
|
||||
@@ -22,7 +22,24 @@ module Linguist
|
||||
dirname = File.join(PATH, category)
|
||||
Dir.entries(dirname).each do |filename|
|
||||
next if filename == '.' || filename == '..'
|
||||
yield({ :path => File.join(dirname, filename), :language => category })
|
||||
|
||||
if filename == 'filenames'
|
||||
Dir.entries(File.join(dirname, filename)).each do |subfilename|
|
||||
next if subfilename == '.' || subfilename == '..'
|
||||
|
||||
yield({
|
||||
:path => File.join(dirname, filename, subfilename),
|
||||
:language => category,
|
||||
:filename => subfilename
|
||||
})
|
||||
end
|
||||
else
|
||||
yield({
|
||||
:path => File.join(dirname, filename),
|
||||
:language => category,
|
||||
:extname => File.extname(filename)
|
||||
})
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -36,15 +53,29 @@ module Linguist
|
||||
def self.extensions
|
||||
extensions = {}
|
||||
each do |sample|
|
||||
extname = File.extname(sample[:path])
|
||||
# TODO: For now skip empty extnames
|
||||
next if extname == ""
|
||||
next if sample[:extname].nil? || sample[:extname] == ""
|
||||
extensions[sample[:language]] ||= Set.new
|
||||
extensions[sample[:language]] << extname
|
||||
extensions[sample[:language]] << sample[:extname]
|
||||
end
|
||||
extensions
|
||||
end
|
||||
|
||||
# Get all filenames listed in samples/
|
||||
#
|
||||
# Returns Hash of sample language keys with a Set of filename
|
||||
# Strings.
|
||||
def self.filenames
|
||||
filenames = {}
|
||||
each do |sample|
|
||||
# TODO: For now skip empty extnames
|
||||
next if sample[:filename].nil?
|
||||
filenames[sample[:language]] ||= Set.new
|
||||
filenames[sample[:language]] << sample[:filename]
|
||||
end
|
||||
filenames
|
||||
end
|
||||
|
||||
# Public: Build Classifier from all samples.
|
||||
#
|
||||
# Returns trained Classifier.
|
||||
|
||||
@@ -87,6 +87,6 @@ class TestTokenizer < Test::Unit::TestCase
|
||||
def test_ruby_tokens
|
||||
assert_equal %w(module Foo end), tokenize(:"ruby/foo.rb")
|
||||
assert_equal %w(# /usr/bin/env ruby puts), tokenize(:"ruby/script.rb")
|
||||
assert_equal %w(task default do puts end), tokenize(:"ruby/Rakefile")
|
||||
assert_equal %w(task default do puts end), tokenize(:"ruby/filenames/Rakefile")
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user