kdwatch 0.3.0 → 0.5.0

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
  SHA256:
3
- metadata.gz: 2a061720f05736d7be0f68e3e18887c799f94bdc5d83be4ac0b0553f7f65b822
4
- data.tar.gz: 66ba9346da80aa7a1587baa978163290c59f3f3f6255964fae1a2a89913c3047
3
+ metadata.gz: 2e2ba541b81a0758e14930c2daeeb13f8795ef86f13db41d2099ba2c863ae6a8
4
+ data.tar.gz: 225edec007a3005fb9e401888073d3e74fd6d92db622560685d812d0a37527ea
5
5
  SHA512:
6
- metadata.gz: a42cd6df0ec3c6c8562ab41809d7676162d08dd1b34993f4e3aa8010d1edbe4930bb94507489176996f15c55b7e43d4b29642913a8305e157d009bf5dc0567cb
7
- data.tar.gz: 50856210e599e8aa2e37af01da0e6173a349cd3d94858c3ff90f4b9b1ad5510a403fb11248f0f0fbe0f4a5c132a088c891a5412a5bdf0a90f6148a0490789302
6
+ metadata.gz: 7f61fd99900cb3e4b1951863424816438e7e426b84c3cc0e4854f4a64954f26e2ec56f13b08394d4c086fe2d9b919cd4fa66ed4486ef10daebace7d30767c0b1
7
+ data.tar.gz: 4c0853a737166b50b728d6ecbd29845c908fa5e1fcc4b07ea88bbd762c3b6f71b281a7429acbc07f452e3a1a6e9e18f29d7198b97e6d96edef98bbdaef8aa6ad
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Kdwatch
2
2
 
3
- Autoreloading display of [kramdown-rfc][] document in browser
3
+ Auto-formatting, auto-reloading display of formatted [kramdown-rfc][] document in browser
4
4
 
5
5
  [kramdown-rfc]: http://rfc.space
6
6
 
@@ -14,11 +14,11 @@ $ gem install kdwatch
14
14
 
15
15
  * For some reason, the initial `gem install` takes a couple of minutes,
16
16
  during the first few of which it may seem nothing happens.
17
- * If the above `pip3` doesn't work, no problem: in a pinch, kdrfc will
18
- use the IETF web service for xml2rfc processing (but that may be a
19
- bit slower).
20
- * Depending on system configuration, add `sudo` (but don't if it isn't
21
- actually needed).
17
+ * If the above `pip3` (or `pip`) doesn't work, no problem: in a pinch,
18
+ kdrfc will use the IETF web service for xml2rfc processing (but that
19
+ may be a bit slower).
20
+ * Depending on system configuration, add `sudo` on the pip/gem
21
+ commands (but don't if it isn't actually needed).
22
22
 
23
23
  ## Usage
24
24
 
@@ -34,12 +34,16 @@ $ kdwatch
34
34
  pop up with the URL to use, which depends on the options given, but
35
35
  defaults to <http://127.0.0.1:7991/>).
36
36
 
37
- Now, whenever you do an editor save of the markdown file, after a
38
- couple of seconds (1.6 s for my Intel Mac, 0.8 s for my M1 Mac) you
39
- see an updated HTML in the browser.
37
+ Now, whenever you do an editor save of the kramdown-rfc markdown file,
38
+ kdwatch auto-formats and, after a couple of seconds(*), you see an
39
+ updated HTML in the browser without pressing buttons or switching windows.
40
40
 
41
41
  You will need to keep the `kdwatch` terminal/screen open to see
42
42
  potential error messages, e.g., if you break the markdown in some way.
43
+ (The author uses an Emacs "Async Shell Command" buffer for that.)
44
+
45
+ (*) The latency depends on your computer and a bit on the size of the
46
+ file, say, around 1.6 s for my Intel Mac, 0.8 s for my M1 Mac.
43
47
 
44
48
  ### There can only be one (per host/port)
45
49
 
data/bin/kdwatch CHANGED
@@ -6,11 +6,24 @@ ENV["KRAMDOWN_PERSISTENT"]="yes"
6
6
 
7
7
  require 'optparse'
8
8
  require 'ostruct'
9
+ require 'socket'
9
10
 
