mirror of
https://github.com/KevinMidboe/linguist.git
synced 2025-10-29 17:50:22 +00:00
Merge branch 'master' into handlebars_color
This commit is contained in:
@@ -1,4 +1,3 @@
|
||||
sudo: false
|
||||
before_install: script/travis/before_install
|
||||
rvm:
|
||||
- 1.9.3
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
module Linguist
|
||||
VERSION = "4.4.2"
|
||||
VERSION = "4.4.3"
|
||||
end
|
||||
|
||||
4
samples/Ruby/index.json.jbuilder
Normal file
4
samples/Ruby/index.json.jbuilder
Normal 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
|
||||
@@ -5,6 +5,8 @@ set -ex
|
||||
# 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
|
||||
|
||||
sudo apt-get update
|
||||
|
||||
script/vendor-deb libicu48 libicu-dev
|
||||
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
|
||||
|
||||
50
test/test_instrumentation.rb
Normal file
50
test/test_instrumentation.rb
Normal 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
|
||||
2
vendor/grammars/NimLime
vendored
2
vendor/grammars/NimLime
vendored
Submodule vendor/grammars/NimLime updated: fac6b182e8...ae0b75d99a
2
vendor/grammars/PHP-Twig.tmbundle
vendored
2
vendor/grammars/PHP-Twig.tmbundle
vendored
Submodule vendor/grammars/PHP-Twig.tmbundle updated: ad0f5147e6...f4f7529ac2
2
vendor/grammars/SublimePapyrus
vendored
2
vendor/grammars/SublimePapyrus
vendored
Submodule vendor/grammars/SublimePapyrus updated: e1b78aacb6...6f4e954f35
2
vendor/grammars/dart-sublime-bundle
vendored
2
vendor/grammars/dart-sublime-bundle
vendored
Submodule vendor/grammars/dart-sublime-bundle updated: 21096f24d8...65c9cd9a65
2
vendor/grammars/elixir-tmbundle
vendored
2
vendor/grammars/elixir-tmbundle
vendored
Submodule vendor/grammars/elixir-tmbundle updated: 9c63ff09bd...99910870bb
2
vendor/grammars/factor
vendored
2
vendor/grammars/factor
vendored
Submodule vendor/grammars/factor updated: fe2c2d23de...e237b49f83
2
vendor/grammars/fsharpbinding
vendored
2
vendor/grammars/fsharpbinding
vendored
Submodule vendor/grammars/fsharpbinding updated: a008fe9c64...513db1c443
2
vendor/grammars/grace-tmbundle
vendored
2
vendor/grammars/grace-tmbundle
vendored
Submodule vendor/grammars/grace-tmbundle updated: 6bea212a58...2fba162ce7
2
vendor/grammars/haxe-sublime-bundle
vendored
2
vendor/grammars/haxe-sublime-bundle
vendored
Submodule vendor/grammars/haxe-sublime-bundle updated: 50c5aa0e10...84a4fab144
2
vendor/grammars/language-gfm
vendored
2
vendor/grammars/language-gfm
vendored
Submodule vendor/grammars/language-gfm updated: 5f5df3064c...6ca2ea2ac5
2
vendor/grammars/mercury-tmlanguage
vendored
2
vendor/grammars/mercury-tmlanguage
vendored
Submodule vendor/grammars/mercury-tmlanguage updated: 1cb8e94922...cb57d42dbe
2
vendor/grammars/restructuredtext.tmbundle
vendored
2
vendor/grammars/restructuredtext.tmbundle
vendored
Submodule vendor/grammars/restructuredtext.tmbundle updated: 43fc7b1ff3...608d8bcdea
Reference in New Issue
Block a user