Permalink
Browse files

Add detect_file for spec files

  • Loading branch information...
1 parent b4851fe commit 2dc3119501b882b1e869611077d211452fb11a26 Brandon Tilley committed Jul 21, 2011
Showing with 25 additions and 0 deletions.
  1. +25 −0 detect_file_type.py
  2. BIN detect_file_type.pyc
View
@@ -0,0 +1,25 @@
+import sublime, sublime_plugin
+import os
+
+class DetectFileTypeCommand(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", "User/RSpec")
+ elif name == "factories.rb":
+ set_syntax(view, "Rspec", "User/RSpec")
+
+
+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
View
Binary file not shown.

0 comments on commit 2dc3119

Please sign in to comment.