Class: Linguist::Strategy::Modeline
- Inherits:
-
Object
- Object
- Linguist::Strategy::Modeline
- Defined in:
- lib/linguist/strategy/modeline.rb
Constant Summary collapse
- EmacsModeline =
/-\*-\s*(?:(?!mode)[\w-]+\s*:\s*(?:[\w+-]+)\s*;?\s*)*(?:mode\s*:)?\s*([\w+-]+)\s*(?:;\s*(?!mode)[\w-]+\s*:\s*[\w+-]+\s*)*;?\s*-\*-/i
- VimModeline =
/vim:\s*set.*\s(?:ft|filetype)=(\w+)\s?.*:/i
Class Method Summary collapse
-
.call(blob, _ = nil) ⇒ Object
Public: Detects language based on Vim and Emacs modelines.
-
.modeline(data) ⇒ Object
Public: Get the modeline from the first n-lines of the file.
Class Method Details
.call(blob, _ = nil) ⇒ Object
Public: Detects language based on Vim and Emacs modelines
blob - An object that quacks like a blob.
Examples
Modeline.call(FileBlob.new("path/to/file"))
Returns an Array with one Language if the blob has a Vim or Emacs modeline that matches a Language name or alias. Returns an empty array if no match.
17 18 19 |
# File 'lib/linguist/strategy/modeline.rb', line 17 def self.call(blob, _ = nil) Array(Language.find_by_alias(modeline(blob.data))) end |
.modeline(data) ⇒ Object
Public: Get the modeline from the first n-lines of the file
Returns a String or nil
24 25 26 27 |
# File 'lib/linguist/strategy/modeline.rb', line 24 def self.modeline(data) match = data.match(EmacsModeline) || data.match(VimModeline) match[1] if match end |