Add language groups

This commit is contained in:
Joshua Peek
2011-06-22 10:07:37 -05:00
parent 876265e8f3
commit a881cde6fd
3 changed files with 67 additions and 0 deletions

View File

@@ -197,6 +197,21 @@ module Linguist
@popular = attributes.key?(:popular) ? attributes[:popular] : false
@common = attributes.key?(:common) ? attributes[:common] : false
@searchable = attributes.key?(:searchable) ? attributes[:searchable] : true
# If group name is set, save the name so we can lazy load it later
if attributes[:group_name]
if common?
warn "#{name} is a major langauage, it should not be grouped with #{attributes[:group_name]}"
end
@group = nil
@group_name = attributes[:group_name]
# Otherwise we can set it to self now
else
@group = self
end
end
# Public: Get proper name
@@ -261,6 +276,19 @@ module Linguist
name.downcase.gsub(/\s/, '-')
end
# Public: Get Language group
#
# Minor languages maybe grouped with major languages for
# accounting purposes. For an example, JSP files are grouped as
# Java.
#
# For major languages, group should always return self.
#
# Returns a Language
def group
@group ||= Language.find_by_name(@group_name)
end
# Public: Is it popular?
#
# Returns true or false
@@ -337,6 +365,7 @@ module Linguist
:name => name,
:aliases => options['aliases'],
:lexer => options['lexer'],
:group_name => options['group'],
:searchable => options.key?('searchable') ? options['searchable'] : true,
:search_term => options['search_term'],
:extensions => options['extensions'],