10
11
  require_relative "../lib/kdwatch/version"
11
12
 
12
13
  KDWATCH_PORT = 7991 # currently unregistered...
13
14
 
15
+ def socket_is_free(host, port, uri)
16
+ begin
17
+ TCPSocket.new(host, port, connect_timeout: 1)
18
+ rescue Errno::ECONNREFUSED => e
19
+ return true
20
+ rescue => e
21
+ warn "*** #{uri} -- #{e.inspect}"
22
+ return nil # break, but don't use
23
+ end
24
+ return false
25
+ end
26
+
14
27
  options = OpenStruct.new
15
28
 
16
29
  op = OptionParser.new do |opts|
@@ -30,7 +43,7 @@ BANNER
30
43
  opts.on("-r", "--[no-]replace", "Replace existing server")
31
44
  opts.on("-oNAME", "--host=NAME", String, "Server host (127.0.0.1)")
32
45
  opts.on("-i", "--internet", 'Abbr. "on the Internet" (host = "::")')
33
- opts.on("-pNUM", "--port=NUM", Integer, "Port number (#{KDWATCH_PORT})")
46
+ opts.on("-pNUM", "--port=NUM", Integer, "Port number (#{KDWATCH_PORT}...)")
34
47
  opts.on("-[1-6]", "--[1-6]", Integer, "Abbr. port number (#{KDWATCH_PORT/10}x), must be last")
35
48
  end
36
49
  begin
@@ -52,7 +65,26 @@ if short_port = options[""]
52
65
  warn "** overriding port #{options.port} with #{port}" if options.port
53
66
  options.port = port
54
67
  else
55
- options.port ||= KDWATCH_PORT
68
+ unless options.port
69
+ port = KDWATCH_PORT
70
+ host = options.host
71
+ host = "[#{host}]" if host =~ /:/
72
+ uri = nil
73
+ found = false
74
+ 100.times do
75
+ uri = "http://#{host}:#{port}"
76
+ # warn "Trying URI #{uri}"
77
+ found = socket_is_free(options.host, port, uri)
78
+ break unless found == false
79
+ port += 1
80
+ end
81
+ unless found
82
+ warn "*** Cannot find port number available to serve from!"
83
+ exit 1
84
+ end
85
+ warn "*** Using URI: #{uri}"
86
+ options.port = port
87
+ end
56
88
  end
57
89
 
58
90
  # p options
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Kdwatch
4
- VERSION = "0.3.0"
4
+ VERSION = "0.5.0"
5
5
  end
data/lib/kdwatch-app.rb CHANGED
@@ -9,7 +9,7 @@ require "rack-livereload"
9
9
  require "guard"
10
10
  require "sinatra"
11
11
  require "kramdown-rfc2629"
12
- ENV["KDRFC_PREPEND"] = "time"
12
+ ENV["KDRFC_PREPEND"] = "time" if system("time", "true", err: "/dev/null")
13
13
  require "kramdown-rfc/kdrfc-processor"
14
14
  require "net/http/persistent"
15
15
 
@@ -40,7 +40,18 @@ get "/" do
40
40
  warn "...done"
41
41
  end
42
42
  end
43
- File.read(dfn)
43
+ dfc = File.stat(dfn).ctime rescue Time.at(0)
44
+ ret = File.read(dfn)
45
+ if sfc > dfc # somehow the above went wrong
46
+ ret.gsub!(<<CSS, <<RED)
47
+ /* general and mobile first */
48
+ html {
49
+ CSS
50
+ /* general and mobile first */
51
+ html { border: 5px solid red;
52
+ RED
53
+ end
54
+ ret
44
55
  end
45
56
 
46
57
  get "/metadata.min.js" do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kdwatch
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Carsten Bormann
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-07-10 00:00:00.000000000 Z
11
+ date: 2022-05-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -157,7 +157,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
157
157
  - !ruby/object:Gem::Version
158
158
  version: '0'
159
159
  requirements: []
160
- rubygems_version: 3.2.22
160
+ rubygems_version: 3.3.11
161
161
  signing_key:
162
162
  specification_version: 4
163
163
  summary: 'kdwatch: open auto-reloaded HTML for kramdown-rfc in a browser.'