-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #30 from eparisio/master
add jstl language support + mini refactoring to resolver
- Loading branch information
Showing
6 changed files
with
91 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters