Permalink
Browse files

Added RSpecDetectFileType.py to auto-detect RSpec files (*_spec.rb) a…

…nd set syntax appropriately.
  • Loading branch information...
Greg Williams
Greg Williams committed Feb 13, 2012
1 parent 0e475bf commit d8a2ccf5af9a4aacdb9d30117c6cd14b0cfbf8d5
Showing with 31 additions and 1 deletion.
  1. +2 −1 .gitignore
  2. +29 −0 RSpecDetectFileType.py
View
@@ -1 +1,2 @@
-*.pyc
+*.pyc
+*.cache
View
@@ -0,0 +1,29 @@
+import sublime, sublime_plugin
+import os
+
+class RSpecDetectFileTypeCommand(sublime_plugin.EventListener):
+ """ Detects current file type if the file's extension isn't conclusive """
+ """ Modified for Ruby on Rails and Sublime Text 2 """
+ """ Original pastie here: http://pastie.org/private/kz8gtts0cjcvkec0d4quqa """
+
+ def on_load(self, view):
+ filename = view.file_name()
+ if not filename: # buffer has never been saved
+ return
+
+ name = os.path.basename(filename.lower())
+ if name[-8:] == "_spec.rb":
+ set_syntax(view, "RSpec", "RSpec")
+ elif name == "factories.rb":
+ set_syntax(view, "RSpec", "RSpec")
+ # elif name == "gemfile":
+ # set_syntax(view, "Ruby on Rails", "Rails")
+ # elif name[-2:] == "rb":
+ # set_syntax(view, "Ruby on Rails", "Rails")
+
+
+def set_syntax(view, syntax, path=None):
+ if path is None:
+ path = syntax
+ view.settings().set('syntax', 'Packages/'+ path + '/' + syntax + '.tmLanguage')
+ print "Switched syntax to: " + syntax

0 comments on commit d8a2ccf

Please sign in to comment.