Permalink
Browse files

added Goto Tea Definition functionality

  • Loading branch information...
1 parent bc8bb2f commit 5ebc9f4c62d5bd084d5b7da4e73d9a7f79b1bff5 @pferruggiaro committed Mar 4, 2013
Showing with 106 additions and 1 deletion.
  1. +3 −0 .gitignore
  2. +5 −0 Default.sublime-commands
  3. +5 −0 Default.sublime-keymap
  4. +70 −0 GotoTeaDefinition.py
  5. +5 −1 README.md
  6. +18 −0 SublimeTea.sublime-settings
View
3 .gitignore
@@ -0,0 +1,3 @@
+.DS_Store
+*.pyc
+*.tmlanguage.cache
View
5 Default.sublime-commands
@@ -0,0 +1,5 @@
+[{
+ "id": "GotoTeaDefinition",
+ "caption": "Goto Definition: Tea",
+ "command": "goto_tea_definition"
+}]
View
5 Default.sublime-keymap
@@ -0,0 +1,5 @@
+[
+ {
+ "keys": ["alt+super+down"], "command": "goto_tea_definition"
+ }
+]
View
70 GotoTeaDefinition.py
@@ -0,0 +1,70 @@
+import sublime, sublime_plugin
+import os.path
+import re
+from collections import defaultdict
+from collections import deque
+
+settings = sublime.load_settings('SublimeTea.sublime-settings')
+
+class GotoTeaDefinitionCommand(sublime_plugin.TextCommand):
+
+ # def run_(self, args):
+ # window = sublime.active_window()
+ # view = self.view
+ # edit = self.view.begin_edit(self.name(), args)
+ # #print self.view.sel()[0]
+
+ # old_sel = [r for r in self.view.sel()]
+ # print args
+ # self.view.run_command("drag_select", {'event': args['event']})
+ # pos = self.view.sel()[0].begin()
+ # # #sel = self.view.sel()
+ # print pos
+ # new_sel = self.view.sel()
+ # click_point = new_sel[0].a
+ # new_sel.clear()
+ # map(new_sel.add, old_sel)
+ # self.view.run_command("drag_select", args)
+ # # self.view.end_edit(edit)
+ # # self.view.sel().clear()
+ # # self.view.end_edit(edit)
+
+ def run(self, edit):
+ window = sublime.active_window()
+ view = self.view
+ pos = view.sel()[0].end()
+ syntax = view.scope_name(pos)
+
+ if re.match(".*meta.template-call.tea", syntax):
+ path = view.substr(view.extract_scope(pos))
+ opened = self.resolve_path(window, view, path)
+
+ def resolve_path(self, window, view, path):
+ path = path.replace(".", "/") + ".tea"
+ dirname = os.path.dirname(view.file_name())
+ window.open_file(self.find_template(dirname, path))
+
+ def find_template(self, dirname, filename):
+ # first try the same folder as the current template
+ absolute = os.path.join(dirname, filename)
+ if (os.path.exists(absolute)):
+ return absolute
+
+ # second try from the root of the service
+ service = self.find_service(dirname)
+ if (service):
+ absolute = os.path.join(service.get('path'), filename)
+ if (os.path.exists(absolute)):
+ return absolute
+
+ # third try the inlcudes paths
+ for includePath in service.get('include-paths'):
+ absolute = os.path.join(includePath, filename)
+ if (os.path.exists(absolute)):
+ return absolute
+
+ def find_service(self, dirname):
+ for service in settings.get('template_paths'):
+ path = service.get('path')
+ if dirname.find(path) != -1:
+ return service
View
6 README.md
@@ -3,4 +3,8 @@ Sublime Tea
A Sublime Text 2 language definition file for the Tea templating language.
-Drop into tea.tmlanguage into Library/Application Support/Sublime Text 2/Packages/User and restart.
+Clone this repo into Library/Application Support/Sublime Text 2/Packages/Tea and restart.
+
+Edit SublimeTea.sublime-settings to configure your template paths.
+
+Place your cursor on a template call and press alt+command+down to Goto Tea Template definition. Yay!
View
18 SublimeTea.sublime-settings
@@ -0,0 +1,18 @@
+{
+ "template_paths": [
+ {
+ "name": "espn360-butler",
+ "path" : "/Users/ferruggp/workspace/watch.espn-templates/espn360-butler/src/main/resources",
+ "include-paths": [
+ "/Users/ferruggp/workspace/watch.espn-templates/includes/src/main/resources"
+ ]
+ },
+ {
+ "name": "auth-butler",
+ "path": "/Users/ferruggp/workspace/watch.espn-templates/auth-butler/src/main/resources",
+ "include-paths": [
+ "/Users/ferruggp/workspace/watch.espn-templates/includes/src/main/resources"
+ ]
+ }
+ ]
+}

0 comments on commit 5ebc9f4

Please sign in to comment.