Permalink
Browse files

Allow including LiveReload from arbitrary URLs

  • Loading branch information...
1 parent 0fdd224 commit 0b0b8a90ca9e75d2c52d1e97a01082a1cd29cd6d @andreyvit andreyvit committed Oct 16, 2011
Showing with 23 additions and 6 deletions.
  1. +8 −6 src/options.coffee
  2. +15 −0 test/options_test.coffee
View
@@ -2,7 +2,7 @@
exports.Options = class Options
constructor: ->
@host = null
- @port = null
+ @port = 35729
@snipver = null
@ext = null
@@ -22,13 +22,15 @@ exports.Options = class Options
Options.extract = (document) ->
for element in document.getElementsByTagName('script')
- if (src = element.src) && (m = src.match ///^ https?:// ([^/:]+) : (\d+) / z?livereload\.js (?: \? (.*) )? $///)
+ if (src = element.src) && (m = src.match ///^ [^:]+ :// (.*) / z?livereload\.js (?: \? (.*) )? $///)
options = new Options()
- options.host = m[1]
- options.port = parseInt(m[2], 10)
+ if mm = m[1].match ///^ ([^/:]+) (?: : (\d+) )? $///
+ options.host = mm[1]
+ if mm[2]
+ options.port = parseInt(mm[2], 10)
- if m[3]
- for pair in m[3].split('&')
+ if m[2]
+ for pair in m[2].split('&')
if (keyAndValue = pair.split('=')).length > 1
options.set keyAndValue[0].replace(/-/g, '_'), keyAndValue.slice(1).join('=')
return options
View
@@ -66,3 +66,18 @@ exports['should extract additional options'] = (beforeExit, assert) ->
assert.equal '2.0', options.extver
beforeExit -> assert.ok _loaded
+
+
+exports['should be cool with a strange URL'] = (beforeExit, assert) ->
+ _loaded = no
+ jsdom.env """
+ <script src="safari-ext://132324324/23243443/4343/livereload.js?host=somewhere.com"></script>
+ """, [], (errors, window) ->
+ assert.isNull errors
+ _loaded = yes
+
+ options = Options.extract(window.document)
+ assert.equal 'somewhere.com', options.host
+ assert.equal 35729, options.port
+
+ beforeExit -> assert.ok _loaded

0 comments on commit 0b0b8a9

Please sign in to comment.