docwatch-bin 1.1.1 → 1.1.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/docwatch +25 -31
- data/lib/docwatch/connection.rb +7 -5
- data/lib/docwatch/renderer/markdown.rb +2 -2
- data/lib/docwatch/renderer.rb +2 -3
- data/lib/docwatch/session.rb +17 -9
- data/lib/docwatch/version.rb +1 -1
- data/lib/docwatch/watcher.rb +1 -1
- data/lib/docwatch.rb +1 -1
- metadata +30 -30
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 365505a045416de99180ea9c1cf68a9471499ac2a6c26c251018a4816ae025c1
|
4
|
+
data.tar.gz: 989e62d45cdb2bfd45f6892683c70c5edf18f392d384da347fd346a1b443034a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4f066bf2f71eb36305e30f0542581a4df0cc8258bbf112fdfe1653aeeb8644033cc13d07b9be76f054d7fe5eabe134d41617b9978a961168881aef2c8cfe650e
|
7
|
+
data.tar.gz: d2899529b2d2120629bbf028f10a8754e8b09f18787bfcfb87aee1704e3d596f642d646d18f45bd18fd756f66898509801b5b73134015511fa7f83c5c84a2ee0
|
data/bin/docwatch
CHANGED
@@ -15,17 +15,16 @@ class Main
|
|
15
15
|
@params ||= OpenStruct.new({
|
16
16
|
verbose: @opts['--verbose'],
|
17
17
|
version: @opts['--version'],
|
18
|
-
|
19
|
-
file_path: @opts['<file-path>']
|
18
|
+
file_path: @opts['<file-path>'],
|
20
19
|
})
|
21
20
|
end
|
22
21
|
|
23
22
|
def port
|
24
|
-
|
23
|
+
if @opts['--port'] == 'random'
|
25
24
|
# TODO: check if this port is in use
|
26
|
-
|
25
|
+
@port ||= 10_000 + Random.random_number(50_000)
|
27
26
|
else
|
28
|
-
@opts['--port']
|
27
|
+
@port ||= @opts['--port']
|
29
28
|
end
|
30
29
|
end
|
31
30
|
|
@@ -37,11 +36,6 @@ class Main
|
|
37
36
|
true
|
38
37
|
end
|
39
38
|
|
40
|
-
def exit_usage
|
41
|
-
puts DOCS
|
42
|
-
exit 0
|
43
|
-
end
|
44
|
-
|
45
39
|
def exit_version
|
46
40
|
puts Docwatch::VERSION
|
47
41
|
exit 0
|
@@ -63,7 +57,6 @@ class Main
|
|
63
57
|
|
64
58
|
def run
|
65
59
|
exit_version if params.version
|
66
|
-
exit_usage if params.help
|
67
60
|
exit_invalid_file unless File.exist?(params.file_path)
|
68
61
|
exit_invalid_port unless port_valid
|
69
62
|
|
@@ -75,12 +68,12 @@ class Main
|
|
75
68
|
watcher = Watcher.new(params.file_path)
|
76
69
|
|
77
70
|
Thread.new do
|
78
|
-
while socket = server.accept
|
71
|
+
while (socket = server.accept)
|
79
72
|
Thread.new do
|
80
73
|
Connection.handle(
|
81
74
|
renderer,
|
82
75
|
watcher,
|
83
|
-
Session.new(socket, logger)
|
76
|
+
Session.new(socket, logger),
|
84
77
|
)
|
85
78
|
end
|
86
79
|
end
|
@@ -90,40 +83,41 @@ class Main
|
|
90
83
|
puts 'Press enter to open page in the default handler (xdg-open)'.green
|
91
84
|
|
92
85
|
begin
|
93
|
-
while
|
86
|
+
while $stdin.gets
|
94
87
|
system('xdg-open %s' % url)
|
95
88
|
end
|
96
|
-
rescue Interrupt
|
89
|
+
rescue Interrupt
|
97
90
|
puts
|
98
91
|
puts 'Bye'
|
99
92
|
end
|
100
93
|
end
|
101
94
|
end
|
102
95
|
|
103
|
-
|
104
|
-
|
96
|
+
usage = <<~EOF
|
97
|
+
Usage:
|
105
98
|
#{File.basename($0)} [options] <file-path>
|
99
|
+
#{File.basename($0)} ( --version | --help )
|
106
100
|
|
107
|
-
|
101
|
+
Options:
|
108
102
|
-p, --port=VALUE Listen port [default: 8888]
|
109
|
-
|
110
|
-
-
|
103
|
+
--verbose Be verbose
|
104
|
+
-v, --version Show version
|
111
105
|
-h, --help Show this help
|
112
106
|
|
113
|
-
|
114
|
-
markdown
|
115
|
-
html
|
107
|
+
Renderers:
|
108
|
+
markdown (.md)
|
109
|
+
html (.html)
|
116
110
|
|
117
|
-
If #{'--port'.bold} is #{'random'.bold} a random port will be chosen, otherwise
|
118
|
-
|
111
|
+
If #{'--port'.bold} is #{'random'.bold} a random port will be chosen, otherwise the specified
|
112
|
+
one will be used. The default is 8888.
|
119
113
|
|
120
|
-
In #{'--verbose'.bold} mode, incoming HTTP requests and file change event
|
121
|
-
|
114
|
+
In #{'--verbose'.bold} mode, incoming HTTP requests and file change event notifications will be
|
115
|
+
printed to standard output.
|
122
116
|
EOF
|
123
117
|
|
124
118
|
begin
|
125
|
-
Main.run(Docopt
|
126
|
-
rescue Docopt::Exit
|
127
|
-
puts
|
128
|
-
exit
|
119
|
+
Main.run(Docopt.docopt(usage))
|
120
|
+
rescue Docopt::Exit
|
121
|
+
puts usage
|
122
|
+
exit 2
|
129
123
|
end
|
data/lib/docwatch/connection.rb
CHANGED
@@ -12,11 +12,13 @@ module Docwatch
|
|
12
12
|
|
13
13
|
def handle
|
14
14
|
case @session.path
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
15
|
+
when '/'
|
16
|
+
@session.respond_with_html(@renderer.to_html)
|
17
|
+
when '/wait'
|
18
|
+
@watcher.wait
|
19
|
+
@session.respond_with_text('OK')
|
20
|
+
else
|
21
|
+
@session.respond_with_404
|
20
22
|
end
|
21
23
|
end
|
22
24
|
end
|
data/lib/docwatch/renderer.rb
CHANGED
@@ -10,6 +10,7 @@ module Docwatch
|
|
10
10
|
def self.by_filetype(file_path)
|
11
11
|
extname = File.extname(file_path)[1..]
|
12
12
|
return if extname.length == 0
|
13
|
+
|
13
14
|
@@extensions[extname.to_sym].first.new(file_path)
|
14
15
|
end
|
15
16
|
|
@@ -44,9 +45,7 @@ module Docwatch
|
|
44
45
|
|
45
46
|
protected
|
46
47
|
|
47
|
-
|
48
|
-
@file_path
|
49
|
-
end
|
48
|
+
attr_reader :file_path
|
50
49
|
|
51
50
|
def contents
|
52
51
|
File.read(@file_path)
|
data/lib/docwatch/session.rb
CHANGED
@@ -4,7 +4,7 @@ module Docwatch
|
|
4
4
|
@socket = socket
|
5
5
|
@logger = logger
|
6
6
|
|
7
|
-
logger.log
|
7
|
+
logger.log(first_request_line)
|
8
8
|
end
|
9
9
|
|
10
10
|
def close
|
@@ -12,22 +12,28 @@ module Docwatch
|
|
12
12
|
end
|
13
13
|
|
14
14
|
def path
|
15
|
-
|
16
|
-
|
15
|
+
if first_request_line.nil? || first_request_line.length == 0
|
16
|
+
return
|
17
|
+
end
|
18
|
+
|
19
|
+
first_request_line.split[1]
|
17
20
|
end
|
18
21
|
|
19
22
|
def respond_with_text(str)
|
20
|
-
respond_with(str, 'text/plain')
|
23
|
+
respond_with(200, str, 'text/plain')
|
21
24
|
end
|
22
25
|
|
23
26
|
def respond_with_html(str)
|
24
|
-
respond_with(str, 'text/html')
|
27
|
+
respond_with(200, str, 'text/html')
|
28
|
+
end
|
29
|
+
|
30
|
+
def respond_with_404
|
31
|
+
respond_with(404, 'Not Found', 'text/html')
|
25
32
|
end
|
26
33
|
|
27
|
-
def respond_with(str, content_type)
|
28
|
-
println 'HTTP/1.1
|
34
|
+
def respond_with(code, str, content_type)
|
35
|
+
println 'HTTP/1.1 %d' % code
|
29
36
|
println 'Content-Type: %s; charset=utf8' % content_type
|
30
|
-
# println 'Connection: close'
|
31
37
|
println
|
32
38
|
println str
|
33
39
|
|
@@ -37,7 +43,9 @@ module Docwatch
|
|
37
43
|
private
|
38
44
|
|
39
45
|
def input_lines
|
40
|
-
@input_lines ||= @socket.recvmsg[0].lines
|
46
|
+
@input_lines ||= @socket.recvmsg[0].lines
|
47
|
+
rescue
|
48
|
+
[]
|
41
49
|
end
|
42
50
|
|
43
51
|
def first_request_line
|
data/lib/docwatch/version.rb
CHANGED
data/lib/docwatch/watcher.rb
CHANGED
data/lib/docwatch.rb
CHANGED
metadata
CHANGED
@@ -1,99 +1,99 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: docwatch-bin
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- crdx
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-10-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: colorize
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: 0.8.1
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
26
|
+
version: 0.8.1
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
28
|
+
name: docopt
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
33
|
+
version: 0.6.1
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version:
|
40
|
+
version: 0.6.1
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
42
|
+
name: nokogiri
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version:
|
47
|
+
version: '1.10'
|
48
48
|
type: :runtime
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version:
|
54
|
+
version: '1.10'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
|
-
name:
|
56
|
+
name: redcarpet
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
59
|
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: '
|
61
|
+
version: '3.5'
|
62
62
|
type: :runtime
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: '
|
68
|
+
version: '3.5'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
|
-
name:
|
70
|
+
name: require_all
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
73
|
- - "~>"
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version: 0
|
75
|
+
version: '3.0'
|
76
76
|
type: :runtime
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
80
|
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version: 0
|
82
|
+
version: '3.0'
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
|
-
name:
|
84
|
+
name: rake
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
86
86
|
requirements:
|
87
87
|
- - "~>"
|
88
88
|
- !ruby/object:Gem::Version
|
89
|
-
version:
|
89
|
+
version: '13.0'
|
90
90
|
type: :development
|
91
91
|
prerelease: false
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
93
93
|
requirements:
|
94
94
|
- - "~>"
|
95
95
|
- !ruby/object:Gem::Version
|
96
|
-
version:
|
96
|
+
version: '13.0'
|
97
97
|
- !ruby/object:Gem::Dependency
|
98
98
|
name: rspec
|
99
99
|
requirement: !ruby/object:Gem::Requirement
|
@@ -109,21 +109,21 @@ dependencies:
|
|
109
109
|
- !ruby/object:Gem::Version
|
110
110
|
version: '3.8'
|
111
111
|
- !ruby/object:Gem::Dependency
|
112
|
-
name:
|
112
|
+
name: simplecov
|
113
113
|
requirement: !ruby/object:Gem::Requirement
|
114
114
|
requirements:
|
115
115
|
- - "~>"
|
116
116
|
- !ruby/object:Gem::Version
|
117
|
-
version: '
|
117
|
+
version: '0'
|
118
118
|
type: :development
|
119
119
|
prerelease: false
|
120
120
|
version_requirements: !ruby/object:Gem::Requirement
|
121
121
|
requirements:
|
122
122
|
- - "~>"
|
123
123
|
- !ruby/object:Gem::Version
|
124
|
-
version: '
|
125
|
-
description:
|
126
|
-
email:
|
124
|
+
version: '0'
|
125
|
+
description:
|
126
|
+
email:
|
127
127
|
executables:
|
128
128
|
- docwatch
|
129
129
|
extensions: []
|
@@ -145,7 +145,7 @@ homepage: https://github.com/crdx/docwatch
|
|
145
145
|
licenses:
|
146
146
|
- MIT
|
147
147
|
metadata: {}
|
148
|
-
post_install_message:
|
148
|
+
post_install_message:
|
149
149
|
rdoc_options: []
|
150
150
|
require_paths:
|
151
151
|
- lib
|
@@ -153,15 +153,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
153
153
|
requirements:
|
154
154
|
- - ">="
|
155
155
|
- !ruby/object:Gem::Version
|
156
|
-
version: '0'
|
156
|
+
version: '3.0'
|
157
157
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
158
158
|
requirements:
|
159
159
|
- - ">="
|
160
160
|
- !ruby/object:Gem::Version
|
161
161
|
version: '0'
|
162
162
|
requirements: []
|
163
|
-
rubygems_version: 3.
|
164
|
-
signing_key:
|
163
|
+
rubygems_version: 3.2.21
|
164
|
+
signing_key:
|
165
165
|
specification_version: 4
|
166
166
|
summary: Preview markdown documents in the browser with reload on change
|
167
167
|
test_files: []
|