docwatch-bin 2.4.2 → 2.7.0

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: 111689573811afcf77ecae63b7ff791cb13cd0a57a2396699028d5f00f477477
4
- data.tar.gz: b1eb2983e15aed8b0020d6f15cc4319017ec66a1ee757329e771065069ad7fd6
3
+ metadata.gz: 3ddc0126c46e08dfd0af49f1028ee92a4bfef1b514d7a22f766d1fa7e03e7c60
4
+ data.tar.gz: 9fc3d2e2b6395170f909fef7feb6c18c7588d17a47f86b57d953810919855ec2
5
5
  SHA512:
6
- metadata.gz: 60dca5f3e30f8c2e9becec5ebf69f85e8abf3214472cff1acf79f7be4c5ecd081b2354efc203e3c47d9e211d32ae65adfb811de947d75bdde4fca04cbb7b6086
7
- data.tar.gz: 6c2ab9e155a31552041dc99fea3ae52d171427a6d8d5c701d523591e99518c8a01545aebda70de826a191303cafdb6a707848adda7cea853ae8f0ef9dfe22663
6
+ metadata.gz: 300eea8d4c9785b6f501b5f89cf1e0cde40a0a2e02da3f9b2634b779060f0b25d330e5c29975f48f303f090901451d9a76955a4c71e7978b0d8b89de89f7ef7c
7
+ data.tar.gz: 674e64b87624473666b6b900e473f2c0746f456dd5d3dc0e69e5e4346d9fa461f02580cccdc11e0b6d03184dc5fec1a4e661ad4306701e2f0a5a5f67192d70bb
data/bin/docwatch CHANGED
@@ -7,6 +7,8 @@ Params = Struct.new(
7
7
  :version,
8
8
  :file_path,
9
9
  :default_styles,
10
+ :style,
11
+ :output,
10
12
  keyword_init: true,
11
13
  )
12
14
 
@@ -25,6 +27,8 @@ class Main
25
27
  version: @opts['--version'],
26
28
  file_path: @opts['<file-path>'],
27
29
  default_styles: @opts['--default-styles'],
30
+ style: @opts['--style'],
31
+ output: @opts['--output'],
28
32
  )
29
33
  end
30
34
 
@@ -41,7 +45,7 @@ class Main
41
45
  'http://localhost:%s' % port
42
46
  end
43
47
 
44
- def port_valid
48
+ def port_valid?
45
49
  true
46
50
  end
47
51
 
@@ -67,11 +71,25 @@ class Main
67
71
  def run
68
72
  exit_version if params.version
69
73
  exit_invalid_file unless File.exist?(params.file_path)
70
- exit_invalid_port unless port_valid
71
74
 
72
- renderer = Renderer.by_filetype(params.file_path, params.default_styles)
75
+ config = Docwatch::Config.new
76
+
77
+ if params.style && config.styles_path(profile: params.style).nil?
78
+ puts('Unknown or missing style profile: %s'.red % params.style)
79
+ exit 4
80
+ end
81
+
82
+ renderer = Renderer.by_filetype(params.file_path, params.default_styles, config, params.style)
73
83
  exit_unknown_renderer if renderer.nil?
74
84
 
85
+ if params.output
86
+ File.write(params.output, renderer.to_html(static: true))
87
+ puts 'Wrote %s'.green % params.output
88
+ exit 0
89
+ end
90
+
91
+ exit_invalid_port unless port_valid?
92
+
75
93
  server = TCPServer.new(port)
76
94
  logger = Logger.new(params.verbose)
77
95
  watcher = Watcher.new(params.file_path)
@@ -110,8 +128,10 @@ usage = <<~EOF
110
128
  #{PROGRAM_NAME} --version
111
129
 
112
130
  Options:
131
+ -o, --output FILE Render once to file and exit
113
132
  -p, --port VALUE Listen port [default: 8888]
114
133
  Set to 'random' for a random port
134
+ -s, --style NAME Use named style profile
115
135
  -d, --default-styles Use default styling
116
136
  --verbose Be verbose
117
137
  -v, --version Show version
