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

@@ -1,4 +1,3 @@
sudo: false
before_install: script/travis/before_install before_install: script/travis/before_install
rvm: rvm:
- 1.9.3 - 1.9.3

View File

@@ -6,3 +6,15 @@ require 'linguist/repository'
require 'linguist/samples' require 'linguist/samples'
require 'linguist/shebang' require 'linguist/shebang'
require 'linguist/version' 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. # Bail early if the blob is binary or empty.
return nil if blob.likely_binary? || blob.binary? || blob.empty? return nil if blob.likely_binary? || blob.binary? || blob.empty?
Linguist.instrument("linguist.detection", :blob => blob) do
# Call each strategy until one candidate is returned. # Call each strategy until one candidate is returned.
STRATEGIES.reduce([]) do |languages, strategy| languages = []
candidates = strategy.call(blob, 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 if candidates.size == 1
return candidates.first languages = candidates
break
elsif candidates.size > 1 elsif candidates.size > 1
# More than one candidate was found, pass them to the next strategy. # More than one candidate was found, pass them to the next strategy.
candidates languages = candidates
else else
# No candiates were found, pass on languages from the previous strategy. # No candidates, try the next strategy
languages end
end
Linguist.instrument("linguist.detected", :blob => blob, :strategy => returning_strategy, :language => languages.first)
languages.first
end end
end.first
end end
# Public: Get all Languages # Public: Get all Languages

View File

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

View File

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

View File

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

View File

@@ -0,0 +1,4 @@
json.array!(@courts) do |court|
json.extract! court, :id, :name_r, :region, :region_r, :email, :website
json.url court_url(court, format: :json)
end

View File

@@ -5,6 +5,8 @@ set -ex
# Fetch all commits/refs needed to run our tests. # Fetch all commits/refs needed to run our tests.
git fetch origin master:master v2.0.0:v2.0.0 test/attributes:test/attributes test/master:test/master git fetch origin master:master v2.0.0:v2.0.0 test/attributes:test/attributes test/master:test/master
sudo apt-get update
script/vendor-deb libicu48 libicu-dev script/vendor-deb libicu48 libicu-dev
if ruby -e 'exit RUBY_VERSION >= "2.0" && RUBY_VERSION < "2.1"'; then if ruby -e 'exit RUBY_VERSION >= "2.0" && RUBY_VERSION < "2.1"'; then
# Workaround for https://bugs.ruby-lang.org/issues/8074. We can't use this # Workaround for https://bugs.ruby-lang.org/issues/8074. We can't use this

View File

@@ -0,0 +1,50 @@
require_relative "./helper"
class TestInstrumentation < Minitest::Test
include Linguist
class LocalInstrumenter
Event = Struct.new(:name, :args)
attr_reader :events
def initialize
@events = []
end
def instrument(name, *args)
@events << Event.new(name, args)
yield if block_given?
end
end
def setup
Linguist.instrumenter = LocalInstrumenter.new
end
def teardown
Linguist.instrumenter = nil
end
def test_detection_instrumentation_with_binary_blob
binary_blob = fixture_blob("Binary/octocat.ai")
Language.detect(binary_blob)
# Shouldn't instrument this (as it's binary)
assert_equal 0, Linguist.instrumenter.events.size
end
def test_modeline_instrumentation
blob = fixture_blob("Data/Modelines/ruby")
Language.detect(blob)
detect_event = Linguist.instrumenter.events.last
detect_event_payload = detect_event[:args].first
assert_equal 3, Linguist.instrumenter.events.size
assert_equal "linguist.detected", detect_event.name
assert_equal Language['Ruby'], detect_event_payload[:language]
assert_equal blob, detect_event_payload[:blob]
assert_equal Linguist::Strategy::Modeline, detect_event_payload[:strategy]
end
end