Permalink
Browse files

Add haml support when switching between code and spec, thx to @Andrey…

…Chernyh
  • Loading branch information...
gs committed Nov 30, 2012
1 parent bf59065 commit 997dc44475e907da4e2c6b3aec3da6ee8bcba6aa
Showing with 18 additions and 7 deletions.
  1. +2 −6 Default (OSX).sublime-keymap
  2. +16 −1 run_ruby_test.py
@@ -6,10 +6,6 @@
{ "keys": ["super+shift+x"], "command": "show_test_panel" }, // show test panel
{ "keys": ["alt+shift+v"], "command": "verify_ruby_file" }, // verify ruby syntax
- { "keys": ["super+period"], "command": "switch_between_code_and_test", "args": {"split_view": false}, "context" : [
- { "key": "selector", "operator": "equal", "operand": "source.ruby", "match_all": true }
- ]}, // switch between code and test in single mode
- { "keys": ["super+ctrl+period"], "command": "switch_between_code_and_test", "args": {"split_view": true}, "context" : [
- { "key": "selector", "operator": "equal", "operand": "source.ruby", "match_all": true }
- ]} // switch between code and test in split view
+ { "keys": ["super+period"], "command": "switch_between_code_and_test", "args": {"split_view": false} }, // switch between code and test in single mode
+ { "keys": ["super+ctrl+period"], "command": "switch_between_code_and_test", "args": {"split_view": true} } // switch between code and test in split view
]
View
@@ -151,6 +151,9 @@ class BaseFile(object):
def __init__(self, file_name):
self.folder_name, self.file_name = os.path.split(file_name)
self.absolute_path = file_name
+ def parent_dir_name(self):
+ head_dir, tail_dir = os.path.split(self.folder_name)
+ return tail_dir
def verify_syntax_command(self): return None
def possible_alternate_files(self): return []
def run_all_tests_command(self): return None
@@ -202,7 +205,7 @@ def features(self): return ["run_test"]
def get_project_root(self): return self.find_project_root(CUCUMBER_UNIT_FOLDER)
class RSpecFile(RubyFile):
- def possible_alternate_files(self): return [self.file_name.replace("_spec.rb", ".rb")]
+ def possible_alternate_files(self): return [self.file_name.replace("_spec.rb", ".rb"), self.file_name.replace("haml_spec.rb", "haml")]
def run_all_tests_command(self): return RubyTestSettings().run_rspec_command(relative_path=self.relative_file_path(RSPEC_UNIT_FOLDER))
def run_single_test_command(self, view): return RubyTestSettings().run_single_rspec_command(relative_path=self.relative_file_path(RSPEC_UNIT_FOLDER), line_number=self.get_current_line_number(view))
def features(self): return super(BaseRubyTask.RSpecFile, self).features() + ["run_test"]
@@ -213,6 +216,10 @@ def verify_syntax_command(self): return RubyTestSettings().erb_verify_command(fi
def can_verify_syntax(self): return True
def features(self): return ["verify_syntax"]
+ class HamlFile(BaseFile):
+ def possible_alternate_files(self): return [self.file_name.replace(".haml", ".haml_spec.rb")]
+ def features(self): return ["switch_to_test"]
+
def file_type(self, file_name = None):
file_name = file_name or self.view.file_name()
if not file_name: return BaseRubyTask.AnonymousFile()
@@ -226,6 +233,8 @@ def file_type(self, file_name = None):
return BaseRubyTask.RubyFile(file_name)
elif re.search('\w+\.erb', file_name):
return BaseRubyTask.ErbFile(file_name)
+ elif re.search('\w+\.haml', file_name):
+ return BaseRubyTask.HamlFile(file_name)
else:
return BaseRubyTask.BaseFile(file_name)
@@ -278,6 +287,12 @@ def run(self, args, split_view):
self.load_config()
possible_alternates = self.file_type().possible_alternate_files()
alternates = self.project_files(lambda file: file in possible_alternates)
+
+ for alternate in alternates:
+ if re.search(self.file_type().parent_dir_name(), alternate):
+ alternates = [alternate]
+ break
+
if alternates:
if split_view:
self.window().run_command('set_layout', {

0 comments on commit 997dc44

Please sign in to comment.