docwatch-bin 1.1.6 → 2.0.1

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: fab5dc94d05d184be658795e8470af249f9fdb4f3e8c8e0f376bb194f456b26e
4
- data.tar.gz: 444cb4d3d3259107828b72077c2d77850860b4b10926fe9f86fbecb23577af2c
3
+ metadata.gz: fa3e636f3b4e862d11696a5aea4b63df99c72bdd759eaeb07f09517653c32323
4
+ data.tar.gz: 20536056fbed0a73e38ffb614df419cc3497aae702c114a807de4893ffb09234
5
5
  SHA512:
6
- metadata.gz: d9424eccb478f69d96c2353088c998188593fcd25ac217e66fe0b705bfe3320aa3afe9bdcae1fcb198805d8526f1c2d88a5b098b586062733b38248b953982b0
7
- data.tar.gz: 7c494c2bfef056300b98bb76320646d87e03c7fba80aac0426b14990d814b8d7f21549cae527543868c9c57ea0b6db7027592e822a2f5479308d95318220340a
6
+ metadata.gz: f8987d0f03dd42ace0e7ad1ebdf4c8505968890f929f4af27ccb91b7b69f4f45aa9f0051d3228223feccf84de4b0b1c648963982776a0bc6e1bd9b8a9e299075
7
+ data.tar.gz: 325f71d82d130fc50b8ac7c688d5f85cd92a2119caccfd751d754257aa6c919e1fa554baa5f044a0ec52c964c01c4b39a449671cfed9a9a2d89865a7d2bc60db
data/bin/docwatch CHANGED
@@ -86,7 +86,7 @@ class Main
86
86
  end
87
87
  end
88
88
 
89
- puts ('Started server on %s, renderer %s' % [url, renderer.class]).yellow
89
+ puts 'Started server on %s, renderer %s'.yellow % [url, renderer.class]
90
90
  puts 'Press enter to open page in the default handler (xdg-open)'.green
91
91
 
92
92
  begin
@@ -95,21 +95,23 @@ class Main
95
95
  end
96
96
  rescue Interrupt
97
97
  puts
98
- puts 'Bye'
98
+ puts 'Bye!'
99
99
  end
100
100
  end
101
101
  end
102
102
 
103
+ PROGRAM_NAME = File.basename($PROGRAM_NAME)
104
+
103
105
  usage = <<~EOF
104
106
  Usage:
105
- #{File.basename($0)} [options] <file-path>
106
- #{File.basename($0)} ( --version | --help )
107
+ #{PROGRAM_NAME} [options] <file-path>
108
+ #{PROGRAM_NAME} ( --version | --help )
107
109
 
108
110
  Options:
109
111
  -p, --port=VALUE Listen port [default: 8888]
110
112
  --verbose Be verbose
111
113
  -v, --version Show version
112
- -h, --help Show this help
114
+ -h, --help Show help
113
115
 
114
116
  Renderers:
115
117
  markdown (.md)
@@ -0,0 +1,37 @@
1
+ module Docwatch
2
+ class Parser::Frontmatter < Parser
3
+ def self.split(str)
4
+ lines = str.lines
5
+
6
+ if lines.first.chomp != '---'
7
+ return [nil, str]
8
+ end
9
+
10
+ in_frontmatter = false
11
+ in_document = false
12
+ document = ''
13
+ frontmatter_yaml = ''
14
+
15
+ lines.each do |line|
16
+ if line.strip == '---'
17
+ in_frontmatter = !in_frontmatter
18
+ in_document = true if !in_frontmatter
19
+ elsif in_frontmatter
20
+ frontmatter_yaml += line
21
+ elsif in_document
22
+ document += line
23
+ end
24
+ end
25
+
26
+ [Frontmatter.new(frontmatter_yaml), document]
27
+ end
28
+
29
+ def initialize(yaml) # rubocop:disable Lint/MissingSuper
30
+ @data = YAML.safe_load(yaml)
31
+ end
32
+
33
+ def to_html
34
+ Util::HTML.render(@data)
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,4 @@
1
+ module Docwatch
2
+ class Parser # rubocop:disable Lint/EmptyClass
3
+ end
4
+ end
@@ -1,5 +1,5 @@
1
1
  module Docwatch
2
- class HtmlRenderer < Renderer
2
+ class Renderer::Html < Renderer
3
3
  extension :html
4
4
 
5
5
  def doc
@@ -1,5 +1,5 @@
1
1
  module Docwatch
2
- class MarkdownRenderer < Renderer
2
+ class Renderer::Markdown < Renderer
3
3
  extension :md
4
4
 
5
5
  def head
@@ -13,13 +13,35 @@ module Docwatch
13
13
  end
14
14
 
15
15
  def body
