Skip to content

Commit

Permalink
Fixed compass behaviour
Browse files Browse the repository at this point in the history
  • Loading branch information
Grafikart committed Oct 31, 2012
1 parent 15d5f70 commit 36f88b9
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 25 deletions.
1 change: 0 additions & 1 deletion LiveReload.sublime-settings
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,4 @@
, "apply_js_live" : false
, "apply_css_live" : true
, "apply_images_live" : true
, "compass_css_dir" : false //set to false if you have problems with livereload
}
14 changes: 12 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
LiveReload for Sublime Text 2
=========

A web browser page reloading plugin for the [Sublime Text 2](http://sublimetext.com "Sublime Text 2") editor.
A web browser page reloading plugin for the [Sublime Text 2](http://sublimetext.com "Sublime Text 2") editor.

Installing
-----
Expand Down Expand Up @@ -46,4 +46,14 @@ If you are using Chrome, just click the toolbar button (it will turn green to in

----

You can also use the Preferences menu to change port, version and type of reloading(full, js,css).
You can also use the Preferences menu to change port, version and type of reloading(full, js,css).

## Compass

![](http://cdn.nmecdesign.com/wp/wp-content/uploads/2011/12/Compass-Logo.png)

Want to use Livereload with compass ? Now you can !

.scss and .css have to be in the same directory , if no config.rb file is found one will automatically generated !

So if you want to start using compass, install compass gem, edit a xxx.scss file and voila ! A .css file would be automatically generated.
8 changes: 8 additions & 0 deletions assets/config.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
http_path = "/"
css_dir = "."
sass_dir = "."
images_dir = "img"
javascripts_dir = "js"
output_style = :compressed
relative_assets=true
line_comments = false
50 changes: 28 additions & 22 deletions livereload_st2.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import sublime,sublime_plugin,threading,json,os,threading,subprocess,socket
import sublime,sublime_plugin,threading,json,os,threading,subprocess,socket,shutil
from base64 import b64encode, b64decode
# python 2.6 differences
try:
try:
from hashlib import md5, sha1
except: from md5 import md5; from sha import sha as sha1
from SimpleHTTPServer import SimpleHTTPRequestHandler
Expand Down Expand Up @@ -40,7 +40,7 @@ def run(self):
class LiveReloadChange(sublime_plugin.EventListener):
def __init__ (self):
LiveReload().start()

def __del__(self):
global LivereloadFactory
LivereloadFactory.stop()
Expand All @@ -49,43 +49,49 @@ def on_post_save(self, view):
global LivereloadFactory
settings = sublime.load_settings('LiveReload.sublime-settings')
filename = view.file_name()
if view.file_name().find('.scss') > 0 and bool(settings.get('compass_css_dir')):
filename = filename.replace('sass',settings.get('compass_css_dir')).replace('.scss','.css')
dirname = os.path.dirname(os.path.dirname(filename))
compiler = CompassThread(dirname,filename,LivereloadFactory)
if view.file_name().find('.scss') > 0 or view.file_name().find('.scss') > 0:
compiler = CompassThread(filename,LivereloadFactory)
compiler.start()
else:
filename = os.path.normcase(filename)
filename = os.path.split(filename)[1]
filename = filename.replace('.scss','.css').replace('.styl','.css').replace('.less','.css')
filename = filename.replace('.coffee','.js')

data = json.dumps(["refresh", {
"path": filename,
"apply_js_live": settings.get('apply_js_live'),
"apply_css_live": settings.get('apply_css_live'),
"apply_images_live": settings.get('apply_images_live')
}])
sublime.set_timeout(lambda: LivereloadFactory.send_all(data), int(settings.get('delay_ms')))
sublime.set_timeout(lambda: sublime.status_message("Sent LiveReload command for file: "+filename), int(settings.get('delay_ms')))
sublime.set_timeout(lambda: LivereloadFactory.send_all(data), int(settings.get('delay_ms')))
sublime.set_timeout(lambda: sublime.status_message("Sent LiveReload command for file: "+filename), int(settings.get('delay_ms')))


class CompassThread(threading.Thread):

def __init__(self, dirname,filename,LivereloadFactory):
self.dirname = dirname
self.filename = filename
def __init__(self, filename,LivereloadFactory):
self.dirname = os.path.dirname(filename)
self.filename = filename.replace('.scss','.css').replace('.sass','.css')
self.LivereloadFactory = LivereloadFactory
self.stdout = None
self.stderr = None
threading.Thread.__init__(self)

def run(self):
global LivereloadFactory
p = subprocess.Popen(['compass','compile',self.dirname],shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.STDOUT )
print 'compass compile ' + self.dirname

# autocreate config.rb for compass
if not os.path.exists(os.path.join(self.dirname, "config.rb")):
print "Generating config.rb"
shutil.copy(os.path.join(sublime.packages_path(), "LiveReload","assets","config.rb"), self.dirname)

# compass compile
p = subprocess.Popen(['compass compile ' + self.dirname.replace('\\','/')],shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.STDOUT )
if p.stdout.read() :
self.LivereloadFactory.send_all(json.dumps(["refresh", {
"path": self.filename,
"path": self.filename.replace('\\','/'),
"apply_js_live": True,
"apply_css_live": True,
"apply_images_live": True
Expand All @@ -97,7 +103,7 @@ class WebSocketServer:
Handle the Server, bind and accept new connections, open and close
clients connections.
"""

def __init__(self, port, version):
self.clients = []
self.port = port
Expand Down Expand Up @@ -135,7 +141,7 @@ def send_all(self, data):
"""
Send a message to all the currenly connected clients.
"""

[client.send(data) for client in self.clients]

def remove(self, client):
Expand Down Expand Up @@ -196,7 +202,7 @@ def run(self):
print response
self.s.send(response.encode())
self.new_client()

# Receive and handle data
while 1:
try:
Expand Down Expand Up @@ -250,8 +256,8 @@ def encode_hybi(buf, opcode, base64=False):

print("Encoded: %s" % repr(header + buf))

return header + buf, len(header), 0
return header + buf, len(header), 0

@staticmethod
def decode_hybi(buf, base64=False):
""" Decode HyBi style WebSocket packets.
Expand Down

0 comments on commit 36f88b9

Please sign in to comment.