mirror of
https://github.com/KevinMidboe/linguist.git
synced 2025-12-08 04:18:48 +00:00
Merge branch 'master' into tesch1-emacs-patch-1
This commit is contained in:
@@ -99,7 +99,7 @@ module Linguist
|
||||
elsif name.nil?
|
||||
"attachment"
|
||||
else
|
||||
"attachment; filename=#{EscapeUtils.escape_url(File.basename(name))}"
|
||||
"attachment; filename=#{EscapeUtils.escape_url(name)}"
|
||||
end
|
||||
end
|
||||
|
||||
@@ -233,7 +233,7 @@ module Linguist
|
||||
#
|
||||
# Return true or false
|
||||
def vendored?
|
||||
name =~ VendoredRegexp ? true : false
|
||||
path =~ VendoredRegexp ? true : false
|
||||
end
|
||||
|
||||
documentation_paths = YAML.load_file(File.expand_path("../documentation.yml", __FILE__))
|
||||
@@ -248,7 +248,7 @@ module Linguist
|
||||
#
|
||||
# Return true or false
|
||||
def documentation?
|
||||
name =~ DocumentationRegexp ? true : false
|
||||
path =~ DocumentationRegexp ? true : false
|
||||
end
|
||||
|
||||
# Public: Get each line of data
|
||||
@@ -316,7 +316,7 @@ module Linguist
|
||||
#
|
||||
# Return true or false
|
||||
def generated?
|
||||
@_generated ||= Generated.generated?(name, lambda { data })
|
||||
@_generated ||= Generated.generated?(path, lambda { data })
|
||||
end
|
||||
|
||||
# Public: Detects the Language of the blob.
|
||||
|
||||
@@ -3,7 +3,7 @@ require 'linguist/blob_helper'
|
||||
module Linguist
|
||||
# A FileBlob is a wrapper around a File object to make it quack
|
||||
# like a Grit::Blob. It provides the basic interface: `name`,
|
||||
# `data`, and `size`.
|
||||
# `data`, `path` and `size`.
|
||||
class FileBlob
|
||||
include BlobHelper
|
||||
|
||||
@@ -14,43 +14,50 @@ module Linguist
|
||||
#
|
||||
# Returns a FileBlob.
|
||||
def initialize(path, base_path = nil)
|
||||
@path = path
|
||||
@name = base_path ? path.sub("#{base_path}/", '') : path
|
||||
@fullpath = path
|
||||
@path = base_path ? path.sub("#{base_path}/", '') : path
|
||||
end
|
||||
|
||||
# Public: Filename
|
||||
#
|
||||
# Examples
|
||||
#
|
||||
# FileBlob.new("/path/to/linguist/lib/linguist.rb").name
|
||||
# FileBlob.new("/path/to/linguist/lib/linguist.rb").path
|
||||
# # => "/path/to/linguist/lib/linguist.rb"
|
||||
#
|
||||
# FileBlob.new("/path/to/linguist/lib/linguist.rb",
|
||||
# "/path/to/linguist").name
|
||||
# "/path/to/linguist").path
|
||||
# # => "lib/linguist.rb"
|
||||
#
|
||||
# Returns a String
|
||||
attr_reader :name
|
||||
attr_reader :path
|
||||
|
||||
# Public: Read file permissions
|
||||
#
|
||||
# Returns a String like '100644'
|
||||
def mode
|
||||
File.stat(@path).mode.to_s(8)
|
||||
File.stat(@fullpath).mode.to_s(8)
|
||||
end
|
||||
|
||||
# Public: File name
|
||||
#
|
||||
# Returns a String
|
||||
def name
|
||||
File.basename(@fullpath)
|
||||
end
|
||||
|
||||
# Public: Read file contents.
|
||||
#
|
||||
# Returns a String.
|
||||
def data
|
||||
File.read(@path)
|
||||
File.read(@fullpath)
|
||||
end
|
||||
|
||||
# Public: Get byte size
|
||||
#
|
||||
# Returns an Integer.
|
||||
def size
|
||||
File.size(@path)
|
||||
File.size(@fullpath)
|
||||
end
|
||||
|
||||
# Public: Get file extension.
|
||||
@@ -67,7 +74,7 @@ module Linguist
|
||||
#
|
||||
# Returns an Array
|
||||
def extensions
|
||||
basename, *segments = File.basename(name).downcase.split(".")
|
||||
basename, *segments = name.downcase.split(".")
|
||||
|
||||
segments.map.with_index do |segment, index|
|
||||
"." + segments[index..-1].join(".")
|
||||
|
||||
@@ -58,10 +58,12 @@ module Linguist
|
||||
godeps? ||
|
||||
generated_by_zephir? ||
|
||||
minified_files? ||
|
||||
source_map? ||
|
||||
compiled_coffeescript? ||
|
||||
generated_parser? ||
|
||||
generated_net_docfile? ||
|
||||
generated_postscript? ||
|
||||
compiled_cython_file? ||
|
||||
generated_protocol_buffer_go? ||
|
||||
generated_protocol_buffer? ||
|
||||
generated_jni_header? ||
|
||||
@@ -95,6 +97,20 @@ module Linguist
|
||||
end
|
||||
end
|
||||
|
||||
# Internal: Is the blob a generated source map?
|
||||
#
|
||||
# Source Maps usually have .css.map or .js.map extensions. In case they
|
||||
# are not following the name convention, detect them based on the content.
|
||||
#
|
||||
# Returns true or false.
|
||||
def source_map?
|
||||
return false unless extname.downcase == '.map'
|
||||
|
||||
name =~ /(\.css|\.js)\.map$/i || # Name convention
|
||||
lines[0] =~ /^{"version":\d+,/ || # Revision 2 and later begin with the version number
|
||||
lines[0] =~ /^\/\*\* Begin line maps\. \*\*\/{/ # Revision 1 begins with a magic comment
|
||||
end
|
||||
|
||||
# Internal: Is the blob of JS generated by CoffeeScript?
|
||||
#
|
||||
# CoffeeScript is meant to output JS that would be difficult to
|
||||
@@ -270,5 +286,18 @@ module Linguist
|
||||
# VCR Cassettes have "recorded_with: VCR" in the second last line.
|
||||
return lines[-2].include?("recorded_with: VCR")
|
||||
end
|
||||
|
||||
# Internal: Is this a compiled C/C++ file from Cython?
|
||||
#
|
||||
# Cython-compiled C/C++ files typically contain:
|
||||
# /* Generated by Cython x.x.x on ... */
|
||||
# on the first line.
|
||||
#
|
||||
# Return true or false
|
||||
def compiled_cython_file?
|
||||
return false unless ['.c', '.cpp'].include? extname
|
||||
return false unless lines.count > 1
|
||||
return lines[0].include?("Generated by Cython")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -164,7 +164,7 @@ module Linguist
|
||||
end
|
||||
end
|
||||
|
||||
disambiguate "FORTRAN", "Forth" do |data|
|
||||
disambiguate "FORTRAN", "Forth", "Formatted" do |data|
|
||||
if /^: /.match(data)
|
||||
Language["Forth"]
|
||||
elsif /^([c*][^a-z]| (subroutine|program)\s|\s*!)/i.match(data)
|
||||
@@ -261,5 +261,22 @@ module Linguist
|
||||
Language["Makefile"]
|
||||
end
|
||||
end
|
||||
|
||||
disambiguate "OCaml", "Standard ML" do |data|
|
||||
if /module|let rec |match\s+(\S+\s)+with/.match(data)
|
||||
Language["OCaml"]
|
||||
elsif /=> |case\s+(\S+\s)+of/.match(data)
|
||||
Language["Standard ML"]
|
||||
end
|
||||
end
|
||||
|
||||
disambiguate "NL", "NewLisp" do |data|
|
||||
if /^g3 /.match(data)
|
||||
Language["NL"]
|
||||
else
|
||||
Language["NewLisp"]
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
@@ -18,6 +18,8 @@
|
||||
# language. This should match one of the scopes listed in
|
||||
# the grammars.yml file. Use "none" if there is no grammar
|
||||
# for this language.
|
||||
# group - Name of the parent language. Languages in a group are counted
|
||||
# in the statistics as the parent language.
|
||||
#
|
||||
# Any additions or modifications (even trivial) should have corresponding
|
||||
# test change in `test/test_blob.rb`.
|
||||
@@ -148,7 +150,6 @@ ApacheConf:
|
||||
- apache
|
||||
extensions:
|
||||
- .apacheconf
|
||||
- .conf
|
||||
tm_scope: source.apache-config
|
||||
ace_mode: apache_conf
|
||||
|
||||
@@ -514,6 +515,7 @@ Clojure:
|
||||
color: "#db5855"
|
||||
extensions:
|
||||
- .clj
|
||||
- .boot
|
||||
- .cl2
|
||||
- .cljc
|
||||
- .cljs
|
||||
@@ -709,6 +711,8 @@ DM:
|
||||
|
||||
DTrace:
|
||||
type: programming
|
||||
aliases:
|
||||
- dtrace-script
|
||||
extensions:
|
||||
- .d
|
||||
interpreters:
|
||||
@@ -717,7 +721,7 @@ DTrace:
|
||||
ace_mode: c_cpp
|
||||
|
||||
Darcs Patch:
|
||||
type: programming
|
||||
type: data
|
||||
search_term: dpatch
|
||||
aliases:
|
||||
- dpatch
|
||||
@@ -735,12 +739,14 @@ Dart:
|
||||
ace_mode: dart
|
||||
|
||||
Diff:
|
||||
type: programming
|
||||
type: data
|
||||
color: "#88dddd"
|
||||
extensions:
|
||||
- .diff
|
||||
- .patch
|
||||
aliases:
|
||||
- udiff
|
||||
tm_scope: source.diff
|
||||
ace_mode: diff
|
||||
|
||||
Dockerfile:
|
||||
@@ -929,6 +935,13 @@ Fantom:
|
||||
tm_scope: source.fan
|
||||
ace_mode: text
|
||||
|
||||
Formatted:
|
||||
type: data
|
||||
extensions:
|
||||
- .for
|
||||
tm_scope: none
|
||||
ace_mode: text
|
||||
|
||||
Forth:
|
||||
type: programming
|
||||
color: "#341708"
|
||||
@@ -1147,7 +1160,7 @@ Graphviz (DOT):
|
||||
ace_mode: text
|
||||
|
||||
Groff:
|
||||
type: programming
|
||||
type: markup
|
||||
extensions:
|
||||
- .man
|
||||
- '.1'
|
||||
@@ -1257,6 +1270,7 @@ Haml:
|
||||
|
||||
Handlebars:
|
||||
type: markup
|
||||
color: "#01a9d6"
|
||||
aliases:
|
||||
- hbs
|
||||
- htmlbars
|
||||
@@ -2201,7 +2215,7 @@ PHP:
|
||||
aliases:
|
||||
- inc
|
||||
|
||||
#Oracle
|
||||
#Oracle
|
||||
PLSQL:
|
||||
type: programming
|
||||
ace_mode: sql
|
||||
@@ -2211,9 +2225,10 @@ PLSQL:
|
||||
- .pkb
|
||||
- .pks
|
||||
- .plb
|
||||
- .plsql
|
||||
- .sql
|
||||
|
||||
#Postgres
|
||||
#Postgres
|
||||
PLpgSQL:
|
||||
type: programming
|
||||
ace_mode: pgsql
|
||||
@@ -2282,6 +2297,7 @@ Pascal:
|
||||
|
||||
Perl:
|
||||
type: programming
|
||||
tm_scope: source.perl
|
||||
ace_mode: perl
|
||||
color: "#0298c3"
|
||||
extensions:
|
||||
@@ -2317,7 +2333,7 @@ Perl6:
|
||||
- Rexfile
|
||||
interpreters:
|
||||
- perl6
|
||||
tm_scope: none
|
||||
tm_scope: source.perl.6
|
||||
ace_mode: perl
|
||||
|
||||
PigLatin:
|
||||
@@ -2614,6 +2630,7 @@ Rebol:
|
||||
- .r3
|
||||
- .rebol
|
||||
ace_mode: text
|
||||
tm_scope: source.rebol
|
||||
|
||||
Red:
|
||||
type: programming
|
||||
@@ -2623,7 +2640,7 @@ Red:
|
||||
- .reds
|
||||
aliases:
|
||||
- red/system
|
||||
tm_scope: none
|
||||
tm_scope: source.red
|
||||
ace_mode: text
|
||||
|
||||
Redcode:
|
||||
@@ -3192,12 +3209,15 @@ VimL:
|
||||
search_term: vim
|
||||
aliases:
|
||||
- vim
|
||||
- nvim
|
||||
extensions:
|
||||
- .vim
|
||||
filenames:
|
||||
- .nvimrc
|
||||
- .vimrc
|
||||
- _vimrc
|
||||
- gvimrc
|
||||
- nvimrc
|
||||
- vimrc
|
||||
ace_mode: text
|
||||
|
||||
|
||||
@@ -14,13 +14,15 @@ module Linguist
|
||||
|
||||
attr_reader :repository
|
||||
attr_reader :oid
|
||||
attr_reader :name
|
||||
attr_reader :path
|
||||
attr_reader :mode
|
||||
|
||||
def initialize(repo, oid, name, mode = nil)
|
||||
alias :name :path
|
||||
|
||||
def initialize(repo, oid, path, mode = nil)
|
||||
@repository = repo
|
||||
@oid = oid
|
||||
@name = name
|
||||
@path = path
|
||||
@mode = mode
|
||||
end
|
||||
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
module Linguist
|
||||
VERSION = "4.4.3"
|
||||
VERSION = "4.5.2"
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user