mirror of
https://github.com/KevinMidboe/linguist.git
synced 2025-10-29 17:50:22 +00:00
Add searchable flag to langauge
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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),
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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")
|
||||
<div class="highlight"><pre>Hello
|
||||
|
||||
Reference in New Issue
Block a user