Identify php files by first line

Fixes #32
This commit is contained in:
Rok Žlender
2011-07-05 09:43:48 -05:00
committed by Joshua Peek
parent 5ecc4421d7
commit 111ebe3c80
3 changed files with 160 additions and 0 deletions

View File

@@ -287,6 +287,9 @@ module Linguist
# See if there is a Language for the extension
pathname.language ||
# Look for idioms in first line
first_line_language ||
# Try to detect Language from shebang line
shebang_language
end
@@ -357,6 +360,20 @@ module Linguist
end
end
# Internal: Guess language from the first line.
#
# Look for leading "<?php"
#
# Returns a Language.
def first_line_language
# Fail fast if blob isn't viewable?
return unless viewable?
if lines.first.to_s =~ /^<\?php/
Language['PHP']
end
end
# Internal: Extract the script name from the shebang line
#
# Requires Blob#data