def test_parse_tag(self): cases = [ (('extends', ['_base/base.html']), "{% extends '_base/base.html' %}"), (('extends', ['_base/base.html']), "{%extends '_base/base.html' %}"), (('extends', ['ur base/are belong to us.html']), "{%extends 'ur base/are belong to us.html' %}"), (('include', ['_base/base.html']), '{% include "_base/base.html" %}'), (('include', ['_base/base.html']), '{% include "_base/base.html" %}'), (('include', ['_base/base.html']), '{% include "_base/base.html"%}'), (('include', ['_base/base.html']), '{%include "_base/base.html"%}'), (('include', ['_base/base.html']), ' {%include "_base/base.html"%}'), (('include', ['_base/base.html']), 'hnidopich{%include "_base/base.html"%} '), (('include', ['lorem-ipsum/__dolorem']), " {% include 'lorem-ipsum/__dolorem' %}"), (('includeblocks', ['_base/base.html', '_base templates/base.html']), "{% includeblocks '_base/base.html' '_base templates/base.html' %}"), (('include', ['base/base.html']), "{% include 'base/base.html' with foo='bar' %}") ] for exp, line in cases: self.assertEqual(exp, parse_tag(line))
def test_parse_tag(self): cases = [ (('extends', ['_base/base.html']), "{% extends '_base/base.html' %}"), (('extends', ['_base/base.html']), "{%extends '_base/base.html' %}"), (('extends', ['ur base/are belong to us.html']), "{%extends 'ur base/are belong to us.html' %}"), (('include', ['_base/base.html']), '{% include "_base/base.html" %}'), (('include', ['_base/base.html']), '{% include "_base/base.html" %}'), (('include', ['_base/base.html']), '{% include "_base/base.html"%}'), (('include', ['_base/base.html']), '{%include "_base/base.html"%}'), (('includeblocks', ['_base/base.html', '_base templates/base.html']), "{% includeblocks '_base/base.html' '_base templates/base.html' %}"), ] for exp, line in cases: self.assertEqual(exp, parse_tag(line))
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 not tag: return # get the base-path of current file base, current_file = self.view.file_name().split('%(separator)stemplates%(separator)s' % dict(separator=os.path.sep)) 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)
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)