Skip to content
This repository was archived by the owner on Oct 26, 2021. It is now read-only.

search for a binary #1

Open
wants to merge 6 commits 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
35 changes: 23 additions & 12 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,39 @@ LESS PLUGIN FOR SUBLIME TEXT
This plugin compiles LESS (http://lesscss.org/) files into CSS files in Sublime
Text 2 on save.

This plugin is tested on Linux only.

If you are using Mac OS X or Windows have a look at
https://github.com/BBB/sublime-text-2-plugins.

This plugin is tested on Mac Os X, but suppose to work on other systems.

Prerequisits
------------

Install lessc
Install nodejs, required for runing lessc:

$ apt-get install lessc
http://www.hodejs.org

or
Install lessc binary:

$ apt-get install nodejs npm
$ npm install lessc
http://lesscss.org/


Installation
Package installation
------------

Linux

$ cd ~/.config/sublime-text-2/Packages/
$ git clone [email protected]:tisto/sublime-text-less.git

Mac Os X

$ cd ~/Library/Application\ Support/Sublime\ Text\ 2/Packages

$ git clone [email protected]:speechkey/sublime-text-less.git

Edit sublime-text-less.sublime-settings and add lessc and nodejs path, if it not already included in your default environment path.

Linux

$ vim ~/.config/sublime-text-2/Packages/sublime-text-less.sublime-settings

Mac Os X

$ vim ~/Library/Application\ Support/Sublime\ Text\ 2/Packages/sublime-text-less.sublime-settings
41 changes: 41 additions & 0 deletions commandline.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# adapted from https://github.com/wbond/sublime_package_control/blob/master/Package%20Control.py
import os.path
import subprocess
import sublime


class BinaryNotFoundError(Exception):
pass


def find_binary(name):
dirs = ['/usr/local/sbin', '/usr/local/bin', '/usr/sbin', '/usr/bin',
'/sbin', '/bin']

s = sublime.load_settings("sublime-text-less.sublime-settings")
lessc_path = s.get("lessc_path")
nodejs_path = s.get("nodejs_path")

if lessc_path:
dirs.append(lessc_path)

if nodejs_path:
os.environ["PATH"] += ''.join([':', nodejs_path])

for dir in dirs:
path = os.path.join(dir, name)
if os.path.exists(path):
return path

raise BinaryNotFoundError('The binary ' + name + ' could not be ' + \
'located')


def execute(args):
proc = subprocess.Popen(args, stdin=subprocess.PIPE,
stdout=subprocess.PIPE, stderr=subprocess.STDOUT)

output = proc.stdout.read()
proc.wait()
return output

19 changes: 12 additions & 7 deletions less.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,28 @@
import sublime
import sublime_plugin
import subprocess
import commandline


class CompileLessOnSave(sublime_plugin.EventListener):

def on_post_save(self, view):
try:
lessc = commandline.find_binary('lessc')
except commandline.BinaryNotFoundError:
sublime.error_message("I couldn't find \"less\" binary on your system. Less is required on your system. Please install it and try again.")
return

if not view.file_name().endswith('.less'):
return

filename = view.file_name()
output_filename = filename.replace('.less', '.css')

proc = subprocess.Popen("lessc %s" % filename,
shell=True,
stdout=subprocess.PIPE)
output = proc.communicate()[0]
command = [lessc] + [filename]
output = commandline.execute(command)

output_file = open(output_filename,"w")
output_file.write(output)
output_file.close()
output_file = open(output_filename,"w")
output_file.write(output)
output_file.close()

4 changes: 4 additions & 0 deletions sublime-text-less.sublime-settings
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"lessc_path": "/Users/speechkey/Dev/tools/bin",
"nodejs_path": "/opt/local/bin"
}