Skip to content

Commit

Permalink
added Goto Tea Definition functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
pferruggiaro committed Mar 4, 2013
1 parent bc8bb2f commit 5ebc9f4
Show file tree
Hide file tree
Showing 6 changed files with 106 additions and 1 deletion.
3 changes: 3 additions & 0 deletions .gitignore
@@ -0,0 +1,3 @@
.DS_Store
*.pyc
*.tmlanguage.cache
5 changes: 5 additions & 0 deletions Default.sublime-commands
@@ -0,0 +1,5 @@
[{
"id": "GotoTeaDefinition",
"caption": "Goto Definition: Tea",
"command": "goto_tea_definition"
}]
5 changes: 5 additions & 0 deletions Default.sublime-keymap
@@ -0,0 +1,5 @@
[
{
"keys": ["alt+super+down"], "command": "goto_tea_definition"
}
]
70 changes: 70 additions & 0 deletions 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
6 changes: 5 additions & 1 deletion README.md
Expand Up @@ -3,4 +3,8 @@ Sublime Tea


A Sublime Text 2 language definition file for the Tea templating language. 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!
18 changes: 18 additions & 0 deletions 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.