Skip to content

Commit

Permalink
Proper sass import path resolution. Fixes #103
Browse files Browse the repository at this point in the history
  • Loading branch information
mrjoelkemp committed Feb 10, 2015
1 parent 94ff451 commit c6f0623
Showing 1 changed file with 41 additions and 20 deletions.
61 changes: 41 additions & 20 deletions JumpToDependency.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,33 +73,54 @@ def run(self):
else:
module_with_extension = module

p('Before abs path resolution', module_with_extension)

file_to_open = self.get_absolute_path(module_with_extension)
p('After abs path resolution', file_to_open)

file_exists = os.path.isfile(file_to_open)

if not file_exists and is_sass_file(file_to_open):
p('Now looking for underscored sass path')
file_to_open = get_underscored_sass_path(file_to_open)
p('Underscored file:', file_to_open)

# Our guess at the extension failed
elif not file_exists:
# Is relative to the module
actual_file = find_file_like(module)
if actual_file:
extension = os.path.splitext(actual_file)[1]
module_with_extension = module + extension
file_to_open = self.get_absolute_path(module_with_extension)
if is_sass_file(module_with_extension):
file_to_open = self.resolve_sass_import(module_with_extension)
else:
p('Before abs path resolution', module_with_extension)

# Assume the file is about the root
file_to_open = self.get_absolute_path(module_with_extension)
p('After abs path resolution', file_to_open)

file_exists = os.path.isfile(file_to_open)
if not file_exists:
p('Now searching for a file like', module)
# Is relative to the module
actual_file = find_file_like(module)
if actual_file:
extension = os.path.splitext(actual_file)[1]
module_with_extension = module + extension
file_to_open = self.get_absolute_path(module_with_extension)

self.open_file(file_to_open)

t('Run_JumpToDependency', {
'etime': time.time() - total_start_time
})

def resolve_sass_import(self, filename):
"""
Looks for the appropriate filename to open
by checking the same folder as the current file and
if the file isn't found, looking for an underscored
partial with the expected name.
"""
# Check current file's directory
file_dir = os.path.dirname(self.view.filename)

p('Looking within', file_dir, 'for', filename)

file_to_open = os.path.normpath(os.path.join(file_dir, filename))
if os.path.isfile(file_to_open):
return file_to_open

# Check underscored file within current file's directory
file_to_open = get_underscored_sass_path(file_to_open)
p('Now looking for underscored sass path', file_to_open)
if os.path.isfile(file_to_open):
return file_to_open

return None
def open_file(self, filename):
"""
Opens the passed file or shows an error error message
Expand Down

0 comments on commit c6f0623

Please sign in to comment.