Skip to content
Browse files

Full support for third-party plugins

  • Loading branch information...
1 parent 7db3e32 commit 224b1f98febd730853de839b5df6f37f684ba117 @andreyvit andreyvit committed Nov 18, 2011
Showing with 15 additions and 0 deletions.
  1. +6 −0 src/livereload.coffee
  2. +4 −0 src/startup.coffee
  3. +5 −0 test/html/lessjs/test.html
View
6 src/livereload.coffee
@@ -8,6 +8,7 @@ exports.LiveReload = class LiveReload
constructor: (@window) ->
@listeners = {}
@plugins = []
+ @pluginIdentifiers = {}
# i can haz console?
@console = if @window.console && @window.console.log && @window.console.error
@@ -87,7 +88,12 @@ exports.LiveReload = class LiveReload
@log "LiveReload disconnected."
@listeners.shutdown?()
+ hasPlugin: (identifier) -> !!@pluginIdentifiers[identifier]
+
addPlugin: (pluginClass) ->
+ return if @hasPlugin(pluginClass.identifier)
+ @pluginIdentifiers[pluginClass.identifier] = yes
+
plugin = new pluginClass @window,
# expose internal objects for those who know what they're doing
View
4 src/startup.coffee
@@ -1,6 +1,10 @@
CustomEvents = require('customevents')
LiveReload = window.LiveReload = new (require('livereload').LiveReload)(window)
+for k, v of window
+ if k.match(/^LiveReloadPlugin/)
+ LiveReload.addPlugin v
+
LiveReload.addPlugin require('less')
LiveReload.on 'shutdown', -> delete window.LiveReload
View
5 test/html/lessjs/test.html
@@ -7,6 +7,11 @@
</head>
<body>
<h1>Less.js In-Browser Test</h1>
+ <script>
+ LiveReloadPluginFoo = function() {};
+ LiveReloadPluginFoo.identifier = 'foo';
+ LiveReloadPluginFoo.version = '2.0';
+ </script>
<script src="../../../dist/livereload.js?host=localhost" async defer></script>
</body>
</html>

0 comments on commit 224b1f9

Please sign in to comment.
Something went wrong with that request. Please try again.