-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathdjango_click.py
29 lines (22 loc) · 894 Bytes
/
django_click.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
import os
import sublime, sublime_plugin
try:
from utils import parse_tag
except ImportError:
from .utils import parse_tag
class DjangoClickCommand(sublime_plugin.TextCommand):
TEMPLATE_DIR = 'templates'
def run(self, edit):
region = self.view.sel()[0]
line = self.view.line(region)
line_contents = self.view.substr(line)
tag, targets = parse_tag(line_contents)
if tag:
# get the base-path of current file
base, current_file = self.view.file_name().split('%(separator)stemplates%(separator)s' % dict(separator=os.path.sep), 1)
for one in targets:
# get the target file path
tar = os.path.join(base, self.TEMPLATE_DIR, one)
# open it!
window = sublime.active_window()
window.open_file(tar, sublime.ENCODED_POSITION)