@@ -0,0 +1,52 @@
1
+ module Docwatch
2
+ class Config
3
+ def initialize
4
+ @config_dir = ENV.fetch('XDG_CONFIG_HOME', File.expand_path('~/.config'))
5
+ @dir = File.join(@config_dir, 'org.crdx', 'docwatch')
6
+ @data = load
7
+ end
8
+
9
+ def styles_path(profile: nil)
10
+ name = profile || @data&.dig('profile')
11
+
12
+ if name
13
+ profile_path(name)
14
+ else
15
+ legacy_path
16
+ end
17
+ end
18
+
19
+ def profiles
20
+ @data&.dig('profiles') || {}
21
+ end
22
+
23
+ private
24
+
25
+ def profile_path(name)
26
+ file = profiles[name]
27
+ return nil unless file
28
+
29
+ path = File.join(@dir, file)
30
+ path if File.exist?(path)
31
+ end
32
+
33
+ def legacy_path
34
+ path = File.join(@dir, 'styles.css')
35
+ return path if File.exist?(path)
36
+
37
+ # Old location: $XDG_CONFIG_HOME/docwatch/styles.css
38
+ old = File.join(@config_dir, 'docwatch', 'styles.css')
39
+ old if File.exist?(old)
40
+ end
41
+
42
+ def load
43
+ path = File.join(@dir, 'config.toml')
44
+ return nil unless File.exist?(path)
45
+
46
+ TomlRB.parse(File.read(path))
47
+ rescue TomlRB::ParseError => e
48
+ $stderr.puts('Warning: failed to parse %s: %s' % [path, e.message])
49
+ nil
50
+ end
51
+ end
52
+ end
@@ -13,12 +13,12 @@ module Docwatch
13
13
 
14
14
  def css
15
15
  return default_css if @default_styles
16
+ return default_css unless @config
16
17
 
17
- config_dir = ENV.fetch('XDG_CONFIG_HOME', File.expand_path('~/.config'))
18
- styles_path = File.join(config_dir, 'docwatch', 'styles.css')
18
+ path = @config.styles_path(profile: @style)
19
19
 
20
- if File.exist?(styles_path)
21
- File.read(styles_path)
20
+ if path
21
+ File.read(path)
22
22
  else
23
23
  default_css
24
24
  end
@@ -7,39 +7,33 @@ module Docwatch
7
7
  (@@extensions[sym] ||= []) << self
8
8
  end
9
9
 
10
- def self.by_filetype(file_path, default_styles)
10
+ def self.by_filetype(file_path, default_styles, config = nil, style = nil)
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, default_styles)
14
+ @@extensions[extname.to_sym].first.new(file_path, default_styles, config, style)
15
15
  end
16
16
 
17
- def initialize(file_path, default_styles)
17
+ def initialize(file_path, default_styles, config = nil, style = nil)
18
18
  @file_path = file_path
19
19
  @default_styles = default_styles
20
+ @config = config
21
+ @style = style
20
22
  end
21
23
 
22
24
  def js
23
25
  File.read(Docwatch.root_dir + '/res/inject.js')
24
26
  end
25
27
 
26
- def to_html
27
- return <<~EOF
28
- <!doctype html>
29
- <html>
30
- <head>
31
- #{head}
32
- </head>
33
- <body>
34
- #{body}
35
- <script>
36
- (function() {
37
- #{js}
38
- })()
39
- </script>
40
- </body>
41
- </html>
42
- EOF
28
+ def to_html(static: false)
29
+ parts = ['<!doctype html>', '<html>', '<head>', head, '</head>', '<body>', body]
30
+
31
+ if !static
32
+ parts << "<script>\n(function() {\n#{js}\n})()\n</script>"
33
+ end
34
+
35
+ parts.push('</body>', '</html>')
36
+ parts.join("\n")
43
37
  end
44
38
 
45
39
  protected
@@ -1,3 +1,3 @@
1
1
  module Docwatch
2
- VERSION = '2.4.2'
2
+ VERSION = '2.7.0'
3
3
  end
data/lib/docwatch.rb CHANGED
@@ -1,10 +1,10 @@
1
- require 'require_all'
2
1
  require 'rouge'
