Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ability to use locally installed stylus #75

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ Go to `Project > Edit Project` to change project settings.
{
"Stylus":
{
"binDir": "./node_modules/.bin",
"compress": false,
"compileOnSave": true,
"compileDir": "out"
Expand Down
32 changes: 31 additions & 1 deletion Stylus.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,20 @@ def _run(cmd, args=[], source="", cwd=None, env=None):
okay = proc.returncode == 0
return {"okay": okay, "out": stat[0].decode(locale.getdefaultlocale()[1]), "err": stat[1].decode(locale.getdefaultlocale()[1])}
else:
bindir = settings_get('binDir', '/usr/local/bin')
if bindir.startswith("./"):
bindir = current_project_folder() + bindir[1:]

if env is None:
env = {"PATH": settings_get('binDir', '/usr/local/bin')}
env = {"PATH": bindir}

# adding custom PATHs from settings
customEnv = settings_get('envPATH', "")

# adding environment path
if len(os.environ.get("PATH")):
env["PATH"] = env["PATH"]+":"+os.environ.get("PATH")

if customEnv:
env["PATH"] = env["PATH"]+":"+customEnv
if source == "":
Expand All @@ -75,6 +84,27 @@ def _run(cmd, args=[], source="", cwd=None, env=None):
return {"okay": okay, "out": stat[0].decode('utf-8'), "err": stat[1].decode('utf-8')}


# From https://github.com/pderichs/sublime_rubocop/blob/master/rubocop_command.py
# Return the the first path of the project
def current_project_folder():
if int(sublime.version()) >= 3000:
project = sublime.active_window().project_data()
project_base_path = os.path.dirname(sublime.active_window().project_file_name())
if not (project is None):
if 'folders' in project:
folders = project['folders']
if len(folders) > 0:
first_folder = folders[0]
if 'path' in first_folder:
path = first_folder['path']
return (path if os.path.isabs(path) else os.path.join(project_base_path, path)) or ''
else:
folders = sublime.active_window().folders()
if (not (folders is None)) and (len(folders) > 0):
return folders[0]
return ''


def isStylus(view=None):
if view is None:
view = sublime.active_window().active_view()
Expand Down
2 changes: 2 additions & 0 deletions Stylus.sublime-settings
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
/*
The directory containing your stylus binary. Usually
/usr/local/bin or /usr/bin.
If binDir begins with "./", then it is replaced by the first path of the project.
Set bindir to "./node_modules/.bin", and it will use the locally installed coffee.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it should be stylus instead of coffee

*/
"binDir": "/usr/local/bin",

Expand Down