LiveReload for Sublime Text

Plugins api

class PluginAPI.PluginClass[source]

Class for implementing your custom plug-ins, sublime_plugins compatible

Plug-ins implementing this reference should provide the following attributes:

  • description (string) describing your plug-in
  • title (string) naming your plug-in
  • file_types (string) file_types which should trigger refresh for this plug-in
addResource(req_path, blob, content_type='text/plain')[source]
  • (string) req_path; browser path to file you want to serve. Ex: /yourfile.js
  • (string/file) buffer; string or file instance to file you want to serve
  • (string) content_type; Mime-type of file you want to serve
file_types[source]

Run plug-in only with this file extensions, defaults to all extensions

listClients()[source]

returns list with all connected clients with their req_url and origin

onDisabled()[source]

Runs when plug-in is disabled via menu

onEnabled()[source]

Runs when plug-in is enabled via menu

onReceive(data, origin)[source]

Event handler which fires when browser plug-ins sends data - (string) data sent by browser - (string) origin of data

refresh(filename, settings=None)[source]

Generic refresh command

  • (string) filename; file to refresh (.css, .js, jpg ...)
  • (object) settings; how to reload(entire page or just parts)
sendCommand(command, settings, filename=False)[source]
  • (instance) plug-in; instance
  • (string) command; to trigger in livereload.js (refresh, info, or one of the plugins)
  • (object) settings; additional data that gets passed to command (should be json parsable)
  • (string) original name of file
should_run(filename=False)[source]

Returns True if specified filename is allowed for plug-in, and plug-in itself is enabled

this_session_only[source]

Should it stay enabled forever or this session only

Decorators:

class LiveReload.LiveReload[source]

Bases: threading.Thread, server.SimpleCallbackServer.SimpleCallbackServer, server.SimpleWSServer.SimpleWSServer, server.SimpleResourceServer.SimpleResourceServer, server.LiveReloadAPI.LiveReloadAPI

Start the LiveReload, which exposes public api.

clean()[source]

Stop the server.

run()[source]

Start LiveReload

start_server(port)[source]

Start the server.

LiveReload.http_callback(callback_f)[source]

Add http callback to plugin defined function. For example request to GET /callback/plugin_name/log_me would trigger log_me function in plugin

Example:

@LiveReload.http_callback
def compiled(self, req):
    print req # urlparse object
    return "cool" #to http client
LiveReload.websocket_callback(callback_f)[source]

Add websocket callback to plugin defined function. For example on function call in browser LiveReload.SM2.plugin_name.definedfunction(data) would trigger definedfunction function in plugin or vice verse. Shortly you can call client functions from the server and server functions from client. Everything is JSON encoded by default.

Example:

@LiveReload.websocket_callback
def compiled(self, json):
    print json # json object
    return "cool" #to http client {msg: "cool"}

Indices and tables