adsf-live 1.5.0 → 1.5.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/adsf/live/rack_livereload.rb +74 -0
- data/lib/adsf/live/version.rb +1 -1
- data/lib/adsf/live/web_socket_server.rb +1 -1
- data/lib/adsf/live.rb +1 -1
- data/vendor/livereload.js +1058 -0
- metadata +5 -17
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e4220f4fee4eee180d5040729b4839845bca8a28281e2c791f1c6432038511a9
|
4
|
+
data.tar.gz: f1d377a375fb78e668c2c3e807460e67ce1bcc54598f8a3bde764be370f8fd74
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5d6b6d34d7eb8f907845b6d028ef25c2aa38a754268fcf2331d52cc0de13fad1f4b2f920665c803da3c3ddad43c6999e59300ea1b7d8ce16a03edbfd99f6addd
|
7
|
+
data.tar.gz: 4e7a31fc49e21d5fb1c1f6cad47be74b78f2c55bd8493c0ff322156014d1d08ae5babb1072e3e97a39d0fcee403dadcb89b5e58a440350e671853a509957e097
|
@@ -0,0 +1,74 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Rack
|
4
|
+
class LiveReload
|
5
|
+
LIVERELOAD_JS_PATH = '/__rack/livereload.js'
|
6
|
+
VENDORED_JS_PATH = "#{__dir__}/../../../vendor/livereload.js"
|
7
|
+
HEAD_TAG_REGEX = /<head( [^<]+)?>/.freeze
|
8
|
+
LIVERELOAD_PORT = 35_729
|
9
|
+
LIVERELOAD_SCHEME = 'ws'
|
10
|
+
|
11
|
+
def initialize(app, options = {})
|
12
|
+
@app = app
|
13
|
+
@options = options
|
14
|
+
end
|
15
|
+
|
16
|
+
def call(env)
|
17
|
+
return deliver_file(VENDORED_JS_PATH) if env['PATH_INFO']&.end_with? LIVERELOAD_JS_PATH
|
18
|
+
|
19
|
+
status, headers, body = result = @app.call(env)
|
20
|
+
|
21
|
+
if env['REQUEST_METHOD'] != 'GET' ||
|
22
|
+
headers['content-type'] !~ %r{text/html} ||
|
23
|
+
headers['transfer-encoding'] == 'chunked' ||
|
24
|
+
headers['content-disposition'] =~ /^inline/
|
25
|
+
return result
|
26
|
+
end
|
27
|
+
|
28
|
+
body.close if body.respond_to?(:close)
|
29
|
+
new_body = []
|
30
|
+
livereload_added = false
|
31
|
+
@env = env
|
32
|
+
body.each do |line|
|
33
|
+
if !livereload_added && line =~ HEAD_TAG_REGEX
|
34
|
+
new_body << line.sub(HEAD_TAG_REGEX) { |match| %(#{match}#{template}) }
|
35
|
+
livereload_added = true
|
36
|
+
else
|
37
|
+
new_body << line
|
38
|
+
end
|
39
|
+
end
|
40
|
+
headers['content-length'] = new_body.sum(&:bytesize).to_s
|
41
|
+
headers['x-rack-livereload'] = '1' if livereload_added
|
42
|
+
|
43
|
+
[status, headers, new_body]
|
44
|
+
end
|
45
|
+
|
46
|
+
private
|
47
|
+
|
48
|
+
def deliver_file(file)
|
49
|
+
[200, { 'content-type' => 'text/javascript', 'content-length' => ::File.size(file).to_s }, [::File.read(file)]]
|
50
|
+
end
|
51
|
+
|
52
|
+
def template
|
53
|
+
<<~HTML
|
54
|
+
<script>
|
55
|
+
RACK_LIVERELOAD_PORT = #{@options[:live_reload_port] || LIVERELOAD_PORT}
|
56
|
+
RACK_LIVERELOAD_SCHEME = "#{@options[:live_reload_scheme] || LIVERELOAD_SCHEME}"
|
57
|
+
</script>
|
58
|
+
<script src="#{livereload_source}?host=#{host_to_use}"></script>
|
59
|
+
HTML
|
60
|
+
end
|
61
|
+
|
62
|
+
def livereload_source
|
63
|
+
if @options[:source] == :vendored
|
64
|
+
LIVERELOAD_JS_PATH
|
65
|
+
else
|
66
|
+
"#{@options[:protocol] || 'http'}://#{host_to_use}/livereload.js"
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
def host_to_use
|
71
|
+
(@options[:host] || @env['HTTP_HOST'] || 'localhost').sub(/:.*/, '')
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
data/lib/adsf/live/version.rb
CHANGED
data/lib/adsf/live.rb
CHANGED
@@ -5,7 +5,6 @@ require 'eventmachine'
|
|
5
5
|
require 'em-websocket'
|
6
6
|
require 'json'
|
7
7
|
require 'listen'
|
8
|
-
require 'rack-livereload'
|
9
8
|
|
10
9
|
module Adsf
|
11
10
|
module Live
|
@@ -13,5 +12,6 @@ module Adsf
|
|
13
12
|
end
|
14
13
|
|
15
14
|
require_relative 'live/version'
|
15
|
+
require_relative 'live/rack_livereload'
|
16
16
|
require_relative 'live/web_socket_server'
|
17
17
|
require_relative 'live/watcher'
|
@@ -0,0 +1,1058 @@
|
|
1
|
+
(function() {
|
2
|
+
var __customevents = {}, __protocol = {}, __connector = {}, __timer = {}, __options = {}, __reloader = {}, __livereload = {}, __less = {}, __startup = {};
|
3
|
+
|
4
|
+
// customevents
|
5
|
+
var CustomEvents;
|
6
|
+
CustomEvents = {
|
7
|
+
bind: function(element, eventName, handler) {
|
8
|
+
if (element.addEventListener) {
|
9
|
+
return element.addEventListener(eventName, handler, false);
|
10
|
+
} else if (element.attachEvent) {
|
11
|
+
element[eventName] = 1;
|
12
|
+
return element.attachEvent('onpropertychange', function(event) {
|
13
|
+
if (event.propertyName === eventName) {
|
14
|
+
return handler();
|
15
|
+
}
|
16
|
+
});
|
17
|
+
} else {
|
18
|
+
throw new Error("Attempt to attach custom event " + eventName + " to something which isn't a DOMElement");
|
19
|
+
}
|
20
|
+
},
|
21
|
+
fire: function(element, eventName) {
|
22
|
+
var event;
|
23
|
+
if (element.addEventListener) {
|
24
|
+
event = document.createEvent('HTMLEvents');
|
25
|
+
event.initEvent(eventName, true, true);
|
26
|
+
return document.dispatchEvent(event);
|
27
|
+
} else if (element.attachEvent) {
|
28
|
+
if (element[eventName]) {
|
29
|
+
return element[eventName]++;
|
30
|
+
}
|
31
|
+
} else {
|
32
|
+
throw new Error("Attempt to fire custom event " + eventName + " on something which isn't a DOMElement");
|
33
|
+
}
|
34
|
+
}
|
35
|
+
};
|
36
|
+
__customevents.bind = CustomEvents.bind;
|
37
|
+
__customevents.fire = CustomEvents.fire;
|
38
|
+
|
39
|
+
// protocol
|
40
|
+
var PROTOCOL_6, PROTOCOL_7, Parser, ProtocolError;
|
41
|
+
var __indexOf = Array.prototype.indexOf || function(item) {
|
42
|
+
for (var i = 0, l = this.length; i < l; i++) {
|
43
|
+
if (this[i] === item) return i;
|
44
|
+
}
|
45
|
+
return -1;
|
46
|
+
};
|
47
|
+
__protocol.PROTOCOL_6 = PROTOCOL_6 = 'http://livereload.com/protocols/official-6';
|
48
|
+
__protocol.PROTOCOL_7 = PROTOCOL_7 = 'http://livereload.com/protocols/official-7';
|
49
|
+
__protocol.ProtocolError = ProtocolError = (function() {
|
50
|
+
function ProtocolError(reason, data) {
|
51
|
+
this.message = "LiveReload protocol error (" + reason + ") after receiving data: \"" + data + "\".";
|
52
|
+
}
|
53
|
+
return ProtocolError;
|
54
|
+
})();
|
55
|
+
__protocol.Parser = Parser = (function() {
|
56
|
+
function Parser(handlers) {
|
57
|
+
this.handlers = handlers;
|
58
|
+
this.reset();
|
59
|
+
}
|
60
|
+
Parser.prototype.reset = function() {
|
61
|
+
return this.protocol = null;
|
62
|
+
};
|
63
|
+
Parser.prototype.process = function(data) {
|
64
|
+
var command, message, options, _ref;
|
65
|
+
try {
|
66
|
+
if (!(this.protocol != null)) {
|
67
|
+
if (data.match(/^!!ver:([\d.]+)$/)) {
|
68
|
+
this.protocol = 6;
|
69
|
+
} else if (message = this._parseMessage(data, ['hello'])) {
|
70
|
+
if (!message.protocols.length) {
|
71
|
+
throw new ProtocolError("no protocols specified in handshake message");
|
72
|
+
} else if (__indexOf.call(message.protocols, PROTOCOL_7) >= 0) {
|
73
|
+
this.protocol = 7;
|
74
|
+
} else if (__indexOf.call(message.protocols, PROTOCOL_6) >= 0) {
|
75
|
+
this.protocol = 6;
|
76
|
+
} else {
|
77
|
+
throw new ProtocolError("no supported protocols found");
|
78
|
+
}
|
79
|
+
}
|
80
|
+
return this.handlers.connected(this.protocol);
|
81
|
+
} else if (this.protocol === 6) {
|
82
|
+
message = JSON.parse(data);
|
83
|
+
if (!message.length) {
|
84
|
+
throw new ProtocolError("protocol 6 messages must be arrays");
|
85
|
+
}
|
86
|
+
command = message[0], options = message[1];
|
87
|
+
if (command !== 'refresh') {
|
88
|
+
throw new ProtocolError("unknown protocol 6 command");
|
89
|
+
}
|
90
|
+
return this.handlers.message({
|
91
|
+
command: 'reload',
|
92
|
+
path: options.path,
|
93
|
+
liveCSS: (_ref = options.apply_css_live) != null ? _ref : true
|
94
|
+
});
|
95
|
+
} else {
|
96
|
+
message = this._parseMessage(data, ['reload', 'alert']);
|
97
|
+
return this.handlers.message(message);
|
98
|
+
}
|
99
|
+
} catch (e) {
|
100
|
+
if (e instanceof ProtocolError) {
|
101
|
+
return this.handlers.error(e);
|
102
|
+
} else {
|
103
|
+
throw e;
|
104
|
+
}
|
105
|
+
}
|
106
|
+
};
|
107
|
+
Parser.prototype._parseMessage = function(data, validCommands) {
|
108
|
+
var message, _ref;
|
109
|
+
try {
|
110
|
+
message = JSON.parse(data);
|
111
|
+
} catch (e) {
|
112
|
+
throw new ProtocolError('unparsable JSON', data);
|
113
|
+
}
|
114
|
+
if (!message.command) {
|
115
|
+
throw new ProtocolError('missing "command" key', data);
|
116
|
+
}
|
117
|
+
if (_ref = message.command, __indexOf.call(validCommands, _ref) < 0) {
|
118
|
+
throw new ProtocolError("invalid command '" + message.command + "', only valid commands are: " + (validCommands.join(', ')) + ")", data);
|
119
|
+
}
|
120
|
+
return message;
|
121
|
+
};
|
122
|
+
return Parser;
|
123
|
+
})();
|
124
|
+
|
125
|
+
// connector
|
126
|
+
// Generated by CoffeeScript 1.3.3
|
127
|
+
var Connector, PROTOCOL_6, PROTOCOL_7, Parser, Version, _ref;
|
128
|
+
|
129
|
+
_ref = __protocol, Parser = _ref.Parser, PROTOCOL_6 = _ref.PROTOCOL_6, PROTOCOL_7 = _ref.PROTOCOL_7;
|
130
|
+
|
131
|
+
Version = '2.0.8';
|
132
|
+
|
133
|
+
__connector.Connector = Connector = (function() {
|
134
|
+
|
135
|
+
function Connector(options, WebSocket, Timer, handlers) {
|
136
|
+
var _this = this;
|
137
|
+
this.options = options;
|
138
|
+
this.WebSocket = WebSocket;
|
139
|
+
this.Timer = Timer;
|
140
|
+
this.handlers = handlers;
|
141
|
+
this._uri = this.options.scheme + "://" + this.options.host + ":" + this.options.port + "/livereload";
|
142
|
+
this._nextDelay = this.options.mindelay;
|
143
|
+
this._connectionDesired = false;
|
144
|
+
this.protocol = 0;
|
145
|
+
this.protocolParser = new Parser({
|
146
|
+
connected: function(protocol) {
|
147
|
+
_this.protocol = protocol;
|
148
|
+
_this._handshakeTimeout.stop();
|
149
|
+
_this._nextDelay = _this.options.mindelay;
|
150
|
+
_this._disconnectionReason = 'broken';
|
151
|
+
return _this.handlers.connected(protocol);
|
152
|
+
},
|
153
|
+
error: function(e) {
|
154
|
+
_this.handlers.error(e);
|
155
|
+
return _this._closeOnError();
|
156
|
+
},
|
157
|
+
message: function(message) {
|
158
|
+
return _this.handlers.message(message);
|
159
|
+
}
|
160
|
+
});
|
161
|
+
this._handshakeTimeout = new Timer(function() {
|
162
|
+
if (!_this._isSocketConnected()) {
|
163
|
+
return;
|
164
|
+
}
|
165
|
+
_this._disconnectionReason = 'handshake-timeout';
|
166
|
+
return _this.socket.close();
|
167
|
+
});
|
168
|
+
this._reconnectTimer = new Timer(function() {
|
169
|
+
if (!_this._connectionDesired) {
|
170
|
+
return;
|
171
|
+
}
|
172
|
+
return _this.connect();
|
173
|
+
});
|
174
|
+
this.connect();
|
175
|
+
}
|
176
|
+
|
177
|
+
Connector.prototype._isSocketConnected = function() {
|
178
|
+
return this.socket && this.socket.readyState === this.WebSocket.OPEN;
|
179
|
+
};
|
180
|
+
|
181
|
+
Connector.prototype.connect = function() {
|
182
|
+
var _this = this;
|
183
|
+
this._connectionDesired = true;
|
184
|
+
if (this._isSocketConnected()) {
|
185
|
+
return;
|
186
|
+
}
|
187
|
+
this._reconnectTimer.stop();
|
188
|
+
this._disconnectionReason = 'cannot-connect';
|
189
|
+
this.protocolParser.reset();
|
190
|
+
this.handlers.connecting();
|
191
|
+
this.socket = new this.WebSocket(this._uri);
|
192
|
+
this.socket.onopen = function(e) {
|
193
|
+
return _this._onopen(e);
|
194
|
+
};
|
195
|
+
this.socket.onclose = function(e) {
|
196
|
+
return _this._onclose(e);
|
197
|
+
};
|
198
|
+
this.socket.onmessage = function(e) {
|
199
|
+
return _this._onmessage(e);
|
200
|
+
};
|
201
|
+
return this.socket.onerror = function(e) {
|
202
|
+
return _this._onerror(e);
|
203
|
+
};
|
204
|
+
};
|
205
|
+
|
206
|
+
Connector.prototype.disconnect = function() {
|
207
|
+
this._connectionDesired = false;
|
208
|
+
this._reconnectTimer.stop();
|
209
|
+
if (!this._isSocketConnected()) {
|
210
|
+
return;
|
211
|
+
}
|
212
|
+
this._disconnectionReason = 'manual';
|
213
|
+
return this.socket.close();
|
214
|
+
};
|
215
|
+
|
216
|
+
Connector.prototype._scheduleReconnection = function() {
|
217
|
+
if (!this._connectionDesired) {
|
218
|
+
return;
|
219
|
+
}
|
220
|
+
if (!this._reconnectTimer.running) {
|
221
|
+
this._reconnectTimer.start(this._nextDelay);
|
222
|
+
return this._nextDelay = Math.min(this.options.maxdelay, this._nextDelay * 2);
|
223
|
+
}
|
224
|
+
};
|
225
|
+
|
226
|
+
Connector.prototype.sendCommand = function(command) {
|
227
|
+
if (this.protocol == null) {
|
228
|
+
return;
|
229
|
+
}
|
230
|
+
return this._sendCommand(command);
|
231
|
+
};
|
232
|
+
|
233
|
+
Connector.prototype._sendCommand = function(command) {
|
234
|
+
return this.socket.send(JSON.stringify(command));
|
235
|
+
};
|
236
|
+
|
237
|
+
Connector.prototype._closeOnError = function() {
|
238
|
+
this._handshakeTimeout.stop();
|
239
|
+
this._disconnectionReason = 'error';
|
240
|
+
return this.socket.close();
|
241
|
+
};
|
242
|
+
|
243
|
+
Connector.prototype._onopen = function(e) {
|
244
|
+
var hello;
|
245
|
+
this.handlers.socketConnected();
|
246
|
+
this._disconnectionReason = 'handshake-failed';
|
247
|
+
hello = {
|
248
|
+
command: 'hello',
|
249
|
+
protocols: [PROTOCOL_6, PROTOCOL_7]
|
250
|
+
};
|
251
|
+
hello.ver = Version;
|
252
|
+
if (this.options.ext) {
|
253
|
+
hello.ext = this.options.ext;
|
254
|
+
}
|
255
|
+
if (this.options.extver) {
|
256
|
+
hello.extver = this.options.extver;
|
257
|
+
}
|
258
|
+
if (this.options.snipver) {
|
259
|
+
hello.snipver = this.options.snipver;
|
260
|
+
}
|
261
|
+
this._sendCommand(hello);
|
262
|
+
return this._handshakeTimeout.start(this.options.handshake_timeout);
|
263
|
+
};
|
264
|
+
|
265
|
+
Connector.prototype._onclose = function(e) {
|
266
|
+
this.protocol = 0;
|
267
|
+
this.handlers.disconnected(this._disconnectionReason, this._nextDelay);
|
268
|
+
return this._scheduleReconnection();
|
269
|
+
};
|
270
|
+
|
271
|
+
Connector.prototype._onerror = function(e) {};
|
272
|
+
|
273
|
+
Connector.prototype._onmessage = function(e) {
|
274
|
+
return this.protocolParser.process(e.data);
|
275
|
+
};
|
276
|
+
|
277
|
+
return Connector;
|
278
|
+
|
279
|
+
})();
|
280
|
+
|
281
|
+
// timer
|
282
|
+
var Timer;
|
283
|
+
var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };
|
284
|
+
__timer.Timer = Timer = (function() {
|
285
|
+
function Timer(func) {
|
286
|
+
this.func = func;
|
287
|
+
this.running = false;
|
288
|
+
this.id = null;
|
289
|
+
this._handler = __bind(function() {
|
290
|
+
this.running = false;
|
291
|
+
this.id = null;
|
292
|
+
return this.func();
|
293
|
+
}, this);
|
294
|
+
}
|
295
|
+
Timer.prototype.start = function(timeout) {
|
296
|
+
if (this.running) {
|
297
|
+
clearTimeout(this.id);
|
298
|
+
}
|
299
|
+
this.id = setTimeout(this._handler, timeout);
|
300
|
+
return this.running = true;
|
301
|
+
};
|
302
|
+
Timer.prototype.stop = function() {
|
303
|
+
if (this.running) {
|
304
|
+
clearTimeout(this.id);
|
305
|
+
this.running = false;
|
306
|
+
return this.id = null;
|
307
|
+
}
|
308
|
+
};
|
309
|
+
return Timer;
|
310
|
+
})();
|
311
|
+
Timer.start = function(timeout, func) {
|
312
|
+
return setTimeout(func, timeout);
|
313
|
+
};
|
314
|
+
|
315
|
+
// options
|
316
|
+
var Options;
|
317
|
+
__options.Options = Options = (function() {
|
318
|
+
function Options() {
|
319
|
+
this.host = null;
|
320
|
+
this.port = RACK_LIVERELOAD_PORT;
|
321
|
+
this.scheme = RACK_LIVERELOAD_SCHEME;
|
322
|
+
this.snipver = null;
|
323
|
+
this.ext = null;
|
324
|
+
this.extver = null;
|
325
|
+
this.mindelay = 1000;
|
326
|
+
this.maxdelay = 60000;
|
327
|
+
this.handshake_timeout = 5000;
|
328
|
+
}
|
329
|
+
Options.prototype.set = function(name, value) {
|
330
|
+
switch (typeof this[name]) {
|
331
|
+
case 'undefined':
|
332
|
+
break;
|
333
|
+
case 'number':
|
334
|
+
return this[name] = +value;
|
335
|
+
default:
|
336
|
+
return this[name] = value;
|
337
|
+
}
|
338
|
+
};
|
339
|
+
return Options;
|
340
|
+
})();
|
341
|
+
Options.extract = function(document) {
|
342
|
+
var element, keyAndValue, m, mm, options, pair, src, _i, _j, _len, _len2, _ref, _ref2;
|
343
|
+
_ref = document.getElementsByTagName('script');
|
344
|
+
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
345
|
+
element = _ref[_i];
|
346
|
+
if ((src = element.src) && (m = src.match(/^[^:]+:\/\/(.*)\/z?livereload\.js(?:\?(.*))?$/))) {
|
347
|
+
options = new Options();
|
348
|
+
if (mm = m[1].match(/^([^\/:]+)(?::(\d+))?$/)) {
|
349
|
+
options.host = mm[1];
|
350
|
+
if (mm[2]) {
|
351
|
+
options.port = parseInt(mm[2], 10);
|
352
|
+
}
|
353
|
+
}
|
354
|
+
if (m[2]) {
|
355
|
+
_ref2 = m[2].split('&');
|
356
|
+
for (_j = 0, _len2 = _ref2.length; _j < _len2; _j++) {
|
357
|
+
pair = _ref2[_j];
|
358
|
+
if ((keyAndValue = pair.split('=')).length > 1) {
|
359
|
+
options.set(keyAndValue[0].replace(/-/g, '_'), keyAndValue.slice(1).join('='));
|
360
|
+
}
|
361
|
+
}
|
362
|
+
}
|
363
|
+
return options;
|
364
|
+
}
|
365
|
+
}
|
366
|
+
return null;
|
367
|
+
};
|
368
|
+
|
369
|
+
// reloader
|
370
|
+
// Generated by CoffeeScript 1.3.1
|
371
|
+
(function() {
|
372
|
+
var IMAGE_STYLES, Reloader, numberOfMatchingSegments, pathFromUrl, pathsMatch, pickBestMatch, splitUrl;
|
373
|
+
|
374
|
+
splitUrl = function(url) {
|
375
|
+
var hash, index, params;
|
376
|
+
if ((index = url.indexOf('#')) >= 0) {
|
377
|
+
hash = url.slice(index);
|
378
|
+
url = url.slice(0, index);
|
379
|
+
} else {
|
380
|
+
hash = '';
|
381
|
+
}
|
382
|
+
if ((index = url.indexOf('?')) >= 0) {
|
383
|
+
params = url.slice(index);
|
384
|
+
url = url.slice(0, index);
|
385
|
+
} else {
|
386
|
+
params = '';
|
387
|
+
}
|
388
|
+
return {
|
389
|
+
url: url,
|
390
|
+
params: params,
|
391
|
+
hash: hash
|
392
|
+
};
|
393
|
+
};
|
394
|
+
|
395
|
+
pathFromUrl = function(url) {
|
396
|
+
var path;
|
397
|
+
url = splitUrl(url).url;
|
398
|
+
if (url.indexOf('file://') === 0) {
|
399
|
+
path = url.replace(/^file:\/\/(localhost)?/, '');
|
400
|
+
} else {
|
401
|
+
path = url.replace(/^([^:]+:)?\/\/([^:\/]+)(:\d*)?\//, '/');
|
402
|
+
}
|
403
|
+
return decodeURIComponent(path);
|
404
|
+
};
|
405
|
+
|
406
|
+
pickBestMatch = function(path, objects, pathFunc) {
|
407
|
+
var bestMatch, object, score, _i, _len;
|
408
|
+
bestMatch = {
|
409
|
+
score: 0
|
410
|
+
};
|
411
|
+
for (_i = 0, _len = objects.length; _i < _len; _i++) {
|
412
|
+
object = objects[_i];
|
413
|
+
score = numberOfMatchingSegments(path, pathFunc(object));
|
414
|
+
if (score > bestMatch.score) {
|
415
|
+
bestMatch = {
|
416
|
+
object: object,
|
417
|
+
score: score
|
418
|
+
};
|
419
|
+
}
|
420
|
+
}
|
421
|
+
if (bestMatch.score > 0) {
|
422
|
+
return bestMatch;
|
423
|
+
} else {
|
424
|
+
return null;
|
425
|
+
}
|
426
|
+
};
|
427
|
+
|
428
|
+
numberOfMatchingSegments = function(path1, path2) {
|
429
|
+
var comps1, comps2, eqCount, len;
|
430
|
+
path1 = path1.replace(/^\/+/, '').toLowerCase();
|
431
|
+
path2 = path2.replace(/^\/+/, '').toLowerCase();
|
432
|
+
if (path1 === path2) {
|
433
|
+
return 10000;
|
434
|
+
}
|
435
|
+
comps1 = path1.split('/').reverse();
|
436
|
+
comps2 = path2.split('/').reverse();
|
437
|
+
len = Math.min(comps1.length, comps2.length);
|
438
|
+
eqCount = 0;
|
439
|
+
while (eqCount < len && comps1[eqCount] === comps2[eqCount]) {
|
440
|
+
++eqCount;
|
441
|
+
}
|
442
|
+
return eqCount;
|
443
|
+
};
|
444
|
+
|
445
|
+
pathsMatch = function(path1, path2) {
|
446
|
+
return numberOfMatchingSegments(path1, path2) > 0;
|
447
|
+
};
|
448
|
+
|
449
|
+
IMAGE_STYLES = [
|
450
|
+
{
|
451
|
+
selector: 'background',
|
452
|
+
styleNames: ['backgroundImage']
|
453
|
+
}, {
|
454
|
+
selector: 'border',
|
455
|
+
styleNames: ['borderImage', 'webkitBorderImage', 'MozBorderImage']
|
456
|
+
}
|
457
|
+
];
|
458
|
+
|
459
|
+
__reloader.Reloader = Reloader = (function() {
|
460
|
+
|
461
|
+
Reloader.name = 'Reloader';
|
462
|
+
|
463
|
+
function Reloader(window, console, Timer) {
|
464
|
+
this.window = window;
|
465
|
+
this.console = console;
|
466
|
+
this.Timer = Timer;
|
467
|
+
this.document = this.window.document;
|
468
|
+
this.importCacheWaitPeriod = 200;
|
469
|
+
this.plugins = [];
|
470
|
+
}
|
471
|
+
|
472
|
+
Reloader.prototype.addPlugin = function(plugin) {
|
473
|
+
return this.plugins.push(plugin);
|
474
|
+
};
|
475
|
+
|
476
|
+
Reloader.prototype.analyze = function(callback) {
|
477
|
+
return results;
|
478
|
+
};
|
479
|
+
|
480
|
+
Reloader.prototype.reload = function(path, options) {
|
481
|
+
var plugin, _base, _i, _len, _ref;
|
482
|
+
this.options = options;
|
483
|
+
if ((_base = this.options).stylesheetReloadTimeout == null) {
|
484
|
+
_base.stylesheetReloadTimeout = 15000;
|
485
|
+
}
|
486
|
+
_ref = this.plugins;
|
487
|
+
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
488
|
+
plugin = _ref[_i];
|
489
|
+
if (plugin.reload && plugin.reload(path, options)) {
|
490
|
+
return;
|
491
|
+
}
|
492
|
+
}
|
493
|
+
if (options.liveCSS) {
|
494
|
+
if (path.match(/\.css$/i)) {
|
495
|
+
if (this.reloadStylesheet(path)) {
|
496
|
+
return;
|
497
|
+
}
|
498
|
+
}
|
499
|
+
}
|
500
|
+
if (options.liveImg) {
|
501
|
+
if (path.match(/\.(jpe?g|png|gif)$/i)) {
|
502
|
+
this.reloadImages(path);
|
503
|
+
return;
|
504
|
+
}
|
505
|
+
}
|
506
|
+
var current_path= document.location.pathname // Only reload the page if we need to
|
507
|
+
if (path === current_path || path === current_path+'index.html')
|
508
|
+
return this.reloadPage();
|
509
|
+
};
|
510
|
+
|
511
|
+
Reloader.prototype.reloadPage = function() {
|
512
|
+
return this.window.document.location.reload();
|
513
|
+
};
|
514
|
+
|
515
|
+
Reloader.prototype.reloadImages = function(path) {
|
516
|
+
var expando, img, selector, styleNames, styleSheet, _i, _j, _k, _l, _len, _len1, _len2, _len3, _ref, _ref1, _ref2, _ref3, _results;
|
517
|
+
expando = this.generateUniqueString();
|
518
|
+
_ref = this.document.images;
|
519
|
+
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
520
|
+
img = _ref[_i];
|
521
|
+
if (pathsMatch(path, pathFromUrl(img.src))) {
|
522
|
+
img.src = this.generateCacheBustUrl(img.src, expando);
|
523
|
+
}
|
524
|
+
}
|
525
|
+
if (this.document.querySelectorAll) {
|
526
|
+
for (_j = 0, _len1 = IMAGE_STYLES.length; _j < _len1; _j++) {
|
527
|
+
_ref1 = IMAGE_STYLES[_j], selector = _ref1.selector, styleNames = _ref1.styleNames;
|
528
|
+
_ref2 = this.document.querySelectorAll("[style*=" + selector + "]");
|
529
|
+
for (_k = 0, _len2 = _ref2.length; _k < _len2; _k++) {
|
530
|
+
img = _ref2[_k];
|
531
|
+
this.reloadStyleImages(img.style, styleNames, path, expando);
|
532
|
+
}
|
533
|
+
}
|
534
|
+
}
|
535
|
+
if (this.document.styleSheets) {
|
536
|
+
_ref3 = this.document.styleSheets;
|
537
|
+
_results = [];
|
538
|
+
for (_l = 0, _len3 = _ref3.length; _l < _len3; _l++) {
|
539
|
+
styleSheet = _ref3[_l];
|
540
|
+
_results.push(this.reloadStylesheetImages(styleSheet, path, expando));
|
541
|
+
}
|
542
|
+
return _results;
|
543
|
+
}
|
544
|
+
};
|
545
|
+
|
546
|
+
Reloader.prototype.reloadStylesheetImages = function(styleSheet, path, expando) {
|
547
|
+
var rule, rules, styleNames, _i, _j, _len, _len1;
|
548
|
+
try {
|
549
|
+
rules = styleSheet != null ? styleSheet.cssRules : void 0;
|
550
|
+
} catch (e) {
|
551
|
+
|
552
|
+
}
|
553
|
+
if (!rules) {
|
554
|
+
return;
|
555
|
+
}
|
556
|
+
for (_i = 0, _len = rules.length; _i < _len; _i++) {
|
557
|
+
rule = rules[_i];
|
558
|
+
switch (rule.type) {
|
559
|
+
case CSSRule.IMPORT_RULE:
|
560
|
+
this.reloadStylesheetImages(rule.styleSheet, path, expando);
|
561
|
+
break;
|
562
|
+
case CSSRule.STYLE_RULE:
|
563
|
+
for (_j = 0, _len1 = IMAGE_STYLES.length; _j < _len1; _j++) {
|
564
|
+
styleNames = IMAGE_STYLES[_j].styleNames;
|
565
|
+
this.reloadStyleImages(rule.style, styleNames, path, expando);
|
566
|
+
}
|
567
|
+
break;
|
568
|
+
case CSSRule.MEDIA_RULE:
|
569
|
+
this.reloadStylesheetImages(rule, path, expando);
|
570
|
+
}
|
571
|
+
}
|
572
|
+
};
|
573
|
+
|
574
|
+
Reloader.prototype.reloadStyleImages = function(style, styleNames, path, expando) {
|
575
|
+
var newValue, styleName, value, _i, _len,
|
576
|
+
_this = this;
|
577
|
+
for (_i = 0, _len = styleNames.length; _i < _len; _i++) {
|
578
|
+
styleName = styleNames[_i];
|
579
|
+
value = style[styleName];
|
580
|
+
if (typeof value === 'string') {
|
581
|
+
newValue = value.replace(/\burl\s*\(([^)]*)\)/, function(match, src) {
|
582
|
+
if (pathsMatch(path, pathFromUrl(src))) {
|
583
|
+
return "url(" + (_this.generateCacheBustUrl(src, expando)) + ")";
|
584
|
+
} else {
|
585
|
+
return match;
|
586
|
+
}
|
587
|
+
});
|
588
|
+
if (newValue !== value) {
|
589
|
+
style[styleName] = newValue;
|
590
|
+
}
|
591
|
+
}
|
592
|
+
}
|
593
|
+
};
|
594
|
+
|
595
|
+
Reloader.prototype.reloadStylesheet = function(path) {
|
596
|
+
var imported, link, links, match, style, _i, _j, _k, _l, _len, _len1, _len2, _len3, _ref, _ref1,
|
597
|
+
_this = this;
|
598
|
+
links = (function() {
|
599
|
+
var _i, _len, _ref, _results;
|
600
|
+
_ref = this.document.getElementsByTagName('link');
|
601
|
+
_results = [];
|
602
|
+
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
603
|
+
link = _ref[_i];
|
604
|
+
if (link.rel === 'stylesheet' && !link.__LiveReload_pendingRemoval) {
|
605
|
+
_results.push(link);
|
606
|
+
}
|
607
|
+
}
|
608
|
+
return _results;
|
609
|
+
}).call(this);
|
610
|
+
imported = [];
|
611
|
+
_ref = this.document.getElementsByTagName('style');
|
612
|
+
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
613
|
+
style = _ref[_i];
|
614
|
+
if (style.sheet) {
|
615
|
+
this.collectImportedStylesheets(style, style.sheet, imported);
|
616
|
+
}
|
617
|
+
}
|
618
|
+
for (_j = 0, _len1 = links.length; _j < _len1; _j++) {
|
619
|
+
link = links[_j];
|
620
|
+
this.collectImportedStylesheets(link, link.sheet, imported);
|
621
|
+
}
|
622
|
+
if (this.window.StyleFix && this.document.querySelectorAll) {
|
623
|
+
_ref1 = this.document.querySelectorAll('style[data-href]');
|
624
|
+
for (_k = 0, _len2 = _ref1.length; _k < _len2; _k++) {
|
625
|
+
style = _ref1[_k];
|
626
|
+
links.push(style);
|
627
|
+
}
|
628
|
+
}
|
629
|
+
this.console.log("LiveReload found " + links.length + " LINKed stylesheets, " + imported.length + " @imported stylesheets");
|
630
|
+
match = pickBestMatch(path, links.concat(imported), function(l) {
|
631
|
+
return pathFromUrl(_this.linkHref(l));
|
632
|
+
});
|
633
|
+
if (match) {
|
634
|
+
if (match.object.rule) {
|
635
|
+
this.console.log("LiveReload is reloading imported stylesheet: " + match.object.href);
|
636
|
+
this.reattachImportedRule(match.object);
|
637
|
+
} else {
|
638
|
+
this.console.log("LiveReload is reloading stylesheet: " + (this.linkHref(match.object)));
|
639
|
+
this.reattachStylesheetLink(match.object);
|
640
|
+
}
|
641
|
+
} else {
|
642
|
+
this.console.log("LiveReload will reload all stylesheets because path '" + path + "' did not match any specific one");
|
643
|
+
for (_l = 0, _len3 = links.length; _l < _len3; _l++) {
|
644
|
+
link = links[_l];
|
645
|
+
this.reattachStylesheetLink(link);
|
646
|
+
}
|
647
|
+
}
|
648
|
+
return true;
|
649
|
+
};
|
650
|
+
|
651
|
+
Reloader.prototype.collectImportedStylesheets = function(link, styleSheet, result) {
|
652
|
+
var index, rule, rules, _i, _len;
|
653
|
+
try {
|
654
|
+
rules = styleSheet != null ? styleSheet.cssRules : void 0;
|
655
|
+
} catch (e) {
|
656
|
+
|
657
|
+
}
|
658
|
+
if (rules && rules.length) {
|
659
|
+
for (index = _i = 0, _len = rules.length; _i < _len; index = ++_i) {
|
660
|
+
rule = rules[index];
|
661
|
+
switch (rule.type) {
|
662
|
+
case CSSRule.CHARSET_RULE:
|
663
|
+
continue;
|
664
|
+
case CSSRule.IMPORT_RULE:
|
665
|
+
result.push({
|
666
|
+
link: link,
|
667
|
+
rule: rule,
|
668
|
+
index: index,
|
669
|
+
href: rule.href
|
670
|
+
});
|
671
|
+
this.collectImportedStylesheets(link, rule.styleSheet, result);
|
672
|
+
break;
|
673
|
+
default:
|
674
|
+
break;
|
675
|
+
}
|
676
|
+
}
|
677
|
+
}
|
678
|
+
};
|
679
|
+
|
680
|
+
Reloader.prototype.waitUntilCssLoads = function(clone, func) {
|
681
|
+
var callbackExecuted, executeCallback, poll,
|
682
|
+
_this = this;
|
683
|
+
callbackExecuted = false;
|
684
|
+
executeCallback = function() {
|
685
|
+
if (callbackExecuted) {
|
686
|
+
return;
|
687
|
+
}
|
688
|
+
callbackExecuted = true;
|
689
|
+
return func();
|
690
|
+
};
|
691
|
+
clone.onload = function() {
|
692
|
+
console.log("onload!");
|
693
|
+
_this.knownToSupportCssOnLoad = true;
|
694
|
+
return executeCallback();
|
695
|
+
};
|
696
|
+
if (!this.knownToSupportCssOnLoad) {
|
697
|
+
(poll = function() {
|
698
|
+
if (clone.sheet) {
|
699
|
+
console.log("polling!");
|
700
|
+
return executeCallback();
|
701
|
+
} else {
|
702
|
+
return _this.Timer.start(50, poll);
|
703
|
+
}
|
704
|
+
})();
|
705
|
+
}
|
706
|
+
return this.Timer.start(this.options.stylesheetReloadTimeout, executeCallback);
|
707
|
+
};
|
708
|
+
|
709
|
+
Reloader.prototype.linkHref = function(link) {
|
710
|
+
return link.href || link.getAttribute('data-href');
|
711
|
+
};
|
712
|
+
|
713
|
+
Reloader.prototype.reattachStylesheetLink = function(link) {
|
714
|
+
var clone, parent,
|
715
|
+
_this = this;
|
716
|
+
if (link.__LiveReload_pendingRemoval) {
|
717
|
+
return;
|
718
|
+
}
|
719
|
+
link.__LiveReload_pendingRemoval = true;
|
720
|
+
if (link.tagName === 'STYLE') {
|
721
|
+
clone = this.document.createElement('link');
|
722
|
+
clone.rel = 'stylesheet';
|
723
|
+
clone.media = link.media;
|
724
|
+
clone.disabled = link.disabled;
|
725
|
+
} else {
|
726
|
+
clone = link.cloneNode(false);
|
727
|
+
}
|
728
|
+
clone.href = this.generateCacheBustUrl(this.linkHref(link));
|
729
|
+
parent = link.parentNode;
|
730
|
+
if (parent.lastChild === link) {
|
731
|
+
parent.appendChild(clone);
|
732
|
+
} else {
|
733
|
+
parent.insertBefore(clone, link.nextSibling);
|
734
|
+
}
|
735
|
+
return this.waitUntilCssLoads(clone, function() {
|
736
|
+
var additionalWaitingTime;
|
737
|
+
if (/AppleWebKit/.test(navigator.userAgent)) {
|
738
|
+
additionalWaitingTime = 5;
|
739
|
+
} else {
|
740
|
+
additionalWaitingTime = 200;
|
741
|
+
}
|
742
|
+
return _this.Timer.start(additionalWaitingTime, function() {
|
743
|
+
var _ref;
|
744
|
+
if (!link.parentNode) {
|
745
|
+
return;
|
746
|
+
}
|
747
|
+
link.parentNode.removeChild(link);
|
748
|
+
clone.onreadystatechange = null;
|
749
|
+
return (_ref = _this.window.StyleFix) != null ? _ref.link(clone) : void 0;
|
750
|
+
});
|
751
|
+
});
|
752
|
+
};
|
753
|
+
|
754
|
+
Reloader.prototype.reattachImportedRule = function(_arg) {
|
755
|
+
var href, index, link, media, newRule, parent, rule, tempLink,
|
756
|
+
_this = this;
|
757
|
+
rule = _arg.rule, index = _arg.index, link = _arg.link;
|
758
|
+
parent = rule.parentStyleSheet;
|
759
|
+
href = this.generateCacheBustUrl(rule.href);
|
760
|
+
media = rule.media.length ? [].join.call(rule.media, ', ') : '';
|
761
|
+
newRule = "@import url(\"" + href + "\") " + media + ";";
|
762
|
+
rule.__LiveReload_newHref = href;
|
763
|
+
tempLink = this.document.createElement("link");
|
764
|
+
tempLink.rel = 'stylesheet';
|
765
|
+
tempLink.href = href;
|
766
|
+
tempLink.__LiveReload_pendingRemoval = true;
|
767
|
+
if (link.parentNode) {
|
768
|
+
link.parentNode.insertBefore(tempLink, link);
|
769
|
+
}
|
770
|
+
return this.Timer.start(this.importCacheWaitPeriod, function() {
|
771
|
+
if (tempLink.parentNode) {
|
772
|
+
tempLink.parentNode.removeChild(tempLink);
|
773
|
+
}
|
774
|
+
if (rule.__LiveReload_newHref !== href) {
|
775
|
+
return;
|
776
|
+
}
|
777
|
+
parent.insertRule(newRule, index);
|
778
|
+
parent.deleteRule(index + 1);
|
779
|
+
rule = parent.cssRules[index];
|
780
|
+
rule.__LiveReload_newHref = href;
|
781
|
+
return _this.Timer.start(_this.importCacheWaitPeriod, function() {
|
782
|
+
if (rule.__LiveReload_newHref !== href) {
|
783
|
+
return;
|
784
|
+
}
|
785
|
+
parent.insertRule(newRule, index);
|
786
|
+
return parent.deleteRule(index + 1);
|
787
|
+
});
|
788
|
+
});
|
789
|
+
};
|
790
|
+
|
791
|
+
Reloader.prototype.generateUniqueString = function() {
|
792
|
+
return 'livereload=' + Date.now();
|
793
|
+
};
|
794
|
+
|
795
|
+
Reloader.prototype.generateCacheBustUrl = function(url, expando) {
|
796
|
+
var hash, oldParams, params, _ref;
|
797
|
+
if (expando == null) {
|
798
|
+
expando = this.generateUniqueString();
|
799
|
+
}
|
800
|
+
_ref = splitUrl(url), url = _ref.url, hash = _ref.hash, oldParams = _ref.params;
|
801
|
+
if (this.options.overrideURL) {
|
802
|
+
if (url.indexOf(this.options.serverURL) < 0) {
|
803
|
+
url = this.options.serverURL + this.options.overrideURL + "?url=" + encodeURIComponent(url);
|
804
|
+
}
|
805
|
+
}
|
806
|
+
params = oldParams.replace(/(\?|&)livereload=(\d+)/, function(match, sep) {
|
807
|
+
return "" + sep + expando;
|
808
|
+
});
|
809
|
+
if (params === oldParams) {
|
810
|
+
if (oldParams.length === 0) {
|
811
|
+
params = "?" + expando;
|
812
|
+
} else {
|
813
|
+
params = "" + oldParams + "&" + expando;
|
814
|
+
}
|
815
|
+
}
|
816
|
+
return url + params + hash;
|
817
|
+
};
|
818
|
+
|
819
|
+
return Reloader;
|
820
|
+
|
821
|
+
})();
|
822
|
+
|
823
|
+
}).call(this);
|
824
|
+
|
825
|
+
// livereload
|
826
|
+
var Connector, LiveReload, Options, Reloader, Timer;
|
827
|
+
|
828
|
+
Connector = __connector.Connector;
|
829
|
+
|
830
|
+
Timer = __timer.Timer;
|
831
|
+
|
832
|
+
Options = __options.Options;
|
833
|
+
|
834
|
+
Reloader = __reloader.Reloader;
|
835
|
+
|
836
|
+
__livereload.LiveReload = LiveReload = (function() {
|
837
|
+
|
838
|
+
function LiveReload(window) {
|
839
|
+
var _this = this;
|
840
|
+
this.window = window;
|
841
|
+
this.listeners = {};
|
842
|
+
this.plugins = [];
|
843
|
+
this.pluginIdentifiers = {};
|
844
|
+
this.console = this.window.location.href.match(/LR-verbose/) && this.window.console && this.window.console.log && this.window.console.error ? this.window.console : {
|
845
|
+
log: function() {},
|
846
|
+
error: function() {}
|
847
|
+
};
|
848
|
+
if (!(this.WebSocket = this.window.WebSocket || this.window.MozWebSocket)) {
|
849
|
+
console.error("LiveReload disabled because the browser does not seem to support web sockets");
|
850
|
+
return;
|
851
|
+
}
|
852
|
+
if (!(this.options = Options.extract(this.window.document))) {
|
853
|
+
console.error("LiveReload disabled because it could not find its own <SCRIPT> tag");
|
854
|
+
return;
|
855
|
+
}
|
856
|
+
this.reloader = new Reloader(this.window, this.console, Timer);
|
857
|
+
this.connector = new Connector(this.options, this.WebSocket, Timer, {
|
858
|
+
connecting: function() {},
|
859
|
+
socketConnected: function() {},
|
860
|
+
connected: function(protocol) {
|
861
|
+
var _base;
|
862
|
+
if (typeof (_base = _this.listeners).connect === "function") {
|
863
|
+
_base.connect();
|
864
|
+
}
|
865
|
+
_this.log("LiveReload is connected to " + _this.options.host + ":" + _this.options.port + " (protocol v" + protocol + ").");
|
866
|
+
return _this.analyze();
|
867
|
+
},
|
868
|
+
error: function(e) {
|
869
|
+
if (e instanceof ProtocolError) {
|
870
|
+
return console.log("" + e.message + ".");
|
871
|
+
} else {
|
872
|
+
return console.log("LiveReload internal error: " + e.message);
|
873
|
+
}
|
874
|
+
},
|
875
|
+
disconnected: function(reason, nextDelay) {
|
876
|
+
var _base;
|
877
|
+
if (typeof (_base = _this.listeners).disconnect === "function") {
|
878
|
+
_base.disconnect();
|
879
|
+
}
|
880
|
+
switch (reason) {
|
881
|
+
case 'cannot-connect':
|
882
|
+
return _this.log("LiveReload cannot connect to " + _this.options.host + ":" + _this.options.port + ", will retry in " + nextDelay + " sec.");
|
883
|
+
case 'broken':
|
884
|
+
return _this.log("LiveReload disconnected from " + _this.options.host + ":" + _this.options.port + ", reconnecting in " + nextDelay + " sec.");
|
885
|
+
case 'handshake-timeout':
|
886
|
+
return _this.log("LiveReload cannot connect to " + _this.options.host + ":" + _this.options.port + " (handshake timeout), will retry in " + nextDelay + " sec.");
|
887
|
+
case 'handshake-failed':
|
888
|
+
return _this.log("LiveReload cannot connect to " + _this.options.host + ":" + _this.options.port + " (handshake failed), will retry in " + nextDelay + " sec.");
|
889
|
+
case 'manual':
|
890
|
+
break;
|
891
|
+
case 'error':
|
892
|
+
break;
|
893
|
+
default:
|
894
|
+
return _this.log("LiveReload disconnected from " + _this.options.host + ":" + _this.options.port + " (" + reason + "), reconnecting in " + nextDelay + " sec.");
|
895
|
+
}
|
896
|
+
},
|
897
|
+
message: function(message) {
|
898
|
+
switch (message.command) {
|
899
|
+
case 'reload':
|
900
|
+
return _this.performReload(message);
|
901
|
+
case 'alert':
|
902
|
+
return _this.performAlert(message);
|
903
|
+
}
|
904
|
+
}
|
905
|
+
});
|
906
|
+
}
|
907
|
+
|
908
|
+
LiveReload.prototype.on = function(eventName, handler) {
|
909
|
+
return this.listeners[eventName] = handler;
|
910
|
+
};
|
911
|
+
|
912
|
+
LiveReload.prototype.log = function(message) {
|
913
|
+
return this.console.log("" + message);
|
914
|
+
};
|
915
|
+
|
916
|
+
LiveReload.prototype.performReload = function(message) {
|
917
|
+
var _ref, _ref2;
|
918
|
+
this.log("LiveReload received reload request for " + message.path + ".");
|
919
|
+
return this.reloader.reload(message.path, {
|
920
|
+
liveCSS: (_ref = message.liveCSS) != null ? _ref : true,
|
921
|
+
liveImg: (_ref2 = message.liveImg) != null ? _ref2 : true,
|
922
|
+
originalPath: message.originalPath || '',
|
923
|
+
overrideURL: message.overrideURL || '',
|
924
|
+
serverURL: "http://" + this.options.host + ":" + this.options.port
|
925
|
+
});
|
926
|
+
};
|
927
|
+
|
928
|
+
LiveReload.prototype.performAlert = function(message) {
|
929
|
+
return alert(message.message);
|
930
|
+
};
|
931
|
+
|
932
|
+
LiveReload.prototype.shutDown = function() {
|
933
|
+
var _base;
|
934
|
+
this.connector.disconnect();
|
935
|
+
this.log("LiveReload disconnected.");
|
936
|
+
return typeof (_base = this.listeners).shutdown === "function" ? _base.shutdown() : void 0;
|
937
|
+
};
|
938
|
+
|
939
|
+
LiveReload.prototype.hasPlugin = function(identifier) {
|
940
|
+
return !!this.pluginIdentifiers[identifier];
|
941
|
+
};
|
942
|
+
|
943
|
+
LiveReload.prototype.addPlugin = function(pluginClass) {
|
944
|
+
var plugin;
|
945
|
+
var _this = this;
|
946
|
+
if (this.hasPlugin(pluginClass.identifier)) return;
|
947
|
+
this.pluginIdentifiers[pluginClass.identifier] = true;
|
948
|
+
plugin = new pluginClass(this.window, {
|
949
|
+
_livereload: this,
|
950
|
+
_reloader: this.reloader,
|
951
|
+
_connector: this.connector,
|
952
|
+
console: this.console,
|
953
|
+
Timer: Timer,
|
954
|
+
generateCacheBustUrl: function(url) {
|
955
|
+
return _this.reloader.generateCacheBustUrl(url);
|
956
|
+
}
|
957
|
+
});
|
958
|
+
this.plugins.push(plugin);
|
959
|
+
this.reloader.addPlugin(plugin);
|
960
|
+
};
|
961
|
+
|
962
|
+
LiveReload.prototype.analyze = function() {
|
963
|
+
var plugin, pluginData, pluginsData, _i, _len, _ref;
|
964
|
+
if (!(this.connector.protocol >= 7)) return;
|
965
|
+
pluginsData = {};
|
966
|
+
_ref = this.plugins;
|
967
|
+
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
968
|
+
plugin = _ref[_i];
|
969
|
+
pluginsData[plugin.constructor.identifier] = pluginData = (typeof plugin.analyze === "function" ? plugin.analyze() : void 0) || {};
|
970
|
+
pluginData.version = plugin.constructor.version;
|
971
|
+
}
|
972
|
+
this.connector.sendCommand({
|
973
|
+
command: 'info',
|
974
|
+
plugins: pluginsData,
|
975
|
+
url: this.window.location.href
|
976
|
+
});
|
977
|
+
};
|
978
|
+
|
979
|
+
return LiveReload;
|
980
|
+
|
981
|
+
})();
|
982
|
+
|
983
|
+
// less
|
984
|
+
var LessPlugin;
|
985
|
+
__less = LessPlugin = (function() {
|
986
|
+
LessPlugin.identifier = 'less';
|
987
|
+
LessPlugin.version = '1.0';
|
988
|
+
function LessPlugin(window, host) {
|
989
|
+
this.window = window;
|
990
|
+
this.host = host;
|
991
|
+
}
|
992
|
+
LessPlugin.prototype.reload = function(path, options) {
|
993
|
+
if (this.window.less && this.window.less.refresh) {
|
994
|
+
if (path.match(/\.less$/i)) {
|
995
|
+
return this.reloadLess(path);
|
996
|
+
}
|
997
|
+
if (options.originalPath.match(/\.less$/i)) {
|
998
|
+
return this.reloadLess(options.originalPath);
|
999
|
+
}
|
1000
|
+
}
|
1001
|
+
return false;
|
1002
|
+
};
|
1003
|
+
LessPlugin.prototype.reloadLess = function(path) {
|
1004
|
+
var link, links, _i, _len;
|
1005
|
+
links = (function() {
|
1006
|
+
var _i, _len, _ref, _results;
|
1007
|
+
_ref = document.getElementsByTagName('link');
|
1008
|
+
_results = [];
|
1009
|
+
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
1010
|
+
link = _ref[_i];
|
1011
|
+
if (link.href && link.rel === 'stylesheet/less' || (link.rel.match(/stylesheet/) && link.type.match(/^text\/(x-)?less$/))) {
|
1012
|
+
_results.push(link);
|
1013
|
+
}
|
1014
|
+
}
|
1015
|
+
return _results;
|
1016
|
+
})();
|
1017
|
+
if (links.length === 0) {
|
1018
|
+
return false;
|
1019
|
+
}
|
1020
|
+
for (_i = 0, _len = links.length; _i < _len; _i++) {
|
1021
|
+
link = links[_i];
|
1022
|
+
link.href = this.host.generateCacheBustUrl(link.href);
|
1023
|
+
}
|
1024
|
+
this.host.console.log("LiveReload is asking LESS to recompile all stylesheets");
|
1025
|
+
this.window.less.refresh(true);
|
1026
|
+
return true;
|
1027
|
+
};
|
1028
|
+
LessPlugin.prototype.analyze = function() {
|
1029
|
+
return {
|
1030
|
+
disable: !!(this.window.less && this.window.less.refresh)
|
1031
|
+
};
|
1032
|
+
};
|
1033
|
+
return LessPlugin;
|
1034
|
+
})();
|
1035
|
+
|
1036
|
+
// startup
|
1037
|
+
var CustomEvents, LiveReload, k;
|
1038
|
+
CustomEvents = __customevents;
|
1039
|
+
LiveReload = window.LiveReload = new (__livereload.LiveReload)(window);
|
1040
|
+
for (k in window) {
|
1041
|
+
if (k.match(/^LiveReloadPlugin/)) {
|
1042
|
+
LiveReload.addPlugin(window[k]);
|
1043
|
+
}
|
1044
|
+
}
|
1045
|
+
LiveReload.addPlugin(__less);
|
1046
|
+
LiveReload.on('shutdown', function() {
|
1047
|
+
return delete window.LiveReload;
|
1048
|
+
});
|
1049
|
+
LiveReload.on('connect', function() {
|
1050
|
+
return CustomEvents.fire(document, 'LiveReloadConnect');
|
1051
|
+
});
|
1052
|
+
LiveReload.on('disconnect', function() {
|
1053
|
+
return CustomEvents.fire(document, 'LiveReloadDisconnect');
|
1054
|
+
});
|
1055
|
+
CustomEvents.bind(document, 'LiveReloadShutDown', function() {
|
1056
|
+
return LiveReload.shutDown();
|
1057
|
+
});
|
1058
|
+
})();
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: adsf-live
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.5.
|
4
|
+
version: 1.5.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Denis Defreyne
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-09-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: adsf
|
@@ -66,20 +66,6 @@ dependencies:
|
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '3.0'
|
69
|
-
- !ruby/object:Gem::Dependency
|
70
|
-
name: rack-livereload
|
71
|
-
requirement: !ruby/object:Gem::Requirement
|
72
|
-
requirements:
|
73
|
-
- - "~>"
|
74
|
-
- !ruby/object:Gem::Version
|
75
|
-
version: '0.3'
|
76
|
-
type: :runtime
|
77
|
-
prerelease: false
|
78
|
-
version_requirements: !ruby/object:Gem::Requirement
|
79
|
-
requirements:
|
80
|
-
- - "~>"
|
81
|
-
- !ruby/object:Gem::Version
|
82
|
-
version: '0.3'
|
83
69
|
description: Automatically reloads when changes are detected.
|
84
70
|
email: denis.defreyne@stoneship.org
|
85
71
|
executables: []
|
@@ -89,9 +75,11 @@ files:
|
|
89
75
|
- NEWS.md
|
90
76
|
- README.md
|
91
77
|
- lib/adsf/live.rb
|
78
|
+
- lib/adsf/live/rack_livereload.rb
|
92
79
|
- lib/adsf/live/version.rb
|
93
80
|
- lib/adsf/live/watcher.rb
|
94
81
|
- lib/adsf/live/web_socket_server.rb
|
82
|
+
- vendor/livereload.js
|
95
83
|
homepage: http://github.com/ddfreyne/adsf/
|
96
84
|
licenses:
|
97
85
|
- MIT
|
@@ -112,7 +100,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
112
100
|
- !ruby/object:Gem::Version
|
113
101
|
version: '0'
|
114
102
|
requirements: []
|
115
|
-
rubygems_version: 3.5.
|
103
|
+
rubygems_version: 3.5.14
|
116
104
|
signing_key:
|
117
105
|
specification_version: 4
|
118
106
|
summary: livereload support for adsf
|