mirror of
https://github.com/KevinMidboe/linguist.git
synced 2026-01-10 11:25:32 +00:00
Add searchable flag to langauge
This commit is contained in:
@@ -223,17 +223,17 @@ module Linguist
|
|||||||
# Excluded:
|
# Excluded:
|
||||||
# - Files over 0.1MB
|
# - Files over 0.1MB
|
||||||
# - Non-text files
|
# - Non-text files
|
||||||
|
# - Langauges marked as not searchable
|
||||||
# - Generated source files
|
# - Generated source files
|
||||||
# - .po and .sql files
|
|
||||||
#
|
#
|
||||||
# Return true or false
|
# Return true or false
|
||||||
def indexable?
|
def indexable?
|
||||||
if !text?
|
if !text?
|
||||||
false
|
false
|
||||||
elsif ['.po', '.sql'].include?(extname)
|
|
||||||
false
|
|
||||||
elsif !Language.find_by_extension(extname)
|
elsif !Language.find_by_extension(extname)
|
||||||
false
|
false
|
||||||
|
elsif !language.searchable?
|
||||||
|
false
|
||||||
elsif generated?
|
elsif generated?
|
||||||
false
|
false
|
||||||
elsif size > 100 * 1024
|
elsif size > 100 * 1024
|
||||||
|
|||||||
@@ -164,9 +164,10 @@ module Linguist
|
|||||||
# Consider using `@lexer.extensions`
|
# Consider using `@lexer.extensions`
|
||||||
@extensions = attributes[:extensions] || []
|
@extensions = attributes[:extensions] || []
|
||||||
|
|
||||||
# Set popular or common flags
|
# Set popular, common, and searchable flags
|
||||||
@popular = attributes[:popular] || false
|
@popular = attributes.key?(:popular) ? attributes[:popular] : false
|
||||||
@common = attributes[:common] || false
|
@common = attributes.key?(:common) ? attributes[:common] : false
|
||||||
|
@searchable = attributes.key?(:searchable) ? attributes[:searchable] : true
|
||||||
end
|
end
|
||||||
|
|
||||||
# Public: Get proper name
|
# Public: Get proper name
|
||||||
@@ -243,6 +244,16 @@ module Linguist
|
|||||||
@common
|
@common
|
||||||
end
|
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
|
# Public: Highlight syntax of text
|
||||||
#
|
#
|
||||||
# text - String of code to be highlighted
|
# text - String of code to be highlighted
|
||||||
@@ -288,6 +299,7 @@ module Linguist
|
|||||||
:name => name,
|
:name => name,
|
||||||
:aliases => options[:aliases],
|
:aliases => options[:aliases],
|
||||||
:lexer => options[:lexer],
|
:lexer => options[:lexer],
|
||||||
|
:searchable => options.key?(:searchable) ? options[:searchable] : true,
|
||||||
:search_term => options[:search_term],
|
:search_term => options[:search_term],
|
||||||
:extensions => options[:ext],
|
:extensions => options[:ext],
|
||||||
:popular => popular.include?(name),
|
:popular => popular.include?(name),
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
# aliases - An Array of additional aliases (implicitly
|
# aliases - An Array of additional aliases (implicitly
|
||||||
# includes name.downcase)
|
# includes name.downcase)
|
||||||
# ext - An Array of associated extensions
|
# ext - An Array of associated extensions
|
||||||
|
# searchable - Boolean flag to enable searching (defaults to true)
|
||||||
# search_term - Deprecated: Some langauges maybe indexed under a
|
# search_term - Deprecated: Some langauges maybe indexed under a
|
||||||
# different alias. Avoid defining new exceptions.
|
# different alias. Avoid defining new exceptions.
|
||||||
|
|
||||||
@@ -204,6 +205,7 @@ Gentoo Eclass:
|
|||||||
- .eclass
|
- .eclass
|
||||||
Gettext Catalog:
|
Gettext Catalog:
|
||||||
:search_term: pot
|
:search_term: pot
|
||||||
|
:searchable: false
|
||||||
:aliases:
|
:aliases:
|
||||||
- pot
|
- pot
|
||||||
:ext:
|
:ext:
|
||||||
@@ -457,6 +459,7 @@ Ruby:
|
|||||||
- .thor
|
- .thor
|
||||||
- Gemfile
|
- Gemfile
|
||||||
SQL:
|
SQL:
|
||||||
|
:searchable: false
|
||||||
:ext:
|
:ext:
|
||||||
- .sql
|
- .sql
|
||||||
Sass:
|
Sass:
|
||||||
|
|||||||
@@ -320,6 +320,12 @@ class TestLanguage < Test::Unit::TestCase
|
|||||||
assert !Language['Makefile'].common?
|
assert !Language['Makefile'].common?
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_searchable
|
||||||
|
assert Language['Ruby'].searchable?
|
||||||
|
assert !Language['Gettext Catalog'].searchable?
|
||||||
|
assert !Language['SQL'].searchable?
|
||||||
|
end
|
||||||
|
|
||||||
def test_colorize
|
def test_colorize
|
||||||
assert_equal <<-HTML, Language['Text'].colorize("Hello")
|
assert_equal <<-HTML, Language['Text'].colorize("Hello")
|
||||||
<div class="highlight"><pre>Hello
|
<div class="highlight"><pre>Hello
|
||||||
|
|||||||
Reference in New Issue
Block a user