3
2
  require 'rouge/plugins/redcarpet'
4
3
  require 'redcarpet'
5
4
  require 'colorize'
6
5
  require 'nokogiri'
7
6
  require 'docopt'
7
+ require 'toml-rb'
8
8
 
9
9
  require 'ostruct'
10
10
  require 'socket'
@@ -18,4 +18,15 @@ module Docwatch
18
18
  end
19
19
  end
20
20
 
21
- require_rel 'docwatch'
21
+ require_relative 'docwatch/config'
22
+ require_relative 'docwatch/connection'
23
+ require_relative 'docwatch/logger'
24
+ require_relative 'docwatch/parser'
25
+ require_relative 'docwatch/parser/frontmatter'
26
+ require_relative 'docwatch/renderer'
27
+ require_relative 'docwatch/renderer/html'
28
+ require_relative 'docwatch/renderer/markdown'
29
+ require_relative 'docwatch/session'
30
+ require_relative 'docwatch/util/html'
31
+ require_relative 'docwatch/version'
32
+ require_relative 'docwatch/watcher'
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: docwatch-bin
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.4.2
4
+ version: 2.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - crdx
8
- autorequire:
9
8
  bindir: bin
10
9
  cert_chain: []
11
- date: 2024-05-12 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: colorize
@@ -81,33 +80,33 @@ dependencies:
81
80
  - !ruby/object:Gem::Version
82
81
  version: '3.5'
83
82
  - !ruby/object:Gem::Dependency
84
- name: require_all
83
+ name: rouge
85
84
  requirement: !ruby/object:Gem::Requirement
86
85
  requirements:
87
86
  - - "~>"
88
87
  - !ruby/object:Gem::Version
89
- version: '3.0'
88
+ version: '4.0'
90
89
  type: :runtime
91
90
  prerelease: false
92
91
  version_requirements: !ruby/object:Gem::Requirement
93
92
  requirements:
94
93
  - - "~>"
95
94
  - !ruby/object:Gem::Version
96
- version: '3.0'
95
+ version: '4.0'
97
96
  - !ruby/object:Gem::Dependency
98
- name: rouge
97
+ name: toml-rb
99
98
  requirement: !ruby/object:Gem::Requirement
100
99
  requirements:
101
100
  - - "~>"
102
101
  - !ruby/object:Gem::Version
103
- version: '4.0'
102
+ version: '3.0'
104
103
  type: :runtime
105
104
  prerelease: false
106
105
  version_requirements: !ruby/object:Gem::Requirement
107
106
  requirements:
108
107
  - - "~>"
109
108
  - !ruby/object:Gem::Version
110
- version: '4.0'
109
+ version: '3.0'
111
110
  - !ruby/object:Gem::Dependency
112
111
  name: rake
113
112
  requirement: !ruby/object:Gem::Requirement
@@ -122,8 +121,6 @@ dependencies:
122
121
  - - "~>"
123
122
  - !ruby/object:Gem::Version
124
123
  version: '13.0'
125
- description:
126
- email:
127
124
  executables:
128
125
  - docwatch
129
126
  extensions: []
@@ -131,6 +128,7 @@ extra_rdoc_files: []
131
128
  files:
132
129
  - bin/docwatch
133
130
  - lib/docwatch.rb
131
+ - lib/docwatch/config.rb
134
132
  - lib/docwatch/connection.rb
135
133
  - lib/docwatch/logger.rb
136
134
  - lib/docwatch/parser.rb
@@ -149,7 +147,6 @@ licenses:
149
147
  - GPLv3
150
148
  metadata:
151
149
  rubygems_mfa_required: 'true'
152
- post_install_message:
153
150
  rdoc_options: []
154
151
  require_paths:
155
152
  - lib
@@ -164,8 +161,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
164
161
  - !ruby/object:Gem::Version
165
162
  version: '0'
166
163
  requirements: []
167
- rubygems_version: 3.3.25
168
- signing_key:
164
+ rubygems_version: 3.6.9
169
165
  specification_version: 4
170
166
  summary: Preview markdown documents in the browser with reload on change
171
167
  test_files: []