hawkins 2.0.4 → 2.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/hawkins/liveserve.rb +16 -4
- data/lib/hawkins/servlet.rb +18 -14
- data/lib/hawkins/version.rb +1 -1
- data/lib/hawkins/websockets.rb +19 -3
- data/test/test_liveserve.rb +2 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 08351443faff94c7f57124889029acf7a027265e
|
4
|
+
data.tar.gz: d4ec1c35cd3952a106d04527f9e9736281d7becb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 91f12d9f6525263a18b0dd49a629ecb4aa64d679121e272fa2797599760f740d7f18fb339efd9cee497ce00a6c2c8bd5929dbd2af6a31f53157d31dc190980a7
|
7
|
+
data.tar.gz: e8c86d3a6f4c958a37456efb492a8225aa40bb225e0b63b0614846c596025934c95edc1a343d4c4a27324952a771666df2433fbe270d50d3ca96bdd811a03f28
|
data/lib/hawkins/liveserve.rb
CHANGED
@@ -3,7 +3,6 @@ require 'thread'
|
|
3
3
|
module Hawkins
|
4
4
|
module Commands
|
5
5
|
class LiveServe < Jekyll::Command
|
6
|
-
|
7
6
|
# Based on pattern described in
|
8
7
|
# https://emptysqua.re/blog/an-event-synchronization-primitive-for-ruby/
|
9
8
|
@mutex = Mutex.new
|
@@ -61,7 +60,6 @@ module Hawkins
|
|
61
60
|
setup(destination)
|
62
61
|
|
63
62
|
@reload_reactor.start(opts)
|
64
|
-
|
65
63
|
@server = WEBrick::HTTPServer.new(webrick_opts(opts)).tap { |o| o.unmount("") }
|
66
64
|
|
67
65
|
@server.mount("#{opts['baseurl']}/__livereload",
|
@@ -96,7 +94,7 @@ module Hawkins
|
|
96
94
|
# path matching is very loose so that a message to reload "/" will always
|
97
95
|
# lead the page to reload since every page starts with "/".
|
98
96
|
Jekyll::Hooks.register(:site, :post_write) do
|
99
|
-
|
97
|
+
if @changed_pages && @reload_reactor && @reload_reactor.running?
|
100
98
|
ignore, @changed_pages = @changed_pages.partition do |p|
|
101
99
|
Array(opts["ignore"]).any? do |filter|
|
102
100
|
File.fnmatch(filter, Jekyll.sanitized_path(p.relative_path))
|
@@ -260,6 +258,13 @@ module Hawkins
|
|
260
258
|
unless detached
|
261
259
|
proc do
|
262
260
|
mutex.synchronize do
|
261
|
+
unless @reload_reactor.nil?
|
262
|
+
@reload_reactor.reactor_mutex.synchronize do
|
263
|
+
unless EM.reactor_running?
|
264
|
+
@reload_reactor.reactor_running_cond.wait(@reload_reactor.reactor_mutex)
|
265
|
+
end
|
266
|
+
end
|
267
|
+
end
|
263
268
|
@is_running = true
|
264
269
|
Jekyll.logger.info("Server running...", "press ctrl-c to stop.")
|
265
270
|
running_cond.signal
|
@@ -273,7 +278,14 @@ module Hawkins
|
|
273
278
|
unless detached
|
274
279
|
proc do
|
275
280
|
mutex.synchronize do
|
276
|
-
|
281
|
+
unless @reload_reactor.nil?
|
282
|
+
@reload_reactor.stop
|
283
|
+
@reload_reactor.reactor_mutex.synchronize do
|
284
|
+
if EM.reactor_running?
|
285
|
+
@reload_reactor.reactor_running_cond.wait(@reload_reactor.reactor_mutex)
|
286
|
+
end
|
287
|
+
end
|
288
|
+
end
|
277
289
|
@is_running = false
|
278
290
|
running_cond.signal
|
279
291
|
end
|
data/lib/hawkins/servlet.rb
CHANGED
@@ -87,11 +87,16 @@ module Hawkins
|
|
87
87
|
@new_body = @new_body.join
|
88
88
|
end
|
89
89
|
|
90
|
-
def host_to_use
|
91
|
-
(@options["host"] || 'localhost').gsub(%r{:.*}, '')
|
92
|
-
end
|
93
|
-
|
94
90
|
def template
|
91
|
+
# Unclear what "snipver" does. Doc at
|
92
|
+
# https://github.com/livereload/livereload-js states that the recommended
|
93
|
+
# setting is 1.
|
94
|
+
|
95
|
+
# Complicated JavaScript to ensure that livereload.js is loaded from the
|
96
|
+
# same origin as the page. Mostly useful for dealing with the browser's
|
97
|
+
# distinction between 'localhost' and 127.0.0.1
|
98
|
+
|
99
|
+
# Use 'src="//..."' to mirror the protocol used to load the page itself.
|
95
100
|
template = <<-TEMPLATE
|
96
101
|
<% if with_swf? %>
|
97
102
|
<script type="text/javascript">
|
@@ -101,21 +106,20 @@ module Hawkins
|
|
101
106
|
<script type="text/javascript" src="<%= @options["baseurl"] %>/__livereload/swfobject.js"></script>
|
102
107
|
<script type="text/javascript" src="<%= @options["baseurl"] %>/__livereload/web_socket.js"></script>
|
103
108
|
<% end %>
|
104
|
-
<script
|
105
|
-
document.write(
|
109
|
+
<script>
|
110
|
+
document.write(
|
111
|
+
'<script src="//' +
|
112
|
+
(location.host || 'localhost').split(':')[0] +
|
113
|
+
':<%=@options["reload_port"] %>/livereload.js?snipver=1<%= livereload_args %>"' +
|
114
|
+
'></' +
|
115
|
+
'script>');
|
106
116
|
</script>
|
107
117
|
TEMPLATE
|
108
118
|
ERB.new(Jekyll::Utils.strip_heredoc(template))
|
109
119
|
end
|
110
120
|
|
111
|
-
def
|
112
|
-
|
113
|
-
protocol = use_ssl ? "https" : "http"
|
114
|
-
|
115
|
-
# Unclear what "snipver" does. https://github.com/livereload/livereload-js states
|
116
|
-
# that the recommended setting is 1.
|
117
|
-
src = "#{protocol}://#{host_to_use}:#{@options['reload_port']}/livereload.js?snipver=1"
|
118
|
-
|
121
|
+
def livereload_args
|
122
|
+
src = ''
|
119
123
|
# XHTML standard requires ampersands to be encoded as entities when in attributes
|
120
124
|
# See http://stackoverflow.com/a/2190292
|
121
125
|
src << "&mindelay=#{@options['min_delay']}" if @options["min_delay"]
|
data/lib/hawkins/version.rb
CHANGED
data/lib/hawkins/websockets.rb
CHANGED
@@ -27,7 +27,7 @@ module Hawkins
|
|
27
27
|
|
28
28
|
reload_file = File.join(LIVERELOAD_DIR, "livereload.js")
|
29
29
|
@reload_body = File.read(reload_file)
|
30
|
-
@reload_size =
|
30
|
+
@reload_size = @reload_body.bytesize
|
31
31
|
end
|
32
32
|
|
33
33
|
def dispatch(data)
|
@@ -67,11 +67,14 @@ module Hawkins
|
|
67
67
|
class LiveReloadReactor
|
68
68
|
attr_reader :thread
|
69
69
|
attr_reader :opts
|
70
|
+
attr_reader :reactor_mutex, :reactor_running_cond
|
70
71
|
|
71
72
|
def initialize
|
72
73
|
@thread = nil
|
73
74
|
@websockets = []
|
74
75
|
@connections_count = 0
|
76
|
+
@reactor_mutex = Mutex.new
|
77
|
+
@reactor_running_cond = ConditionVariable.new
|
75
78
|
end
|
76
79
|
|
77
80
|
def stop
|
@@ -80,14 +83,13 @@ module Hawkins
|
|
80
83
|
end
|
81
84
|
|
82
85
|
def running?
|
83
|
-
|
86
|
+
EM.reactor_running?
|
84
87
|
end
|
85
88
|
|
86
89
|
def start(opts)
|
87
90
|
@thread = Thread.new do
|
88
91
|
# Use epoll if the kernel supports it
|
89
92
|
EM.epoll
|
90
|
-
# TODO enable SSL
|
91
93
|
EM.run do
|
92
94
|
Jekyll.logger.info("LiveReload Server:", "#{opts['host']}:#{opts['reload_port']}")
|
93
95
|
EM.start_server(opts['host'], opts['reload_port'], HttpAwareConnection, opts) do |ws|
|
@@ -103,8 +105,22 @@ module Hawkins
|
|
103
105
|
print_message(msg)
|
104
106
|
end
|
105
107
|
end
|
108
|
+
|
109
|
+
# Notify blocked threads that EventMachine has started or shutdown
|
110
|
+
EM.schedule do
|
111
|
+
@reactor_mutex.synchronize do
|
112
|
+
@reactor_running_cond.broadcast
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
EM.add_shutdown_hook do
|
117
|
+
@reactor_mutex.synchronize do
|
118
|
+
@reactor_running_cond.broadcast
|
119
|
+
end
|
120
|
+
end
|
106
121
|
end
|
107
122
|
end
|
123
|
+
@thread.abort_on_exception = true
|
108
124
|
end
|
109
125
|
|
110
126
|
# For a description of the protocol see http://feedback.livereload.com/knowledgebase/articles/86174-livereload-protocol
|
data/test/test_liveserve.rb
CHANGED
@@ -70,6 +70,7 @@ module Hawkins
|
|
70
70
|
@thread = Thread.new do
|
71
71
|
Commands::LiveServe.start(opts)
|
72
72
|
end
|
73
|
+
@thread.abort_on_exception = true
|
73
74
|
|
74
75
|
Commands::LiveServe.mutex.synchronize do
|
75
76
|
unless Commands::LiveServe.is_running
|
@@ -121,8 +122,7 @@ module Hawkins
|
|
121
122
|
client.ssl_config.add_trust_ca(cert)
|
122
123
|
content = client.get_content(
|
123
124
|
"https://#{opts['host']}:#{opts['port']}/#{opts['baseurl']}/hello.html")
|
124
|
-
expect(content).to include(
|
125
|
-
"src=\"https://#{opts['host']}:#{opts['reload_port']}/livereload.js")
|
125
|
+
expect(content).to include(%q(src="//'))
|
126
126
|
end
|
127
127
|
|
128
128
|
it "serves nothing else over HTTP on the default LiveReload port" do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hawkins
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.
|
4
|
+
version: 2.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alex Wood
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-01-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: jekyll
|