<s> import sublime , sublime_plugin , os <EOL> import RailsGoToSpec . resolver <EOL> import re <EOL> class RailsGoToSpecCommand ( sublime_plugin . WindowCommand ) : <EOL> def run ( self ) : <EOL> sublime . status_message ( '<STR_LIT>' ) <EOL> win = self . window <EOL> view = win . active_view ( ) <EOL> current_file = view . file_name ( ) <EOL> root_path = win . folders ( ) [ <NUM_LIT:0> ] <EOL> current_file = re . sub ( root_path , '<STR_LIT>' , current_file ) <EOL> if os . name == '<STR_LIT>' : <EOL> current_file = current_file . replace ( '<STR_LIT:\\>' , '<STR_LIT:/>' ) <EOL> related_files = RailsGoToSpec . resolver . Resolver ( ) . run ( current_file ) <EOL> for ix , file in enumerate ( related_files ) : <EOL> related_files [ ix ] = root_path + file <EOL> self . open_any ( related_files ) <EOL> def is_enabled ( self ) : <EOL> return self . window . active_view ( ) != None <EOL> def open_any ( self , files ) : <EOL> if len ( files ) == <NUM_LIT:0> : <EOL> sublime . status_message ( "<STR_LIT>" ) <EOL> return <EOL> opened = False <EOL> for file in files : <EOL> if not opened : <EOL> opened = self . open ( file ) <EOL> if opened : <EOL> return <EOL> first = files [ <NUM_LIT:0> ] <EOL> if sublime . ok_cancel_dialog ( "<STR_LIT>" + first ) : <EOL> self . create ( first ) <EOL> self . window . open_file ( first ) <EOL> def open ( self , file ) : <EOL> if file == "<STR_LIT>" : <EOL> sublime . status_message ( "<STR_LIT>" ) <EOL> return False <EOL> if os . path . exists ( file ) : <EOL> sublime . status_message ( "<STR_LIT>" + file ) <EOL> self . window . open_file ( file ) <EOL> sublime . status_message ( "<STR_LIT>" + file ) <EOL> return True <EOL> else : <EOL> return False <EOL> def create ( self , filename ) : <EOL> base , filename = os . path . split ( filename ) <EOL> self . create_folder ( base ) <EOL> def create_folder ( self , base ) : <EOL> if not os . path . exists ( base ) : <EOL> parent = os . path . split ( base ) [ <NUM_LIT:0> ] <EOL> if not os . path . exists ( parent ) : <EOL> self . create_folder ( parent ) <EOL> os . mkdir ( base ) </s>
