mirror of
https://github.com/KevinMidboe/linguist.git
synced 2025-10-29 09:40:21 +00:00
Add list of popular languages
This commit is contained in:
@@ -43,6 +43,14 @@ module Linguist
|
||||
@lexer_index.to_a
|
||||
end
|
||||
|
||||
def self.popular
|
||||
@name_index.values.select(&:popular?).sort_by { |lang| lang.name.downcase }
|
||||
end
|
||||
|
||||
def self.unpopular
|
||||
@name_index.values.select(&:unpopular?).sort_by { |lang| lang.name.downcase }
|
||||
end
|
||||
|
||||
def self.lexer2name(lexer)
|
||||
if language = find_by_lexer(lexer)
|
||||
language.name
|
||||
@@ -59,6 +67,7 @@ module Linguist
|
||||
@name = attributes[:name] || raise(ArgumentError, "missing name")
|
||||
@lexer = attributes[:lexer] || default_lexer
|
||||
@extensions = attributes[:extensions] || []
|
||||
@popular = attributes[:popular] || false
|
||||
end
|
||||
|
||||
attr_reader :name, :lexer, :extensions
|
||||
@@ -71,6 +80,14 @@ module Linguist
|
||||
lexer == default_lexer
|
||||
end
|
||||
|
||||
def popular?
|
||||
@popular
|
||||
end
|
||||
|
||||
def unpopular?
|
||||
!popular?
|
||||
end
|
||||
|
||||
def ==(other)
|
||||
eql?(other)
|
||||
end
|
||||
@@ -80,7 +97,14 @@ module Linguist
|
||||
end
|
||||
end
|
||||
|
||||
popular = YAML.load_file(File.expand_path("../popular.yml", __FILE__))
|
||||
|
||||
YAML.load_file(File.expand_path("../extensions.yml", __FILE__)).each do |name, options|
|
||||
Language.create(:name => name, :lexer => options[:lexer], :extensions => options[:ext])
|
||||
Language.create(
|
||||
:name => name,
|
||||
:lexer => options[:lexer],
|
||||
:extensions => options[:ext],
|
||||
:popular => popular.include?(name)
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
25
lib/linguist/popular.yml
Normal file
25
lib/linguist/popular.yml
Normal file
@@ -0,0 +1,25 @@
|
||||
- ActionScript
|
||||
- Bash
|
||||
- C
|
||||
- Common Lisp
|
||||
- C#
|
||||
- C++
|
||||
- CSS
|
||||
- Diff
|
||||
- Emacs Lisp
|
||||
- Erlang
|
||||
- Haskell
|
||||
- HTML
|
||||
- Java
|
||||
- JavaScript
|
||||
- Lua
|
||||
- Objective-C
|
||||
- Perl
|
||||
- PHP
|
||||
- Python
|
||||
- Ruby
|
||||
- Scala
|
||||
- Scheme
|
||||
- SQL
|
||||
- TeX
|
||||
- XML
|
||||
@@ -73,4 +73,12 @@ class TestLanguage < Test::Unit::TestCase
|
||||
assert !Language['Ruby'].eql?(Language['Python'])
|
||||
assert !Language['Ruby'].eql?(Language.new(:name => 'Ruby'))
|
||||
end
|
||||
|
||||
def test_popular
|
||||
assert Language['Ruby'].popular?
|
||||
assert Language['Perl'].popular?
|
||||
assert Language['Python'].popular?
|
||||
assert Language['Assembly'].unpopular?
|
||||
assert Language['Brainfuck'].unpopular?
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user