16
- Redcarpet::Markdown.new(
17
- Redcarpet::Render::HTML,
16
+ # https://github.com/vmg/redcarpet#and-its-like-really-simple-to-use
17
+ markdown_args = {
18
18
  fenced_code_blocks: true,
19
- autolink: true,
20
19
  tables: true,
20
+ no_intra_emphasis: true,
21
+ strikethrough: true,
22
+ space_after_headers: true,
23
+ superscript: true,
24
+ highlight: true,
21
25
  footnotes: true,
22
- ).render(contents)
26
+ }
27
+
28
+ # https://github.com/vmg/redcarpet#darling-i-packed-you-a-couple-renderers-for-lunch
29
+ html_args = {
30
+ with_toc_data: true,
31
+ link_attributes: { rel: 'noreferrer nofollow noopener' },
32
+ hard_wrap: true, # no need for trailing spaces to create new paragraphs
33
+ }
34
+
35
+ frontmatter, document = Parser::Frontmatter.split(contents)
36
+
37
+ if frontmatter
38
+ document = frontmatter.to_html + document
39
+ end
40
+
41
+ Redcarpet::Markdown.new(
42
+ Redcarpet::Render::HTML.new(html_args),
43
+ markdown_args,
44
+ ).render(document)
23
45
  end
24
46
  end
25
47
  end
@@ -0,0 +1,22 @@
1
+ module Docwatch
2
+ module Util
3
+ class HTML
4
+ def self.render(data)
5
+ case data
6
+ when Hash
7
+ rows = data.map do |(k, v)|
8
+ '<th>%s</th><td>%s</td>' % [HTML.render(k), HTML.render(v)]
9
+ end.join('</tr><tr>')
10
+ '<table><tr>%s</tr></table>' % rows
11
+ when Array
12
+ rows = data.map do |v|
13
+ '<li>%s</li>' % HTML.render(v)
14
+ end.join
15
+ '<ul>%s</ul>' % rows
16
+ else
17
+ CGI.escapeHTML(data.to_s)
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -1,3 +1,3 @@
1
1
  module Docwatch
2
- VERSION = '1.1.6'
2
+ VERSION = '2.0.1'
3
3
  end
data/lib/docwatch.rb CHANGED
@@ -6,6 +6,8 @@ require 'docopt'
6
6
 
7
7
  require 'ostruct'
8
8
  require 'socket'
9
+ require 'yaml'
10
+ require 'cgi'
9
11
 
10
12
  module Docwatch
11
13
  def self.root_dir
@@ -428,30 +428,3 @@
428
428
  background-color: initial;
429
429
  border: 0
430
430
  }
431
-
432
- .container .csv-data td,
433
- .container .csv-data th {
434
- padding: 5px;
435
- overflow: hidden;
436
- font-size: 12px;
437
- line-height: 1;
438
- text-align: left;
439
- white-space: nowrap
440
- }
441
-
442
- .container .csv-data .blob-num {
443
- padding: 10px 8px 9px;
444
- text-align: right;
445
- background: #fff;
446
- border: 0
447
- }
448
-
449
- .container .csv-data tr {
450
- border-top: 0
451
- }
452
-
453
- .container .csv-data th {
454
- font-weight: 600;
455
- background: #f6f8fa;
456
- border-top: 0
457
- }
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: docwatch-bin
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.6
4
+ version: 2.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - crdx
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-11-17 00:00:00.000000000 Z
11
+ date: 2022-10-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: colorize
@@ -133,17 +133,20 @@ files:
133
133
  - lib/docwatch.rb
134
134
  - lib/docwatch/connection.rb
135
135
  - lib/docwatch/logger.rb
136
+ - lib/docwatch/parser.rb
137
+ - lib/docwatch/parser/frontmatter.rb
136
138
  - lib/docwatch/renderer.rb
137
139
  - lib/docwatch/renderer/html.rb
138
140
  - lib/docwatch/renderer/markdown.rb
139
141
  - lib/docwatch/session.rb
142
+ - lib/docwatch/util/html.rb
140
143
  - lib/docwatch/version.rb
141
144
  - lib/docwatch/watcher.rb
142
145
  - res/github-markdown.css
143
146
  - res/inject.js
144
147
  homepage: https://github.com/crdx/docwatch
145
148
  licenses:
146
- - MIT
149
+ - GPLv3
147
150
  metadata:
148
151
  rubygems_mfa_required: 'true'
149
152
  post_install_message:
@@ -161,7 +164,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
161
164
  - !ruby/object:Gem::Version
162
165
  version: '0'
163
166
  requirements: []
164
- rubygems_version: 3.2.29
167
+ rubygems_version: 3.3.23
165
168
  signing_key:
166
169
  specification_version: 4
167
170
  summary: Preview markdown documents in the browser with reload on change