docwatch-bin 2.5.0 → 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: a594b9cebe2ecef012c75f8212c7259ad7d9aa274ae2c6322a6ced4299568e75
4
- data.tar.gz: bae4db60bef675d53dc8984386a0b3cc93ea8d07174a30b105c03369a06ceb8d
3
+ metadata.gz: 3ddc0126c46e08dfd0af49f1028ee92a4bfef1b514d7a22f766d1fa7e03e7c60
4
+ data.tar.gz: 9fc3d2e2b6395170f909fef7feb6c18c7588d17a47f86b57d953810919855ec2
5
5
  SHA512:
6
- metadata.gz: 035745675f3da094dac22de02d027f6e83e01fe2bd73155a919532cd8bfde423c5eee4fcb2ba4ba5a2066c3d2289851db41e2028a100cb89a6eaab50a2f9aba0
7
- data.tar.gz: c2e1a169500cd6034373e6f37931388fbe76fc5aef5a5ccd14ff84b73d20f11a4d655e9a0eba1218124a14b7cc8f118a4228d8602a3a165f26858b6d623bc7c2
6
+ metadata.gz: 300eea8d4c9785b6f501b5f89cf1e0cde40a0a2e02da3f9b2634b779060f0b25d330e5c29975f48f303f090901451d9a76955a4c71e7978b0d8b89de89f7ef7c
7
+ data.tar.gz: 674e64b87624473666b6b900e473f2c0746f456dd5d3dc0e69e5e4346d9fa461f02580cccdc11e0b6d03184dc5fec1a4e661ad4306701e2f0a5a5f67192d70bb
data/bin/docwatch CHANGED
@@ -7,6 +7,7 @@ Params = Struct.new(
7
7
  :version,
8
8
  :file_path,
9
9
  :default_styles,
10
+ :style,
10
11
  :output,
11
12
  keyword_init: true,
12
13
  )
@@ -26,6 +27,7 @@ class Main
26
27
  version: @opts['--version'],
27
28
  file_path: @opts['<file-path>'],
28
29
  default_styles: @opts['--default-styles'],
30
+ style: @opts['--style'],
29
31
  output: @opts['--output'],
30
32
  )
31
33
  end
@@ -70,7 +72,14 @@ class Main
70
72
  exit_version if params.version
71
73
  exit_invalid_file unless File.exist?(params.file_path)
72
74
 
73
- 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)
74
83
  exit_unknown_renderer if renderer.nil?
75
84
 
76
85
  if params.output
@@ -122,6 +131,7 @@ usage = <<~EOF
122
131
  -o, --output FILE Render once to file and exit
123
132
  -p, --port VALUE Listen port [default: 8888]
124
133
  Set to 'random' for a random port
134
+ -s, --style NAME Use named style profile
125
135
  -d, --default-styles Use default styling
126
136
  --verbose Be verbose
127
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,16 +7,18 @@ 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
@@ -24,18 +26,14 @@ module Docwatch
24
26
  end
25
27
 
26
28
  def to_html(static: false)
27
- return <<~EOF
28
- <!doctype html>
29
- <html>
30
- <head>
31
- #{head}
32
- </head>
33
- <body>
34
- #{body}
35
- #{static ? '' : "<script>\n(function() {\n#{js}\n})()\n</script>"}
36
- </body>
37
- </html>
38
- EOF
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")
39
37
  end
40
38
 
41
39
  protected
@@ -1,3 +1,3 @@
1
1
  module Docwatch
2
- VERSION = '2.5.0'
2
+ VERSION = '2.7.0'
3
3
  end
data/lib/docwatch.rb CHANGED
@@ -4,6 +4,7 @@ require 'redcarpet'
4
4
  require 'colorize'
5
5
  require 'nokogiri'
6
6
  require 'docopt'
7
+ require 'toml-rb'
7
8
 
8
9
  require 'ostruct'
9
10
  require 'socket'
@@ -17,6 +18,7 @@ module Docwatch
17
18
  end
18
19
  end
19
20
 
21
+ require_relative 'docwatch/config'
20
22
  require_relative 'docwatch/connection'
21
23
  require_relative 'docwatch/logger'
22
24
  require_relative 'docwatch/parser'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: docwatch-bin
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.5.0
4
+ version: 2.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - crdx
@@ -93,6 +93,20 @@ dependencies:
93
93
  - - "~>"
94
94
  - !ruby/object:Gem::Version
95
95
  version: '4.0'
96
+ - !ruby/object:Gem::Dependency
97
+ name: toml-rb
98
+ requirement: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - "~>"
101
+ - !ruby/object:Gem::Version
102
+ version: '3.0'
103
+ type: :runtime
104
+ prerelease: false
105
+ version_requirements: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - "~>"
108
+ - !ruby/object:Gem::Version
109
+ version: '3.0'
96
110
  - !ruby/object:Gem::Dependency
97
111
  name: rake
98
112
  requirement: !ruby/object:Gem::Requirement
@@ -114,6 +128,7 @@ extra_rdoc_files: []
114
128
  files:
115
129
  - bin/docwatch
116
130
  - lib/docwatch.rb
131
+ - lib/docwatch/config.rb
117
132
  - lib/docwatch/connection.rb
118
133
  - lib/docwatch/logger.rb
119
134
  - lib/docwatch/parser.rb