adsf-live 1.4.8 → 1.5.1
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
- metadata +4 -17
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 59551ad64538b33765bcaf107d804454b5d4d2c70fec971b75673ea70a4a3de2
|
4
|
+
data.tar.gz: 4b0e62038081c3112adfbb7a3c5743987d85ed3627e62cd70539fd966a5c1de2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 25148455618848a6247a941d2b56bc58b63e0c8803677ac7908e4c89cde8b17585c53e0f80c20205ca9577e6c24b78f250e2a641016c45af6329a3f8566c0927
|
7
|
+
data.tar.gz: 6432a179cbbf306a707c63b0ddd9735a17b86979d74c24c0ff409ccbf11a2d6f00a142877aa9a5c69d3b917839820770e11026734ffab946b974ad96f1659317
|
@@ -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'
|
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.
|
4
|
+
version: 1.5.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Denis Defreyne
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
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,6 +75,7 @@ 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
|
@@ -112,7 +99,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
112
99
|
- !ruby/object:Gem::Version
|
113
100
|
version: '0'
|
114
101
|
requirements: []
|
115
|
-
rubygems_version: 3.
|
102
|
+
rubygems_version: 3.5.14
|
116
103
|
signing_key:
|
117
104
|
specification_version: 4
|
118
105
|
summary: livereload support for adsf
|