From 9501f6bd3de36f530af0a74b2e1808479fc21c11 Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Tue, 31 May 2011 17:09:11 -0500 Subject: [PATCH] Add searchable flag to langauge --- lib/linguist/blob_helper.rb | 6 +++--- lib/linguist/language.rb | 18 +++++++++++++++--- lib/linguist/languages.yml | 3 +++ test/test_language.rb | 6 ++++++ 4 files changed, 27 insertions(+), 6 deletions(-) diff --git a/lib/linguist/blob_helper.rb b/lib/linguist/blob_helper.rb index ac6b7f8a..50337956 100644 --- a/lib/linguist/blob_helper.rb +++ b/lib/linguist/blob_helper.rb @@ -223,17 +223,17 @@ module Linguist # Excluded: # - Files over 0.1MB # - Non-text files + # - Langauges marked as not searchable # - Generated source files - # - .po and .sql files # # Return true or false def indexable? if !text? false - elsif ['.po', '.sql'].include?(extname) - false elsif !Language.find_by_extension(extname) false + elsif !language.searchable? + false elsif generated? false elsif size > 100 * 1024 diff --git a/lib/linguist/language.rb b/lib/linguist/language.rb index 906ff02a..55c2b202 100644 --- a/lib/linguist/language.rb +++ b/lib/linguist/language.rb @@ -164,9 +164,10 @@ module Linguist # Consider using `@lexer.extensions` @extensions = attributes[:extensions] || [] - # Set popular or common flags - @popular = attributes[:popular] || false - @common = attributes[:common] || false + # Set popular, common, and searchable flags + @popular = attributes.key?(:popular) ? attributes[:popular] : false + @common = attributes.key?(:common) ? attributes[:common] : false + @searchable = attributes.key?(:searchable) ? attributes[:searchable] : true end # Public: Get proper name @@ -243,6 +244,16 @@ module Linguist @common end + # Public: Is it searchable? + # + # Unsearchable languages won't by indexed by solr and won't show + # up in the code search dropdown. + # + # Returns true or false + def searchable? + @searchable + end + # Public: Highlight syntax of text # # text - String of code to be highlighted @@ -288,6 +299,7 @@ module Linguist :name => name, :aliases => options[:aliases], :lexer => options[:lexer], + :searchable => options.key?(:searchable) ? options[:searchable] : true, :search_term => options[:search_term], :extensions => options[:ext], :popular => popular.include?(name), diff --git a/lib/linguist/languages.yml b/lib/linguist/languages.yml index 7991e4b0..4f27a141 100644 --- a/lib/linguist/languages.yml +++ b/lib/linguist/languages.yml @@ -4,6 +4,7 @@ # aliases - An Array of additional aliases (implicitly # includes name.downcase) # ext - An Array of associated extensions +# searchable - Boolean flag to enable searching (defaults to true) # search_term - Deprecated: Some langauges maybe indexed under a # different alias. Avoid defining new exceptions. @@ -204,6 +205,7 @@ Gentoo Eclass: - .eclass Gettext Catalog: :search_term: pot + :searchable: false :aliases: - pot :ext: @@ -457,6 +459,7 @@ Ruby: - .thor - Gemfile SQL: + :searchable: false :ext: - .sql Sass: diff --git a/test/test_language.rb b/test/test_language.rb index 42854219..75d195d0 100644 --- a/test/test_language.rb +++ b/test/test_language.rb @@ -320,6 +320,12 @@ class TestLanguage < Test::Unit::TestCase assert !Language['Makefile'].common? end + def test_searchable + assert Language['Ruby'].searchable? + assert !Language['Gettext Catalog'].searchable? + assert !Language['SQL'].searchable? + end + def test_colorize assert_equal <<-HTML, Language['Text'].colorize("Hello")
Hello