Merge branch 'master' into handlebars_color

This commit is contained in:
Mark Tareshawty
2015-03-09 10:04:51 -04:00
21 changed files with 114 additions and 35 deletions

View File

@@ -6,3 +6,15 @@ require 'linguist/repository'
require 'linguist/samples'
require 'linguist/shebang'
require 'linguist/version'
class << Linguist
attr_accessor :instrumenter
def instrument(*args, &bk)
if instrumenter
instrumenter.instrument(*args, &bk)
else
yield if block_given?
end
end
end

View File

@@ -105,19 +105,31 @@ module Linguist
# Bail early if the blob is binary or empty.
return nil if blob.likely_binary? || blob.binary? || blob.empty?
# Call each strategy until one candidate is returned.
STRATEGIES.reduce([]) do |languages, strategy|
candidates = strategy.call(blob, languages)
if candidates.size == 1
return candidates.first
elsif candidates.size > 1
# More than one candidate was found, pass them to the next strategy.
candidates
else
# No candiates were found, pass on languages from the previous strategy.
languages
Linguist.instrument("linguist.detection", :blob => blob) do
# Call each strategy until one candidate is returned.
languages = []
returning_strategy = nil
STRATEGIES.each do |strategy|
returning_strategy = strategy
candidates = Linguist.instrument("linguist.strategy", :blob => blob, :strategy => strategy, :candidates => languages) do
strategy.call(blob, languages)
end
if candidates.size == 1
languages = candidates
break
elsif candidates.size > 1
# More than one candidate was found, pass them to the next strategy.
languages = candidates
else
# No candidates, try the next strategy
end
end
end.first
Linguist.instrument("linguist.detected", :blob => blob, :strategy => returning_strategy, :language => languages.first)
languages.first
end
end
# Public: Get all Languages

View File

@@ -356,7 +356,7 @@ Bro:
C:
type: programming
color: "#555"
color: "#555555"
extensions:
- .c
- .cats
@@ -994,7 +994,6 @@ GDScript:
ace_mode: text
GLSL:
group: C
type: programming
extensions:
- .glsl
@@ -1048,7 +1047,7 @@ Gentoo Eclass:
ace_mode: sh
Gettext Catalog:
type: programming
type: prose
search_term: pot
searchable: false
aliases:
@@ -2668,6 +2667,7 @@ Ruby:
- .gemspec
- .god
- .irbrc
- .jbuilder
- .mspec
- .pluginspec
- .podspec

View File

@@ -9,21 +9,21 @@
- CSS
- Clojure
- CoffeeScript
- Common Lisp
- Diff
- Emacs Lisp
- Erlang
- Go
- HTML
- Haskell
- Java
- JavaScript
- Lua
- Matlab
- Objective-C
- PHP
- Perl
- Python
- R
- Ruby
- SQL
- Scala
- Scheme
- Shell
- Swift
- TeX
- VimL

View File

@@ -1,3 +1,3 @@
module Linguist
VERSION = "4.4.2"
VERSION = "4.4.3"
end