Navigation Menu

Skip to content

Commit

Permalink
Move LESS.js support into a plugin, start working on plugin API
Browse files Browse the repository at this point in the history
  • Loading branch information
andreyvit committed Nov 18, 2011
1 parent f4b58ef commit 0b09531
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 3 deletions.
13 changes: 13 additions & 0 deletions src/less.coffee
@@ -0,0 +1,13 @@

module.exports = class LessPlugin
@identifier = 'less'

constructor: (@window, @host) ->

reload: (path, options) ->
if path.match(/\.less$/i) and @window.less and @window.less.refresh
@window.less.refresh(true)
return

analyze: ->
{ disable: !!(@window.less and @window.less.refresh) }
16 changes: 16 additions & 0 deletions src/livereload.coffee
Expand Up @@ -7,6 +7,7 @@ exports.LiveReload = class LiveReload

constructor: (@window) ->
@listeners = {}
@plugins = []

# i can haz console?
@console = if @window.console && @window.console.log && @window.console.error
Expand Down Expand Up @@ -84,3 +85,18 @@ exports.LiveReload = class LiveReload
@connector.disconnect()
@log "LiveReload disconnected."
@listeners.shutdown?()

addPlugin: (pluginClass) ->
plugin = new pluginClass @window,

# expose internal objects for those who know what they're doing
# (note that these are private APIs and subject to change!)
_livereload: this
_reloader: @reloader
_connector: @connector

# official API
generateCacheBustUrl: (url) -> @reloader.generateCacheBustUrl(url)

@plugins.push plugin
return
15 changes: 12 additions & 3 deletions src/reloader.coffee
Expand Up @@ -65,15 +65,24 @@ exports.Reloader = class Reloader
@document = @window.document
@stylesheetGracePeriod = 200
@importCacheWaitPeriod = 200
@plugins = []


addPlugin: (plugin) ->
@plugins.push plugin


analyze: (callback) ->
results


reload: (path, options) ->
for plugin in @plugins
if plugin.reload && plugin.reload(path, options)
return
if options.liveCSS
if path.match(/\.css$/i)
return if @reloadStylesheet(path)
if path.match(/\.less$/i) and @window.less and @window.less.refresh
@window.less.refresh(true)
return
if options.liveImg
if path.match(/\.(jpe?g|png|gif)$/i)
@reloadImages(path)
Expand Down
2 changes: 2 additions & 0 deletions src/startup.coffee
@@ -1,6 +1,8 @@
CustomEvents = require('customevents')
LiveReload = window.LiveReload = new (require('livereload').LiveReload)(window)

LiveReload.addPlugin require('less')

LiveReload.on 'shutdown', -> delete window.LiveReload
LiveReload.on 'connect', ->
CustomEvents.fire document, 'LiveReloadConnect'
Expand Down

0 comments on commit 0b09531

Please sign in to comment.