munge 0.15.1 → 0.16.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/munge/cli/commands/build.rb +1 -0
- data/lib/munge/cli/commands/server.rb +37 -5
- data/lib/munge/cli/dispatch.rb +2 -1
- data/lib/munge/config.rb +2 -0
- data/lib/munge/extras/livereload/messaging.rb +40 -0
- data/lib/munge/extras/livereload/server.rb +57 -0
- data/lib/munge/extras/livereload/update_client.rb +19 -0
- data/lib/munge/extras/livereload/update_server.rb +14 -0
- data/lib/munge/extras/livereload/vendor/livereload.js +1183 -0
- data/lib/munge/extras/livereload.rb +32 -0
- data/lib/munge/helpers/livereload.rb +19 -0
- data/lib/munge/helpers/tag.rb +7 -2
- data/lib/munge/runner.rb +5 -0
- data/lib/munge/system/item_factory/content_parser.rb +1 -1
- data/lib/munge/version.rb +1 -1
- data/lib/munge.rb +3 -0
- data/munge.gemspec +4 -0
- data/seeds/config.rb +1 -1
- data/seeds/lib/view_helpers.rb +1 -0
- metadata +24 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 21f94ee6721dd5a6248f8cc682e7c20b25e37c3c
|
4
|
+
data.tar.gz: 4bc2576726939c6ec80482b94fdb05d700dfeab2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b5953027d4225360dfe10436c2c65956cdffe57657e766709b753948f6a212295bcf6aeb198127719749c15db09cdb19fd27cce7eb7b16887cf47a7d75e36d8b
|
7
|
+
data.tar.gz: 38649c10faff0d936d49b72f2f72a2a05e2fd134f599030f6d7ac589b05758699b9098e3cce14c2035d069333290cdb9145690d6c134236d96277db674863231
|
@@ -2,15 +2,26 @@ module Munge
|
|
2
2
|
module Cli
|
3
3
|
module Commands
|
4
4
|
class Server
|
5
|
-
def initialize(bootloader)
|
5
|
+
def initialize(bootloader, livereload:)
|
6
6
|
@bootloader = bootloader
|
7
|
-
@listener
|
7
|
+
@listener = listener
|
8
|
+
@livereload =
|
9
|
+
if livereload
|
10
|
+
if Gem.loaded_specs.key?("reel")
|
11
|
+
Munge::Extras::Livereload::Main.new(true)
|
12
|
+
else
|
13
|
+
STDERR.puts "Gem `reel` is not installed. Check that your Ruby version is compatible"
|
14
|
+
Munge::Extras::Livereload::Main.new(false)
|
15
|
+
end
|
16
|
+
else
|
17
|
+
Munge::Extras::Livereload::Main.new(false)
|
18
|
+
end
|
8
19
|
end
|
9
20
|
|
10
21
|
def call
|
11
22
|
@listener.start
|
12
23
|
|
13
|
-
|
24
|
+
munge_build
|
14
25
|
|
15
26
|
system("munge view")
|
16
27
|
rescue Interrupt
|
@@ -23,9 +34,14 @@ module Munge
|
|
23
34
|
require "listen"
|
24
35
|
|
25
36
|
listen = Listen.to(@bootloader.root_path) do
|
26
|
-
|
37
|
+
built_files = munge_build
|
38
|
+
|
39
|
+
@livereload.notify_changes(files: built_files)
|
40
|
+
|
41
|
+
GC.start
|
27
42
|
end
|
28
43
|
|
44
|
+
ignore(listen, ".sass-cache")
|
29
45
|
ignore(listen, ENV["BUILD_ROOT"])
|
30
46
|
ignore(listen, @bootloader.config[:output_path])
|
31
47
|
|
@@ -34,9 +50,25 @@ module Munge
|
|
34
50
|
|
35
51
|
def ignore(listener, pattern)
|
36
52
|
if pattern
|
37
|
-
listener.ignore(/^#{pattern}/)
|
53
|
+
listener.ignore(/^#{Regexp.escape(pattern)}/)
|
38
54
|
end
|
39
55
|
end
|
56
|
+
|
57
|
+
def munge_build
|
58
|
+
bootloader =
|
59
|
+
Munge::Bootloader.new(root_path: @bootloader.root_path)
|
60
|
+
|
61
|
+
build_command =
|
62
|
+
Munge::Cli::Commands::Build.new(
|
63
|
+
bootloader,
|
64
|
+
dry_run: false,
|
65
|
+
reporter: "Default",
|
66
|
+
verbosity: "written",
|
67
|
+
build_root: ENV["BUILD_ROOT"]
|
68
|
+
)
|
69
|
+
|
70
|
+
build_command.call
|
71
|
+
end
|
40
72
|
end
|
41
73
|
end
|
42
74
|
end
|
data/lib/munge/cli/dispatch.rb
CHANGED
@@ -27,11 +27,12 @@ module Munge
|
|
27
27
|
end
|
28
28
|
|
29
29
|
desc "server", "Run the development server"
|
30
|
+
method_option :livereload, desc: "Reload browser on update", default: Gem.loaded_specs.key?("reel"), type: :boolean
|
30
31
|
def server
|
31
32
|
ENV["MUNGE_ENV"] ||= "development"
|
32
33
|
ENV["BUILD_ROOT"] ||= "tmp/development-build"
|
33
34
|
|
34
|
-
Commands::Server.new(bootloader).call
|
35
|
+
Commands::Server.new(bootloader, **symbolized_options).call
|
35
36
|
end
|
36
37
|
|
37
38
|
desc "update", "Use with caution: override local configs with pristine version (useful after bumping version in Gemfile)"
|
data/lib/munge/config.rb
CHANGED
@@ -0,0 +1,40 @@
|
|
1
|
+
module Munge
|
2
|
+
module Extras
|
3
|
+
module Livereload
|
4
|
+
class Messaging
|
5
|
+
def hello
|
6
|
+
JSON.generate(
|
7
|
+
command: "hello",
|
8
|
+
protocols: [the_protocol],
|
9
|
+
serverName: "munge-livereload"
|
10
|
+
)
|
11
|
+
end
|
12
|
+
|
13
|
+
def reload(changed_file)
|
14
|
+
JSON.generate(
|
15
|
+
command: "reload",
|
16
|
+
path: changed_file,
|
17
|
+
liveCSS: "false"
|
18
|
+
)
|
19
|
+
end
|
20
|
+
|
21
|
+
def valid_handshake?(socket_data)
|
22
|
+
client_handshake = JSON.parse(socket_data)
|
23
|
+
|
24
|
+
return false if client_handshake["command"] != "hello"
|
25
|
+
return false if !client_handshake["protocols"].include?(the_protocol)
|
26
|
+
|
27
|
+
true
|
28
|
+
rescue
|
29
|
+
false
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
33
|
+
|
34
|
+
def the_protocol
|
35
|
+
"http://livereload.com/protocols/official-7".freeze
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
module Munge
|
2
|
+
module Extras
|
3
|
+
module Livereload
|
4
|
+
class Server < Reel::Server::HTTP
|
5
|
+
def initialize(host = "127.0.0.1", port = 35729)
|
6
|
+
super(host, port, &method(:on_connection))
|
7
|
+
@update_client = UpdateClient.new(self)
|
8
|
+
@messaging = Messaging.new
|
9
|
+
@sockets = []
|
10
|
+
end
|
11
|
+
|
12
|
+
def notify_reload(changed_files)
|
13
|
+
@sockets.each do |socket|
|
14
|
+
begin
|
15
|
+
changed_files.each do |file|
|
16
|
+
socket << @messaging.reload(file)
|
17
|
+
end
|
18
|
+
rescue Reel::SocketError
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def on_connection(connection)
|
24
|
+
connection.each_request do |request|
|
25
|
+
if request.websocket?
|
26
|
+
handle_websocket(connection, request)
|
27
|
+
else
|
28
|
+
handle_request(request)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def handle_websocket(_connection, request)
|
34
|
+
socket = request.websocket
|
35
|
+
if socket.url == "/livereload"
|
36
|
+
# Ordering of handshake doesn't seem to matter
|
37
|
+
socket << @messaging.hello
|
38
|
+
|
39
|
+
if @messaging.valid_handshake?(socket.read)
|
40
|
+
@sockets.push(socket)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
rescue Reel::SocketError
|
44
|
+
end
|
45
|
+
|
46
|
+
def handle_request(request)
|
47
|
+
if request.path == "/livereload.js"
|
48
|
+
livejs = File.expand_path("vendor/livereload.js", File.dirname(__FILE__))
|
49
|
+
request.respond(:ok, File.read(livejs))
|
50
|
+
else
|
51
|
+
request.respond(:not_found, "not found")
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Munge
|
2
|
+
module Extras
|
3
|
+
module Livereload
|
4
|
+
class UpdateClient
|
5
|
+
include Celluloid
|
6
|
+
include Celluloid::Notifications
|
7
|
+
|
8
|
+
def initialize(webserver)
|
9
|
+
@webserver = webserver
|
10
|
+
subscribe("changed_files", :notify_reload)
|
11
|
+
end
|
12
|
+
|
13
|
+
def notify_reload(_topic, changed_files)
|
14
|
+
@webserver.notify_reload(changed_files)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|