docwatch-bin 1.1.2 → 1.1.6

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7ab45880b0ec4a3dabedeec7ba8480d7201035a06ba11b90f7a7bd103ecd725f
4
- data.tar.gz: 27d24ba2beea3a03d344584313a1735668607afc5a04c5ee69d95786afc35921
3
+ metadata.gz: fab5dc94d05d184be658795e8470af249f9fdb4f3e8c8e0f376bb194f456b26e
4
+ data.tar.gz: 444cb4d3d3259107828b72077c2d77850860b4b10926fe9f86fbecb23577af2c
5
5
  SHA512:
6
- metadata.gz: 783df445e617e2896b9180f49a36af08c8adfee6b59224b9ef3fe18326cd6bc0033688ad3bce1aa06f1d492dc2b111de0a59f7c2d56126cf3ca70aad94cad34c
7
- data.tar.gz: 15ec12b7fc4d432d84b4c6202ee021b2a29c7c60fa85a412ba763a012a7362601a960fb9c5ca30fbf08343cd06072d07f5e9019c9fa124a5f798b74f867beefd
6
+ metadata.gz: d9424eccb478f69d96c2353088c998188593fcd25ac217e66fe0b705bfe3320aa3afe9bdcae1fcb198805d8526f1c2d88a5b098b586062733b38248b953982b0
7
+ data.tar.gz: 7c494c2bfef056300b98bb76320646d87e03c7fba80aac0426b14990d814b8d7f21549cae527543868c9c57ea0b6db7027592e822a2f5479308d95318220340a
data/bin/docwatch CHANGED
@@ -2,6 +2,13 @@
2
2
  require_relative '../lib/docwatch'
3
3
  include Docwatch
4
4
 
5
+ Params = Struct.new(
6
+ :verbose,
7
+ :version,
8
+ :file_path,
9
+ keyword_init: true,
10
+ )
11
+
5
12
  class Main
6
13
  def initialize(opts)
7
14
  @opts = opts
@@ -12,20 +19,19 @@ class Main
12
19
  end
13
20
 
14
21
  def params
15
- @params ||= OpenStruct.new({
22
+ @params ||= Params.new(
16
23
  verbose: @opts['--verbose'],
17
24
  version: @opts['--version'],
18
- help: @opts['--help'],
19
- file_path: @opts['<file-path>']
20
- })
25
+ file_path: @opts['<file-path>'],
26
+ )
21
27
  end
22
28
 
23
29
  def port
24
- @port ||= if @opts['--port'] == 'random'
30
+ if @opts['--port'] == 'random'
25
31
  # TODO: check if this port is in use
26
- 10000 + Random.random_number(50000)
32
+ @port ||= 10_000 + Random.random_number(50_000)
27
33
  else
28
- @opts['--port']
34
+ @port ||= @opts['--port']
29
35
  end
30
36
  end
31
37
 
@@ -37,11 +43,6 @@ class Main
37
43
  true
38
44
  end
39
45
 
40
- def exit_usage
41
- puts DOCS
42
- exit 0
43
- end
44
-
45
46
  def exit_version
46
47
  puts Docwatch::VERSION
47
48
  exit 0
@@ -63,7 +64,6 @@ class Main
63
64
 
64
65
  def run
65
66
  exit_version if params.version
66
- exit_usage if params.help
67
67
  exit_invalid_file unless File.exist?(params.file_path)
68
68
  exit_invalid_port unless port_valid
69
69
 
@@ -75,12 +75,12 @@ class Main
75
75
  watcher = Watcher.new(params.file_path)
76
76
 
77
77
  Thread.new do
78
- while socket = server.accept
78
+ while (socket = server.accept)
79
79
  Thread.new do
80
80
  Connection.handle(
81
81
  renderer,
82
82
  watcher,
83
- Session.new(socket, logger)
83
+ Session.new(socket, logger),
84
84
  )
85
85
  end
86
86
  end
@@ -90,40 +90,41 @@ class Main
90
90
  puts 'Press enter to open page in the default handler (xdg-open)'.green
91
91
 
92
92
  begin
93
- while STDIN.gets
93
+ while $stdin.gets
94
94
  system('xdg-open %s' % url)
95
95
  end
96
- rescue Interrupt => e
96
+ rescue Interrupt
97
97
  puts
98
98
  puts 'Bye'
99
99
  end
100
100
  end
101
101
  end
102
102
 
103
- docs = <<~EOF
104
- #{'Usage:'.bold}
103
+ usage = <<~EOF
104
+ Usage:
105
105
  #{File.basename($0)} [options] <file-path>
106
+ #{File.basename($0)} ( --version | --help )
106
107
 
107
- #{'Options:'.bold}
108
+ Options:
108
109
  -p, --port=VALUE Listen port [default: 8888]
109
- -v, --verbose Be verbose
110
- -V, --version Show version
110
+ --verbose Be verbose
111
+ -v, --version Show version
111
112
  -h, --help Show this help
112
113
 
113
- #{'Renderers:'.bold}
114
- markdown (.md)
115
- html (.html)
114
+ Renderers:
115
+ markdown (.md)
116
+ html (.html)
116
117
 
117
- If #{'--port'.bold} is #{'random'.bold} a random port will be chosen, otherwise
118
- the specified one will be used. The default is 8888.
118
+ If #{'--port'.bold} is #{'random'.bold} a random port will be chosen, otherwise the specified
119
+ one will be used. The default is 8888.
119
120
 
