octodown 1.4.1 → 1.4.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/octodown/renderer/server.rb +42 -17
- data/lib/octodown/support/services/riposter.rb +0 -1
- data/lib/octodown/version.rb +1 -1
- metadata +11 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6a531a7522c46d3268a13438f70d95a6cda40b44
|
4
|
+
data.tar.gz: 7aec5cd981f01c760edfb5398fb6daf9f5a52b9e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 61fcf9f255aca9065abe69807749e6f266881b63999bdf170f1e64de2535a61cb08c41b809fe532e27994a08b3b085d9ab1abd1a4377f3e46dc012030544375f
|
7
|
+
data.tar.gz: 85d04f8d4f6d81602108d62fe066f8e7cdd019dcf6774bc1f43b376959fd010ff7ec687cdd8f3353ef36a4ce5ba55492e5ae16a02ac786be13a38f07d17085ef
|
@@ -1,31 +1,54 @@
|
|
1
|
+
require 'faye/websocket'
|
2
|
+
require 'puma'
|
3
|
+
require 'rack'
|
4
|
+
require 'rack/handler/puma'
|
5
|
+
require 'thread'
|
6
|
+
require 'launchy'
|
7
|
+
|
1
8
|
module Octodown
|
2
9
|
module Renderer
|
3
10
|
class Server
|
4
11
|
attr_reader :file, :path, :options, :port
|
5
12
|
|
6
13
|
def initialize(_content, options = {})
|
7
|
-
init_ws
|
8
|
-
|
9
14
|
@file = ARGF.file
|
10
15
|
@options = options
|
11
16
|
@path = File.dirname(File.expand_path(file.path))
|
12
17
|
@port = options[:port]
|
13
18
|
@websockets = []
|
19
|
+
@already_opened = false
|
20
|
+
@mutex = Mutex.new
|
14
21
|
end
|
15
22
|
|
16
23
|
def present
|
17
24
|
register_listener
|
18
25
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
sleep 2.5
|
24
|
-
Launchy.open "http://localhost:#{port}" if @websockets.empty?
|
25
|
-
t.exit
|
26
|
+
Thread.new do
|
27
|
+
Thread.abort_on_exception = true
|
28
|
+
maybe_launch_browser
|
29
|
+
Thread.exit
|
26
30
|
end
|
27
31
|
|
28
|
-
|
32
|
+
boot_server
|
33
|
+
end
|
34
|
+
|
35
|
+
def boot_server
|
36
|
+
puts "[INFO] Server running on http://localhost:#{port}"
|
37
|
+
Rack::Handler::Puma.run app, Host: 'localhost', Port: port, Silent: true
|
38
|
+
end
|
39
|
+
|
40
|
+
def maybe_launch_browser
|
41
|
+
return if ENV['TEST']
|
42
|
+
|
43
|
+
sleep 2.5
|
44
|
+
|
45
|
+
@mutex.synchronize do
|
46
|
+
if @already_opened == false
|
47
|
+
@already_opened = true
|
48
|
+
puts '[INFO] Loading preview in a new browser tab'
|
49
|
+
Launchy.open "http://localhost:#{port}"
|
50
|
+
end
|
51
|
+
end
|
29
52
|
end
|
30
53
|
|
31
54
|
def call(env)
|
@@ -47,6 +70,14 @@ module Octodown
|
|
47
70
|
socket = ::Faye::WebSocket.new(env)
|
48
71
|
|
49
72
|
socket.on(:open) do
|
73
|
+
@mutex.synchronize do
|
74
|
+
if @already_opened == false
|
75
|
+
puts '[INFO] Re-using octodown client from previous browser tab'
|
76
|
+
end
|
77
|
+
|
78
|
+
@already_opened = true
|
79
|
+
end
|
80
|
+
|
50
81
|
socket.send md
|
51
82
|
puts "Clients: #{@websockets.size}" if ENV['DEBUG']
|
52
83
|
end
|
@@ -80,6 +111,7 @@ module Octodown
|
|
80
111
|
|
81
112
|
def register_listener
|
82
113
|
Octodown::Support::Services::Riposter.call file do
|
114
|
+
puts '[INFO] Recompiling markdown...'
|
83
115
|
md = render_md(file)
|
84
116
|
@websockets.each do |socket|
|
85
117
|
socket.send md
|
@@ -91,13 +123,6 @@ module Octodown
|
|
91
123
|
f.rewind unless f.pos == 0
|
92
124
|
Renderer::GithubMarkdown.render f, options
|
93
125
|
end
|
94
|
-
|
95
|
-
def init_ws
|
96
|
-
require 'rack'
|
97
|
-
require 'faye/websocket'
|
98
|
-
|
99
|
-
Faye::WebSocket.load_adapter 'thin'
|
100
|
-
end
|
101
126
|
end
|
102
127
|
end # Support
|
103
128
|
end # Octodown
|
data/lib/octodown/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: octodown
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.4.
|
4
|
+
version: 1.4.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ian Ker-Seymer
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-04-
|
11
|
+
date: 2016-04-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: github-markup
|
@@ -123,47 +123,47 @@ dependencies:
|
|
123
123
|
- !ruby/object:Gem::Version
|
124
124
|
version: 1.6.4
|
125
125
|
- !ruby/object:Gem::Dependency
|
126
|
-
name:
|
126
|
+
name: listen
|
127
127
|
requirement: !ruby/object:Gem::Requirement
|
128
128
|
requirements:
|
129
129
|
- - "~>"
|
130
130
|
- !ruby/object:Gem::Version
|
131
|
-
version:
|
131
|
+
version: 3.0.3
|
132
132
|
type: :runtime
|
133
133
|
prerelease: false
|
134
134
|
version_requirements: !ruby/object:Gem::Requirement
|
135
135
|
requirements:
|
136
136
|
- - "~>"
|
137
137
|
- !ruby/object:Gem::Version
|
138
|
-
version:
|
138
|
+
version: 3.0.3
|
139
139
|
- !ruby/object:Gem::Dependency
|
140
|
-
name:
|
140
|
+
name: faye-websocket
|
141
141
|
requirement: !ruby/object:Gem::Requirement
|
142
142
|
requirements:
|
143
143
|
- - "~>"
|
144
144
|
- !ruby/object:Gem::Version
|
145
|
-
version:
|
145
|
+
version: 0.10.0
|
146
146
|
type: :runtime
|
147
147
|
prerelease: false
|
148
148
|
version_requirements: !ruby/object:Gem::Requirement
|
149
149
|
requirements:
|
150
150
|
- - "~>"
|
151
151
|
- !ruby/object:Gem::Version
|
152
|
-
version:
|
152
|
+
version: 0.10.0
|
153
153
|
- !ruby/object:Gem::Dependency
|
154
|
-
name:
|
154
|
+
name: puma
|
155
155
|
requirement: !ruby/object:Gem::Requirement
|
156
156
|
requirements:
|
157
157
|
- - "~>"
|
158
158
|
- !ruby/object:Gem::Version
|
159
|
-
version:
|
159
|
+
version: 3.4.0
|
160
160
|
type: :runtime
|
161
161
|
prerelease: false
|
162
162
|
version_requirements: !ruby/object:Gem::Requirement
|
163
163
|
requirements:
|
164
164
|
- - "~>"
|
165
165
|
- !ruby/object:Gem::Version
|
166
|
-
version:
|
166
|
+
version: 3.4.0
|
167
167
|
- !ruby/object:Gem::Dependency
|
168
168
|
name: rspec
|
169
169
|
requirement: !ruby/object:Gem::Requirement
|