mirror of
https://github.com/KevinMidboe/linguist.git
synced 2025-10-29 17:50:22 +00:00
Add helper method to retrieve languages by type
This commit is contained in:
@@ -26,7 +26,7 @@ module Linguist
|
||||
@primary_extension_index = {}
|
||||
|
||||
# Valid Languages types
|
||||
TYPES = [:data, :markup, :programming]
|
||||
TYPES = [:data, :markup, :programming, :prose]
|
||||
|
||||
# Names of non-programming languages that we will still detect
|
||||
#
|
||||
@@ -35,6 +35,15 @@ module Linguist
|
||||
["CSS", "Less", "Sass", "TeX"]
|
||||
end
|
||||
|
||||
# Detect languages by a specific type
|
||||
#
|
||||
# type - A symbol that exists within TYPES
|
||||
#
|
||||
# Returns an array
|
||||
def self.by_type(type)
|
||||
all.select { |h| h.type == type }
|
||||
end
|
||||
|
||||
# Internal: Create a new Language object
|
||||
#
|
||||
# attributes - A hash of attributes
|
||||
|
||||
@@ -368,6 +368,9 @@ class TestLanguage < Test::Unit::TestCase
|
||||
assert !Language['Ruby'].eql?(Language['Python'])
|
||||
end
|
||||
|
||||
def test_by_type
|
||||
assert_equal 6, Language.by_type(:prose).length
|
||||
end
|
||||
|
||||
def test_colorize
|
||||
assert_equal <<-HTML.chomp, Language['Ruby'].colorize("def foo\n 'foo'\nend\n")
|
||||
|
||||
Reference in New Issue
Block a user