120
- In #{'--verbose'.bold} mode, incoming HTTP requests and file change event
121
- notifications will be printed to standard output.
121
+ In #{'--verbose'.bold} mode, incoming HTTP requests and file change event notifications will be
122
+ printed to standard output.
122
123
  EOF
123
124
 
124
125
  begin
125
- Main.run(Docopt::docopt(docs, version: VERSION))
126
- rescue Docopt::Exit => e
127
- puts e.message
128
- exit 1
126
+ Main.run(Docopt.docopt(usage))
127
+ rescue Docopt::Exit
128
+ puts usage
129
+ exit 2
129
130
  end
@@ -12,11 +12,13 @@ module Docwatch
12
12
 
13
13
  def handle
14
14
  case @session.path
15
- when '/'
16
- @session.respond_with_html @renderer.to_html
17
- when '/wait'
18
- @watcher.wait
19
- @session.respond_with_text 'OK'
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
@@ -16,8 +16,8 @@ module Docwatch
16
16
  Redcarpet::Markdown.new(
17
17
  Redcarpet::Render::HTML,
18
18
  fenced_code_blocks: true,
19
- autolink: true,
20
- tables: true,
19
+ autolink: true,
20
+ tables: true,
21
21
  footnotes: true,
22
22
  ).render(contents)
23
23
  end
@@ -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
- def file_path
48
- @file_path
49
- end
48
+ attr_reader :file_path
50
49
 
51
50
  def contents
52
51
  File.read(@file_path)
@@ -4,7 +4,7 @@ module Docwatch
4
4
  @socket = socket
5
5
  @logger = logger
6
6
 
7
- logger.log first_request_line
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
- return if first_request_line.length == 0
16
- first_request_line.split(' ')[1]
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 200'
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 rescue []
46
+ @input_lines ||= @socket.recvmsg[0].lines
47
+ rescue
48
+ []
41
49
  end
42
50
 
43
51
  def first_request_line
@@ -1,3 +1,3 @@
1
1
  module Docwatch
2
- VERSION = "1.1.2"
2
+ VERSION = '1.1.6'
3
3
  end
@@ -10,7 +10,7 @@ module Docwatch
10
10
 
11
11
  def wait
12
12
  now = mtime
13
- sleep 0.2 while mtime <= now
13
+ sleep(0.2) while mtime <= now
14
14
  end
15
15
  end
16
16
  end
data/lib/docwatch.rb CHANGED
@@ -9,7 +9,7 @@ require 'socket'
9
9
 
10
10
  module Docwatch
11
11
  def self.root_dir
12
- File.expand_path('../..', __FILE__)
12
+ File.expand_path('..', __dir__)
13
13
  end
14
14
  end
15
15
 
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.2
4
+ version: 1.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - crdx
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-02-06 00:00:00.000000000 Z
11
+ date: 2021-11-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: require_all
14
+ name: colorize
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '3.0'
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: '3.0'
26
+ version: 0.8.1
27
27
  - !ruby/object:Gem::Dependency
28
- name: redcarpet
28
+ name: docopt
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '3.5'
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: '3.5'
40
+ version: 0.6.1
41
41
  - !ruby/object:Gem::Dependency
42
- name: colorize
42
+ name: nokogiri
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: 0.8.1
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: 0.8.1
54
+ version: '1.10'
55
55
  - !ruby/object:Gem::Dependency
56
- name: nokogiri
56
+ name: redcarpet
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: '1.10'
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: '1.10'
68
+ version: '3.5'
69
69
  - !ruby/object:Gem::Dependency
70
- name: docopt
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.6.1
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.6.1
82
+ version: '3.0'
83
83
  - !ruby/object:Gem::Dependency
84
- name: simplecov
84
+ name: rake
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
87
  - - "~>"
88
88
  - !ruby/object:Gem::Version
89
- version: '0'
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: '0'
96
+ version: '13.0'
97
97
  - !ruby/object:Gem::Dependency
98
98
  name: rspec
99
99
  requirement: !ruby/object:Gem::Requirement
@@ -109,19 +109,19 @@ dependencies:
109
109
  - !ruby/object:Gem::Version
110
110
  version: '3.8'
111
111
  - !ruby/object:Gem::Dependency
112
- name: rake
112
+ name: simplecov
113
113
  requirement: !ruby/object:Gem::Requirement
114
114
  requirements:
115
115
  - - "~>"
116
116
  - !ruby/object:Gem::Version
117
- version: '13.0'
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: '13.0'
124
+ version: '0'
125
125
  description:
126
126
  email:
127
127
  executables:
@@ -144,7 +144,8 @@ files:
144
144
  homepage: https://github.com/crdx/docwatch
145
145
  licenses:
146
146
  - MIT
147
- metadata: {}
147
+ metadata:
148
+ rubygems_mfa_required: 'true'
148
149
  post_install_message:
149
150
  rdoc_options: []
150
151
  require_paths:
@@ -153,14 +154,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
153
154
  requirements:
154
155
  - - ">="
155
156
  - !ruby/object:Gem::Version
156
- version: '0'
157
+ version: '3.0'
157
158
  required_rubygems_version: !ruby/object:Gem::Requirement
158
159
  requirements:
159
160
  - - ">="
160
161
  - !ruby/object:Gem::Version
161
162
  version: '0'
162
163
  requirements: []
163
- rubygems_version: 3.2.7
164
+ rubygems_version: 3.2.29
164
165
  signing_key:
165
166
  specification_version: 4
166
167
  summary: Preview markdown documents in the browser with reload on change