diff --git a/README.md b/README.md index 8356089..69db4dd 100644 --- a/README.md +++ b/README.md @@ -24,6 +24,7 @@ extended to support more languages. | Stylus | `Stylus.tmLanguage` | | PHP | `PHP.sublime-syntax`
`PHP Source.sublime-syntax` | | HTML | `HTML.sublime-syntax` | +| JSTL | `JSTL.sublime-syntax` | *You can contribute and add more languages by adding a path resolver like [SassPathResolver](https://github.com/aziz/SublimeHyperClick/blob/master/hyper_click/sass_path_resolver.py)* @@ -115,6 +116,9 @@ see [hyper_click.sublime-settings](https://github.com/aziz/SublimeHyperClick/blo ], "html": [ "HTML.sublime-syntax" + ], + "jstl": [ + "jstl.tmLanguage" ] }, "import_line_regex": { @@ -140,6 +144,9 @@ see [hyper_click.sublime-settings](https://github.com/aziz/SublimeHyperClick/blo ], "html": [ ".*?.*?" + ], + "jstl": [ + "(<([\\w-]*)\\:([\\w-]*))", ] }, "valid_extensions": { @@ -148,17 +155,23 @@ see [hyper_click.sublime-settings](https://github.com/aziz/SublimeHyperClick/blo "less": ["less"], "php": ["php"], "stylus": ["styl", "stylus"], - "html": ["html"] + "html": ["html"], + "jstl": ["jsp", "tag"] }, "default_filenames": { "js": ["index"] }, "vendor_dirs": { "js": ["node_modules"], - "html": ["node_modules", "bower_components"] + "html": ["node_modules", "bower_components"], + "jstl": ["WEB-INF"] }, "lookup_paths": { - "js": [] + "js": [], + "jstl": [ + "taglib *prefix ?= ?[\"'](.*)[\"'] *tagdir ?= ?[\"'](.*)[\"']", + "xmlns:(\\w*)=[\"']urn:jsptagdir:(.*?)[\"']" + ] }, "annotation_found_text": "➜", "annotation_not_found_text": "✘", diff --git a/hyper_click.sublime-settings b/hyper_click.sublime-settings index da748cc..78b2365 100644 --- a/hyper_click.sublime-settings +++ b/hyper_click.sublime-settings @@ -22,6 +22,9 @@ ], "html": [ "HTML.sublime-syntax" + ], + "jstl": [ + "jstl.tmLanguage" ] }, "import_line_regex": { @@ -47,6 +50,9 @@ ], "html": [ ".*?.*?" + ], + "jstl": [ + "(<([\\w-]*)\\:([\\w-]*))", ] }, "valid_extensions": { @@ -55,17 +61,23 @@ "less": ["less"], "php": ["php"], "stylus": ["styl", "stylus"], - "html": ["html"] + "html": ["html"], + "jstl": ["jsp", "tag"] }, "default_filenames": { "js": ["index"] }, "vendor_dirs": { "js": ["node_modules"], - "html": ["node_modules", "bower_components"] + "html": ["node_modules", "bower_components"], + "jstl": ["WEB-INF"] }, "lookup_paths": { - "js": [] + "js": [], + "jstl": [ + "taglib *prefix ?= ?[\"'](.*)[\"'] *tagdir ?= ?[\"'](.*)[\"']", + "xmlns:(\\w*)=[\"']urn:jsptagdir:(.*?)[\"']" + ] }, "annotation_found_text": "➜", "annotation_not_found_text": "✘", diff --git a/hyper_click/jstl_path_resolver.py b/hyper_click/jstl_path_resolver.py new file mode 100644 index 0000000..33752f4 --- /dev/null +++ b/hyper_click/jstl_path_resolver.py @@ -0,0 +1,51 @@ +# -*- coding: utf-8 -*- +import re +from os import path + + +class JstlPathResolver: + def __init__(self, view, str_lookup, current_dir, roots, lang, settings): + self.view = view + self.import_line_regex = settings.get('import_line_regex', {})[lang] + prog = re.compile(self.import_line_regex[0]) + regMatch = prog.match(str_lookup) + self.str_path = regMatch.group(2) + self.str_file = regMatch.group(3) + self.current_dir = current_dir + self.lang = lang + self.settings = settings + self.roots = roots + self.valid_extensions = settings.get('valid_extensions', {})[lang] + self.dirs_regex = settings.get('lookup_paths', {})[lang] + self.vendors = settings.get('vendor_dirs', {})[lang] + + def resolve(self): + for regex_str in self.dirs_regex: + regions = self.view.find_all(regex_str) + for region in regions: + file_path = self.find_folder(region) + if file_path: + return file_path + return '' + + def find_folder(self, region): + text = self.view.substr(region) + matched = self.is_valid_line(text) + if matched: + if matched.group(1) == self.str_path: + complete_path = matched.group(2) + "/" + self.str_file + ".tag" + file_path = path.realpath(path.join(self.current_dir, self.str_path)) + for vendor in self.vendors: + base_dir = re.split(vendor,file_path) + dest_file_path = base_dir[0] + complete_path + if path.isfile(dest_file_path): + return dest_file_path + return '' + + def is_valid_line(self, line_content): + for regex_str in self.dirs_regex: + pattern = re.compile(regex_str) + matched = pattern.match(line_content) + if matched: + return matched + return False diff --git a/hyper_click/path_resolver.py b/hyper_click/path_resolver.py index 6f247ab..39cf9f7 100644 --- a/hyper_click/path_resolver.py +++ b/hyper_click/path_resolver.py @@ -3,13 +3,15 @@ from .js_path_resolver import JsPathResolver from .sass_path_resolver import SassPathResolver from .less_path_resolver import LessPathResolver +from .jstl_path_resolver import JstlPathResolver from .php_path_resolver import PhpPathResolver from .html_path_resolver import HTMLPathResolver from .path_generic_subfolder_resolver import GenericSubfolderResolver class HyperClickPathResolver: - def __init__(self, str_path, current_file, roots, lang, settings): + def __init__(self, view, str_path, roots, lang, settings): + current_file = view.file_name() current_dir = path.dirname(path.realpath(current_file)) if lang == 'js': self.resolver = JsPathResolver(str_path, current_dir, roots, lang, settings) @@ -21,6 +23,8 @@ def __init__(self, str_path, current_file, roots, lang, settings): self.resolver = PhpPathResolver(str_path, current_dir, roots, lang, settings) elif lang == 'html': self.resolver = HTMLPathResolver(str_path, current_dir, roots, lang, settings) + elif lang == 'jstl': + self.resolver = JstlPathResolver(view, str_path, current_dir, roots, lang, settings) else: self.resolver = GenericSubfolderResolver(str_path, current_dir, roots, lang, settings) diff --git a/hyper_click_annotator.py b/hyper_click_annotator.py index 1c9236c..1dc22e8 100644 --- a/hyper_click_annotator.py +++ b/hyper_click_annotator.py @@ -72,8 +72,8 @@ def annotate(self, point): if matched: destination_str = matched.group(1) - file_path = HyperClickPathResolver( - destination_str, v.file_name(), + file_path = HyperClickPathResolver(v, + destination_str, self.roots, self.lang, self.settings ) region = sublime.Region(line_range.b, line_range.b) diff --git a/hyper_click_command.py b/hyper_click_command.py index 81ca496..dd5b55d 100644 --- a/hyper_click_command.py +++ b/hyper_click_command.py @@ -30,8 +30,8 @@ def run(self, edit): matched = self.is_valid_line(line_content) if matched: destination_str = matched.group(1) - file_path = HyperClickPathResolver( - destination_str, v.file_name(), + file_path = HyperClickPathResolver(v, + destination_str, self.roots, self.lang, self.settings ) resolved_path = file_path.resolve()