octodown 1.4.1 → 1.4.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 060715e5ebab9c22e3f9cccc9b87f2888f2da006
4
- data.tar.gz: a53f8dc0b0024693d073f345274281416c56c8d7
3
+ metadata.gz: 6a531a7522c46d3268a13438f70d95a6cda40b44
4
+ data.tar.gz: 7aec5cd981f01c760edfb5398fb6daf9f5a52b9e
5
5
  SHA512:
6
- metadata.gz: 7d055ab5ff014d28beca6d8e93fce961bad0f9468a10ffd86490da6ade49df078ec811c414586f85708d95e2a2c87376a6c4be4bf569cca2038a32752c8d9157
7
- data.tar.gz: 3679b776ed450685a3469b8f2525ff6f914ce37aef844fbd94486ce74bf494479e0113543065dcf5e431cef26ba0c243854f6c07fd91384832162ff7e52b1ed7
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
- # We need to make sure the server has started before opening the
20
- # page in a browser. I hate relying on time here, but I can't think
21
- # of cleaner way currently.
22
- Thread.new do |t|
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
- Rack::Server.start app: app, Port: port
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
@@ -9,7 +9,6 @@ module Octodown
9
9
  regex = Regexp.new(file.path)
10
10
 
11
11
  @listener ||= Listen.to(path, only: regex) do
12
- puts "Reloading #{file.path}..."
13
12
  listener_callback.call
14
13
  end
15
14
 
@@ -1,3 +1,3 @@
1
1
  module Octodown
2
- VERSION = '1.4.1'.freeze
2
+ VERSION = '1.4.2'.freeze
3
3
  end
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.1
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-12 00:00:00.000000000 Z
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: thin
126
+ name: listen
127
127
  requirement: !ruby/object:Gem::Requirement
128
128
  requirements:
129
129
  - - "~>"
130
130
  - !ruby/object:Gem::Version
131
- version: 1.6.4
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: 1.6.4
138
+ version: 3.0.3
139
139
  - !ruby/object:Gem::Dependency
140
- name: listen
140
+ name: faye-websocket
141
141
  requirement: !ruby/object:Gem::Requirement
142
142
  requirements:
143
143
  - - "~>"
144
144
  - !ruby/object:Gem::Version
145
- version: 3.0.3
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: 3.0.3
152
+ version: 0.10.0
153
153
  - !ruby/object:Gem::Dependency
154
- name: faye-websocket
154
+ name: puma
155
155
  requirement: !ruby/object:Gem::Requirement
156
156
  requirements:
157
157
  - - "~>"
158
158
  - !ruby/object:Gem::Version
159
- version: 0.10.0
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: 0.10.0
166
+ version: 3.4.0
167
167
  - !ruby/object:Gem::Dependency
168
168
  name: rspec
169
169
  requirement: !ruby/object:Gem::Requirement