mirror of
https://github.com/KevinMidboe/linguist.git
synced 2025-10-29 17:50:22 +00:00
hwhoops
This commit is contained in:
@@ -53,7 +53,7 @@ module Linguist
|
||||
#
|
||||
# Returns a content type String.
|
||||
def content_type
|
||||
@content_type ||= binary? ? mime_type :
|
||||
@content_type ||= (binary_mime_type? || binary?) ? mime_type :
|
||||
(encoding ? "text/plain; charset=#{encoding.downcase}" : "text/plain")
|
||||
end
|
||||
|
||||
@@ -423,8 +423,15 @@ module Linguist
|
||||
def guess_cls_language
|
||||
if lines.grep(/^(%|\\)/).any?
|
||||
Language['TeX']
|
||||
else
|
||||
elsif lines.grep(/^\s*(CLASS|METHOD|INTERFACE).*:\s*/i).any? || lines.grep(/^\s*(USING|DEFINE)/i).any?
|
||||
Language['OpenEdge ABL']
|
||||
elsif lines.grep(/\{$/).any? || lines.grep(/\}$/).any?
|
||||
Language['Apex']
|
||||
elsif lines.grep(/^(\'\*|Attribute|Option|Sub|Private|Protected|Public|Friend)/i).any?
|
||||
Language['Visual Basic']
|
||||
else
|
||||
# The most common language should be the fallback
|
||||
Language['TeX']
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
require 'yaml'
|
||||
require 'escape_utils'
|
||||
require 'pygments'
|
||||
require 'yaml'
|
||||
|
||||
module Linguist
|
||||
# Language names that are recognizable by GitHub. Defined languages
|
||||
@@ -193,6 +194,13 @@ module Linguist
|
||||
@unpopular ||= all.select(&:unpopular?).sort_by { |lang| lang.name.downcase }
|
||||
end
|
||||
|
||||
# Public: A List of languages compatible with Ace.
|
||||
#
|
||||
# Returns an Array of Languages.
|
||||
def self.ace_modes
|
||||
@ace_modes ||= all.select(&:ace_mode).sort_by { |lang| lang.name.downcase }
|
||||
end
|
||||
|
||||
# Internal: Initialize a new Language
|
||||
#
|
||||
# attributes - A hash of attributes
|
||||
@@ -213,6 +221,8 @@ module Linguist
|
||||
@lexer = Pygments::Lexer.find_by_name(attributes[:lexer] || name) ||
|
||||
raise(ArgumentError, "#{@name} is missing lexer")
|
||||
|
||||
@ace_mode = attributes[:ace_mode]
|
||||
|
||||
# Set legacy search term
|
||||
@search_term = attributes[:search_term] || default_alias_name
|
||||
|
||||
@@ -285,6 +295,17 @@ module Linguist
|
||||
# Returns the Lexer
|
||||
attr_reader :lexer
|
||||
|
||||
# Public: Get Ace mode
|
||||
#
|
||||
# Examples
|
||||
#
|
||||
# # => "text"
|
||||
# # => "javascript"
|
||||
# # => "c_cpp"
|
||||
#
|
||||
# Returns a String name or nil
|
||||
attr_reader :ace_mode
|
||||
|
||||
# Public: Get extensions
|
||||
#
|
||||
# Examples
|
||||
@@ -322,6 +343,19 @@ module Linguist
|
||||
# Returns the extensions Array
|
||||
attr_reader :filenames
|
||||
|
||||
# Public: Get URL escaped name.
|
||||
#
|
||||
# Examples
|
||||
#
|
||||
# "C%23"
|
||||
# "C%2B%2B"
|
||||
# "Common%20Lisp"
|
||||
#
|
||||
# Returns the escaped String.
|
||||
def escaped_name
|
||||
EscapeUtils.escape_url(name).gsub('+', '%20')
|
||||
end
|
||||
|
||||
# Internal: Get default alias name
|
||||
#
|
||||
# Returns the alias name String
|
||||
@@ -403,6 +437,7 @@ module Linguist
|
||||
:type => options['type'],
|
||||
:aliases => options['aliases'],
|
||||
:lexer => options['lexer'],
|
||||
:ace_mode => options['ace_mode'],
|
||||
:group_name => options['group'],
|
||||
:searchable => options.key?('searchable') ? options['searchable'] : true,
|
||||
:search_term => options['search_term'],
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
# lexer - An explicit lexer String (defaults to name.downcase)
|
||||
# aliases - An Array of additional aliases (implicitly
|
||||
# includes name.downcase)
|
||||
# ace_mode - A String name of Ace Mode (if available)
|
||||
# extension - An Array of associated extensions
|
||||
# primary_extension - A String for the main extension associated with
|
||||
# the langauge. (defaults to extensions.first)
|
||||
@@ -54,6 +55,12 @@ Ada:
|
||||
- .adb
|
||||
- .ads
|
||||
|
||||
Apex:
|
||||
type: programming
|
||||
lexer: Text only
|
||||
extensions:
|
||||
- .cls
|
||||
|
||||
AppleScript:
|
||||
aliases:
|
||||
- osascript
|
||||
@@ -137,6 +144,7 @@ C:
|
||||
|
||||
C#:
|
||||
type: programming
|
||||
ace_mode: csharp
|
||||
search_term: csharp
|
||||
aliases:
|
||||
- csharp
|
||||
@@ -145,6 +153,7 @@ C#:
|
||||
|
||||
C++:
|
||||
type: programming
|
||||
ace_mode: c_cpp
|
||||
search_term: cpp
|
||||
aliases:
|
||||
- cpp
|
||||
@@ -185,6 +194,7 @@ CMake:
|
||||
- CMakeLists.txt
|
||||
|
||||
CSS:
|
||||
ace_mode: css
|
||||
extensions:
|
||||
- .css
|
||||
|
||||
@@ -195,6 +205,7 @@ ChucK:
|
||||
|
||||
Clojure:
|
||||
type: programming
|
||||
ace_mode: clojure
|
||||
primary_extension: .clj
|
||||
extensions:
|
||||
- .clj
|
||||
@@ -202,6 +213,7 @@ Clojure:
|
||||
|
||||
CoffeeScript:
|
||||
type: programming
|
||||
ace_mode: coffee
|
||||
aliases:
|
||||
- coffee
|
||||
extensions:
|
||||
@@ -212,6 +224,7 @@ CoffeeScript:
|
||||
ColdFusion:
|
||||
type: programming
|
||||
lexer: Coldfusion HTML
|
||||
ace_mode: coldfusion
|
||||
search_term: cfm
|
||||
aliases:
|
||||
- cfm
|
||||
@@ -227,6 +240,7 @@ Common Lisp:
|
||||
primary_extension: .lisp
|
||||
extensions:
|
||||
- .lisp
|
||||
- .lsp
|
||||
- .ny
|
||||
|
||||
Coq:
|
||||
@@ -295,6 +309,13 @@ Dylan:
|
||||
extensions:
|
||||
- .dylan
|
||||
|
||||
Ecere Projects:
|
||||
type: data
|
||||
group: JavaScript
|
||||
lexer: JSON
|
||||
extensions:
|
||||
- .epj
|
||||
|
||||
Eiffel:
|
||||
type: programming
|
||||
lexer: Text only
|
||||
@@ -328,7 +349,7 @@ Erlang:
|
||||
|
||||
F#:
|
||||
type: programming
|
||||
lexer: OCaml
|
||||
lexer: FSharp
|
||||
search_term: ocaml
|
||||
extensions:
|
||||
- .fs
|
||||
@@ -371,7 +392,6 @@ Fancy:
|
||||
|
||||
Fantom:
|
||||
type: programming
|
||||
lexer: Java
|
||||
extensions:
|
||||
- .fan
|
||||
|
||||
@@ -437,7 +457,7 @@ Groff:
|
||||
|
||||
Groovy:
|
||||
type: programming
|
||||
lexer: Java
|
||||
ace_mode: groovy
|
||||
primary_extension: .groovy
|
||||
extensions:
|
||||
- .gradle
|
||||
@@ -455,6 +475,7 @@ Groovy Server Pages:
|
||||
|
||||
HTML:
|
||||
type: markup
|
||||
ace_mode: html
|
||||
primary_extension: .html
|
||||
extensions:
|
||||
- .htm
|
||||
@@ -487,6 +508,7 @@ HTML+PHP:
|
||||
HaXe:
|
||||
type: programming
|
||||
lexer: haXe
|
||||
ace_mode: haxe
|
||||
extensions:
|
||||
- .hx
|
||||
- .hxml
|
||||
@@ -535,13 +557,14 @@ Ioke:
|
||||
JSON:
|
||||
type: data
|
||||
group: JavaScript
|
||||
lexer: JavaScript
|
||||
ace_mode: json
|
||||
searchable: false
|
||||
extensions:
|
||||
- .json
|
||||
|
||||
Java:
|
||||
type: programming
|
||||
ace_mode: java
|
||||
extensions:
|
||||
- .java
|
||||
- .pde
|
||||
@@ -557,6 +580,7 @@ Java Server Pages:
|
||||
|
||||
JavaScript:
|
||||
type: programming
|
||||
ace_mode: javascript
|
||||
aliases:
|
||||
- js
|
||||
- node
|
||||
@@ -565,6 +589,7 @@ JavaScript:
|
||||
- .bones
|
||||
- .jake
|
||||
- .js
|
||||
- .jsfl
|
||||
- .jsm
|
||||
- .jss
|
||||
- .jsx
|
||||
@@ -574,6 +599,14 @@ JavaScript:
|
||||
filenames:
|
||||
- Jakefile
|
||||
|
||||
Kotlin:
|
||||
type: programming
|
||||
lexer: Kotlin
|
||||
extensions:
|
||||
- .kt
|
||||
- .ktm
|
||||
- .kts
|
||||
|
||||
LLVM:
|
||||
extensions:
|
||||
- .ll
|
||||
@@ -602,6 +635,7 @@ Logtalk:
|
||||
|
||||
Lua:
|
||||
type: programming
|
||||
ace_mode: lua
|
||||
primary_extension: .lua
|
||||
extensions:
|
||||
- .lua
|
||||
@@ -624,6 +658,7 @@ Mako:
|
||||
Markdown:
|
||||
type: markup
|
||||
lexer: Text only
|
||||
ace_mode: markdown
|
||||
primary_extension: .md
|
||||
extensions:
|
||||
- .markdown
|
||||
@@ -698,6 +733,7 @@ NumPy:
|
||||
|
||||
OCaml:
|
||||
type: programming
|
||||
ace_mode: ocaml
|
||||
primary_extension: .ml
|
||||
extensions:
|
||||
- .ml
|
||||
@@ -729,7 +765,6 @@ Objective-J:
|
||||
|
||||
Opa:
|
||||
type: programming
|
||||
lexer: Text only
|
||||
extensions:
|
||||
- .opa
|
||||
|
||||
@@ -747,14 +782,13 @@ OpenEdge ABL:
|
||||
- openedge
|
||||
- abl
|
||||
primary_extension: .p
|
||||
overrides:
|
||||
- .cls
|
||||
extensions:
|
||||
- .cls
|
||||
- .p
|
||||
|
||||
PHP:
|
||||
type: programming
|
||||
ace_mode: php
|
||||
extensions:
|
||||
- .aw
|
||||
- .ctp
|
||||
@@ -763,6 +797,8 @@ PHP:
|
||||
- .php4
|
||||
- .php5
|
||||
- .phpt
|
||||
filenames:
|
||||
- Phakefile
|
||||
|
||||
Parrot:
|
||||
type: programming
|
||||
@@ -789,6 +825,7 @@ Parrot Assembly:
|
||||
|
||||
Perl:
|
||||
type: programming
|
||||
ace_mode: perl
|
||||
overrides:
|
||||
- .pl
|
||||
- .t
|
||||
@@ -804,9 +841,9 @@ Perl:
|
||||
- .psgi
|
||||
- .t
|
||||
|
||||
Powershell:
|
||||
PowerShell:
|
||||
type: programming
|
||||
lexer: Text only
|
||||
ace_mode: powershell
|
||||
aliases:
|
||||
- posh
|
||||
extensions:
|
||||
@@ -825,6 +862,8 @@ Puppet:
|
||||
lexer: Text only
|
||||
extensions:
|
||||
- .pp
|
||||
filenames:
|
||||
- Modulefile
|
||||
|
||||
Pure Data:
|
||||
type: programming
|
||||
@@ -834,6 +873,7 @@ Pure Data:
|
||||
|
||||
Python:
|
||||
type: programming
|
||||
ace_mode: python
|
||||
primary_extension: .py
|
||||
extensions:
|
||||
- .py
|
||||
@@ -897,6 +937,7 @@ Redcode:
|
||||
|
||||
Ruby:
|
||||
type: programming
|
||||
ace_mode: ruby
|
||||
aliases:
|
||||
- jruby
|
||||
- macruby
|
||||
@@ -937,11 +978,13 @@ Rust:
|
||||
SCSS:
|
||||
type: markup
|
||||
group: CSS
|
||||
ace_mode: scss
|
||||
extensions:
|
||||
- .scss
|
||||
|
||||
SQL:
|
||||
type: data
|
||||
ace_mode: sql
|
||||
searchable: false
|
||||
extensions:
|
||||
- .sql
|
||||
@@ -962,6 +1005,7 @@ Sass:
|
||||
|
||||
Scala:
|
||||
type: programming
|
||||
ace_mode: scala
|
||||
primary_extension: .scala
|
||||
extensions:
|
||||
- .sbt
|
||||
@@ -1052,7 +1096,10 @@ Tcsh:
|
||||
|
||||
TeX:
|
||||
type: markup
|
||||
ace_mode: latex
|
||||
primary_extension: .tex
|
||||
overrides:
|
||||
- .cls
|
||||
extensions:
|
||||
- .aux
|
||||
- .cls
|
||||
@@ -1063,15 +1110,23 @@ TeX:
|
||||
- .tex
|
||||
- .toc
|
||||
|
||||
Tea:
|
||||
type: markup
|
||||
lexer: Tea
|
||||
extensions:
|
||||
- .tea
|
||||
|
||||
Text:
|
||||
type: data
|
||||
lexer: Text only
|
||||
ace_mode: text
|
||||
extensions:
|
||||
- .txt
|
||||
|
||||
Textile:
|
||||
type: markup
|
||||
lexer: Text only
|
||||
ace_mode: textile
|
||||
extensions:
|
||||
- .textile
|
||||
|
||||
@@ -1092,7 +1147,7 @@ Twig:
|
||||
|
||||
VHDL:
|
||||
type: programming
|
||||
lexer: Text only
|
||||
lexer: vhdl
|
||||
primary_extension: .vhd
|
||||
extensions:
|
||||
- .vhd
|
||||
@@ -1138,6 +1193,7 @@ Visual Basic:
|
||||
|
||||
XML:
|
||||
type: markup
|
||||
ace_mode: xml
|
||||
primary_extension: .xml
|
||||
extensions:
|
||||
- .glade
|
||||
@@ -1184,6 +1240,14 @@ YAML:
|
||||
filenames:
|
||||
- .gemrc
|
||||
|
||||
eC:
|
||||
type: programming
|
||||
search_term: ec
|
||||
primary_extension: .ec
|
||||
extensions:
|
||||
- .ec
|
||||
- .eh
|
||||
|
||||
mupad:
|
||||
lexer: MuPAD
|
||||
extensions:
|
||||
|
||||
@@ -1,6 +1,10 @@
|
||||
require 'mime/types'
|
||||
require 'yaml'
|
||||
|
||||
class MIME::Type
|
||||
attr_accessor :override
|
||||
end
|
||||
|
||||
# Register additional mime type extensions
|
||||
#
|
||||
# Follows same format as mime-types data file
|
||||
@@ -33,6 +37,8 @@ File.read(File.expand_path("../mimes.yml", __FILE__)).lines.each do |line|
|
||||
mime_type.encoding = encoding
|
||||
end
|
||||
|
||||
mime_type.override = true
|
||||
|
||||
# Kind of hacky, but we need to reindex the mime type after making changes
|
||||
MIME::Types.add_type_variant(mime_type)
|
||||
MIME::Types.index_extensions(mime_type)
|
||||
@@ -72,8 +78,11 @@ module Linguist
|
||||
guesses = ::MIME::Types.type_for(ext_or_mime_type)
|
||||
end
|
||||
|
||||
# Prefer text mime types over binary
|
||||
guesses.detect { |type| type.ascii? } ||
|
||||
# Use custom override first
|
||||
guesses.detect { |type| type.override } ||
|
||||
|
||||
# Prefer text mime types over binary
|
||||
guesses.detect { |type| type.ascii? } ||
|
||||
|
||||
# Otherwise use the first guess
|
||||
guesses.first
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
- ^tools/
|
||||
|
||||
# Node depedencies
|
||||
- ^node_modules/
|
||||
- node_modules/
|
||||
|
||||
# Vendored depedencies
|
||||
- vendor/
|
||||
@@ -88,4 +88,9 @@
|
||||
|
||||
# NuGet
|
||||
- ^[Pp]ackages/
|
||||
|
||||
# ExtJS
|
||||
- (^|/)ext(js)?(-\d\.\d\.\d)?(-gpl)?/
|
||||
|
||||
# Samples folders
|
||||
- ^[Ss]amples/
|
||||
|
||||
Reference in New Issue
Block a user