github-linguist 4.2.7 → 4.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/linguist/heuristics.rb +35 -1
- data/lib/linguist/language.rb +6 -20
- data/lib/linguist/languages.json +1 -1
- data/lib/linguist/languages.yml +29 -3
- data/lib/linguist/samples.json +1238 -368
- data/lib/linguist/strategy/modeline.rb +30 -0
- data/lib/linguist/tokenizer.rb +2 -1
- data/lib/linguist/version.rb +1 -1
- metadata +3 -2
@@ -0,0 +1,30 @@
|
|
1
|
+
module Linguist
|
2
|
+
module Strategy
|
3
|
+
class Modeline
|
4
|
+
EmacsModeline = /-\*-\s*(?:mode:)?\s*(\w+);?\s*-\*-/
|
5
|
+
VimModeline = /\/\*\s*vim:\s*set\s*(?:ft|filetype)=(\w+):\s*\*\//
|
6
|
+
|
7
|
+
# Public: Detects language based on Vim and Emacs modelines
|
8
|
+
#
|
9
|
+
# blob - An object that quacks like a blob.
|
10
|
+
#
|
11
|
+
# Examples
|
12
|
+
#
|
13
|
+
# Modeline.call(FileBlob.new("path/to/file"))
|
14
|
+
#
|
15
|
+
# Returns an Array with one Language if the blob has a Vim or Emacs modeline
|
16
|
+
# that matches a Language name or alias. Returns an empty array if no match.
|
17
|
+
def self.call(blob, _ = nil)
|
18
|
+
Array(Language.find_by_alias(modeline(blob.data)))
|
19
|
+
end
|
20
|
+
|
21
|
+
# Public: Get the modeline from the first n-lines of the file
|
22
|
+
#
|
23
|
+
# Returns a String or nil
|
24
|
+
def self.modeline(data)
|
25
|
+
match = data.match(EmacsModeline) || data.match(VimModeline)
|
26
|
+
match[1] if match
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
data/lib/linguist/tokenizer.rb
CHANGED
@@ -33,7 +33,8 @@ module Linguist
|
|
33
33
|
['<!--', '-->'], # XML
|
34
34
|
['{-', '-}'], # Haskell
|
35
35
|
['(*', '*)'], # Coq
|
36
|
-
['"""', '"""']
|
36
|
+
['"""', '"""'], # Python
|
37
|
+
["'''", "'''"] # Python
|
37
38
|
]
|
38
39
|
|
39
40
|
START_SINGLE_LINE_COMMENT = Regexp.compile(SINGLE_LINE_COMMENTS.map { |c|
|
data/lib/linguist/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: github-linguist
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 4.
|
4
|
+
version: 4.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- GitHub
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-01-
|
11
|
+
date: 2015-01-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: charlock_holmes
|
@@ -163,6 +163,7 @@ files:
|
|
163
163
|
- lib/linguist/samples.rb
|
164
164
|
- lib/linguist/shebang.rb
|
165
165
|
- lib/linguist/strategy/filename.rb
|
166
|
+
- lib/linguist/strategy/modeline.rb
|
166
167
|
- lib/linguist/tokenizer.rb
|
167
168
|
- lib/linguist/vendor.yml
|
168
169
|
- lib/linguist/version.rb
|