summaryrefslogtreecommitdiff
path: root/lib/coderay
diff options
context:
space:
mode:
authormurphy <murphy@rubychan.de>2010-03-26 05:12:00 +0000
committermurphy <murphy@rubychan.de>2010-03-26 05:12:00 +0000
commite844893db65abbcdbb6c67a249a22e246d9f13cc (patch)
treedb7070000debc655cb27ea80d4449685fe23c371 /lib/coderay
parentcfcf5478b85725d1c3b2a208bfbcff21964fc023 (diff)
downloadcoderay-e844893db65abbcdbb6c67a249a22e246d9f13cc.tar.gz
Cleanups and updates for FileType.
* *REMOVED* @FileType#shebang@ is a protected method now. * *NEW*: Regonizes @.gemspec@, @.rjs@, @.rpdf@ extensions and @Capfile@ as Ruby.
Diffstat (limited to 'lib/coderay')
-rw-r--r--lib/coderay/helpers/file_type.rb55
1 files changed, 28 insertions, 27 deletions
diff --git a/lib/coderay/helpers/file_type.rb b/lib/coderay/helpers/file_type.rb
index e8a0384..e2c3edd 100644
--- a/lib/coderay/helpers/file_type.rb
+++ b/lib/coderay/helpers/file_type.rb
@@ -5,21 +5,16 @@ module CodeRay
#
# A simple filetype recognizer.
#
-# Copyright (c) 2006 by murphy (Kornelius Kalnbach) <murphy rubychan de>
-#
-# License:: LGPL / ask the author
-# Version:: 0.1 (2005-09-01)
-#
-# == Documentation
+# == Usage
#
# # determine the type of the given
-# lang = FileType[ARGV.first]
-#
-# # return :plaintext if the file type is unknown
-# lang = FileType.fetch ARGV.first, :plaintext
-#
-# # try the shebang line, too
-# lang = FileType.fetch ARGV.first, :plaintext, true
+# lang = FileType[ARGV.first]
+#
+# # return :plaintext if the file type is unknown
+# lang = FileType.fetch ARGV.first, :plaintext
+#
+# # try the shebang line, too
+# lang = FileType.fetch ARGV.first, :plaintext, true
module FileType
UnknownFileType = Class.new Exception
@@ -49,20 +44,6 @@ module FileType
type
end
- def shebang filename
- begin
- File.open filename, 'r' do |f|
- if first_line = f.gets
- if type = first_line[TypeFromShebang]
- type.to_sym
- end
- end
- end
- rescue IOError
- nil
- end
- end
-
# This works like Hash#fetch.
#
# If the filetype cannot be found, the +default+ value
@@ -79,6 +60,22 @@ module FileType
end
type
end
+
+ protected
+
+ def shebang filename
+ begin
+ File.open filename, 'r' do |f|
+ if first_line = f.gets
+ if type = first_line[TypeFromShebang]
+ type.to_sym
+ end
+ end
+ end
+ rescue IOError
+ nil
+ end
+ end
end
@@ -87,6 +84,7 @@ module FileType
'css' => :css,
'diff' => :diff,
'dpr' => :delphi,
+ 'gemspec' => :ruby,
'groovy' => :groovy,
'gvy' => :groovy,
'h' => :c,
@@ -111,6 +109,8 @@ module FileType
'rb' => :ruby,
'rbw' => :ruby,
'rhtml' => :rhtml,
+ 'rjs' => :ruby,
+ 'rpdf' => :ruby,
'rxml' => :ruby,
'sch' => :scheme,
'sql' => :sql,
@@ -127,6 +127,7 @@ module FileType
TypeFromShebang = /\b(?:ruby|perl|python|sh)\b/
TypeFromName = {
+ 'Capfile' => :ruby,
'Rakefile' => :ruby,
'Rantfile' => :ruby,
}