This repository has been archived by the owner on Feb 8, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
EmberComponentSplitView.py
70 lines (54 loc) · 2.43 KB
/
EmberComponentSplitView.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import sublime, sublime_plugin, logging
class EmberComponentSplitViewCommand(sublime_plugin.WindowCommand):
# @public findCompanionPodStructure
# @return {String} newFile - the file to open
def findCompanionPodStructure(self):
if 'hbs' in self.reference_file_type:
if 'components' in self.reference_file_path:
companion_file = self.reference_file_path + '/component.js'
else:
companion_file = self.reference_file_path + '/route.js'
else:
companion_file = self.reference_file_path + '/template.hbs'
return companion_file
# @public findCompanionFolderStucture
# @return {String} newFile - the file to open
def findCompanionFolderStucture(self):
base_path = self.reference_file_path.rsplit('/app/', 1)[0] + '/app/'
if 'hbs' in self.reference_file_type:
if 'components' in self.reference_file_path:
companion_file_name = self.reference_file_name.rsplit('.', 1)[0] + '.js'
companion_file = base_path + 'components/' + self.reference_file_location + '/' + companion_file_name
else:
companion_file_name = self.reference_file_name.rsplit('.', 1)[0] + '.js'
companion_file = base_path + 'routes/' + self.reference_file_location + '/' + companion_file_name
else:
companion_file_name = self.reference_file_name.rsplit('.', 1)[0] + '.hbs'
companion_file = base_path + 'templates/' + self.reference_file_location + '/' + companion_file_name
return companion_file
def checkIfUsePods(self):
settings = sublime.load_settings('EmberComponentSplitView.sublime-settings')
use_pods_defined = settings.has('usePods')
if(use_pods_defined):
return settings.get('usePods')
return 'pods' in self.reference_file_location
# @public findFile
# @return {String} fileToOpen
def processFile(self):
self.reference_file = self.window.active_view().file_name()
self.reference_file_path = self.reference_file.rsplit('/', 1)[0]
self.reference_file_name = self.reference_file.rsplit('/', 1)[1]
self.reference_file_type = self.reference_file.rsplit('.', 1)[-1]
self.reference_file_location = self.reference_file_path.rsplit('/app/', 1)[1]
usePods = self.checkIfUsePods()
if usePods:
companion_file = self.findCompanionPodStructure()
else:
companion_file = self.findCompanionFolderStucture()
return companion_file
def run(self):
file = self.processFile()
self.window.focus_group(0)
self.window.open_file(self.window.active_view().file_name())
self.window.focus_group(1)
self.window.open_file(file)