mirror of
https://github.com/KevinMidboe/linguist.git
synced 2025-12-29 13:21:01 +00:00
Move specific filename samples into their own dir
This commit is contained in:
@@ -442,11 +442,13 @@ module Linguist
|
|||||||
end
|
end
|
||||||
|
|
||||||
extensions = Sample.extensions
|
extensions = Sample.extensions
|
||||||
|
filenames = Sample.filenames
|
||||||
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|
|
||||||
aliases = [name.downcase.gsub(/\s/, '-') ] + (options[:aliases] || [])
|
aliases = [name.downcase.gsub(/\s/, '-') ] + (options[:aliases] || [])
|
||||||
options['extensions'] ||= []
|
options['extensions'] ||= []
|
||||||
|
options['filenames'] ||= []
|
||||||
aliases.each do |name|
|
aliases.each do |name|
|
||||||
if extnames = extensions[name]
|
if extnames = extensions[name]
|
||||||
extnames.each do |extname|
|
extnames.each do |extname|
|
||||||
@@ -457,6 +459,16 @@ module Linguist
|
|||||||
end
|
end
|
||||||
end
|
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
|
end
|
||||||
|
|
||||||
lang = Language.create(
|
lang = Language.create(
|
||||||
|
|||||||
@@ -1064,11 +1064,9 @@ Ruby:
|
|||||||
- .thor
|
- .thor
|
||||||
- .watchr
|
- .watchr
|
||||||
filenames:
|
filenames:
|
||||||
- Capfile
|
|
||||||
- Gemfile
|
- Gemfile
|
||||||
- Guardfile
|
- Guardfile
|
||||||
- Podfile
|
- Podfile
|
||||||
- Rakefile
|
|
||||||
- Thorfile
|
- Thorfile
|
||||||
- Vagrantfile
|
- Vagrantfile
|
||||||
|
|
||||||
@@ -1151,7 +1149,6 @@ Shell:
|
|||||||
- .zshrc
|
- .zshrc
|
||||||
- bashrc
|
- bashrc
|
||||||
- zshrc
|
- zshrc
|
||||||
- PKGBUILD
|
|
||||||
|
|
||||||
Smalltalk:
|
Smalltalk:
|
||||||
type: programming
|
type: programming
|
||||||
|
|||||||
@@ -22,7 +22,24 @@ module Linguist
|
|||||||
dirname = File.join(PATH, category)
|
dirname = File.join(PATH, category)
|
||||||
Dir.entries(dirname).each do |filename|
|
Dir.entries(dirname).each do |filename|
|
||||||
next if filename == '.' || 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
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -36,15 +53,29 @@ module Linguist
|
|||||||
def self.extensions
|
def self.extensions
|
||||||
extensions = {}
|
extensions = {}
|
||||||
each do |sample|
|
each do |sample|
|
||||||
extname = File.extname(sample[:path])
|
|
||||||
# TODO: For now skip empty extnames
|
# TODO: For now skip empty extnames
|
||||||
next if extname == ""
|
next if sample[:extname].nil? || sample[:extname] == ""
|
||||||
extensions[sample[:language]] ||= Set.new
|
extensions[sample[:language]] ||= Set.new
|
||||||
extensions[sample[:language]] << extname
|
extensions[sample[:language]] << sample[:extname]
|
||||||
end
|
end
|
||||||
extensions
|
extensions
|
||||||
end
|
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.
|
# Public: Build Classifier from all samples.
|
||||||
#
|
#
|
||||||
# Returns trained Classifier.
|
# Returns trained Classifier.
|
||||||
|
|||||||
@@ -87,6 +87,6 @@ class TestTokenizer < Test::Unit::TestCase
|
|||||||
def test_ruby_tokens
|
def test_ruby_tokens
|
||||||
assert_equal %w(module Foo end), tokenize(:"ruby/foo.rb")
|
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(# /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
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user