diff options
-rw-r--r-- | Changes.textile | 7 | ||||
-rw-r--r-- | lib/coderay/helpers/file_type.rb | 55 |
2 files changed, 35 insertions, 27 deletions
diff --git a/Changes.textile b/Changes.textile index 719d747..09c236a 100644 --- a/Changes.textile +++ b/Changes.textile @@ -51,6 +51,13 @@ h3. @Styles::Alpha@ * *NEW* A style that uses transparent HSLA colors as defined in CSS 3. +h3. @FileType@ + +* *REMOVED* @FileType#shebang@ is a protected method now. +* *NEW*: Regonizes @.gemspec@, @.rjs@, @.rpdf@ extensions and @Capfile@ as Ruby. + + Thanks to the authors of the TextMate Ruby bundle! + h3. Internal API changes * *FIXED* @Encoders::HTML#token@'s second parameter is no longer optional. 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, } |