mdless 2.1.7 → 2.1.8

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: 3a7d200fbf2d90da97cf6ae65beecac52643ec377d2a60f7d8503ca2411694ea
4
- data.tar.gz: f35b88bdf439f3436ddf2e6cf0b835e8a23d5d5553721b0c35d75954af43013e
3
+ metadata.gz: 0f08302d14bfa27b06fd821e56f46b6a04049009df87ab024c368e7776209810
4
+ data.tar.gz: c14bd96efedeaa61eba790a1f2e2664df39f85839ad914ffccfe323ef3312ee5
5
5
  SHA512:
6
- metadata.gz: 906870b0032f1cba0a1c90be6ac2cb80f82c1abcb331470f75b02598d05d965996b2d2eb0a076b2651e32e9ae567334b693a9dffd702b517e15c5b8048f2e172
7
- data.tar.gz: e1874c241362b44607a357ec4e125bdc463ae3b3ab906bdf7237e1b782a6122b6f90d664210cf7dd1b964bf843adb1056adbacdd93b816f0bb31db4d92ad1cf5
6
+ metadata.gz: 633007f423725e003e3c7154262801738bf22b79485d09b99caf06a83486fdca50a0e8b91f7d9a4118dd43c2bd0404cccc31a55486a8db00500e82a95007edeb
7
+ data.tar.gz: 870af2c74618556db8a6621016f9cc603f424956adda3441f0e8043f661bb2fac22b7c6f0e1aaa655570b0d7234e2d6e12c625d5a8af89599f2061db42e622ec
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ 2.1.8
2
+ : --update-theme option to add any missing keys to your theme file
3
+ : Strip ul_char of any spaces before inserting
4
+
1
5
  2.1.7
2
6
  : Dedup and remove empty escape codes before output
3
7
  : Tables losing column alignment
@@ -555,7 +555,7 @@ module Redcarpet
555
555
  [
556
556
  indent,
557
557
  color('list bullet'),
558
- MDLess.theme['list']['ul_char'],
558
+ MDLess.theme['list']['ul_char'].strip,
559
559
  ' ',
560
560
  color('list color'),
561
561
  indent_lines(content, indent).strip,
@@ -146,6 +146,7 @@ module CLIMarkdown
146
146
  theme = File.expand_path("~/.config/mdless/#{theme}.theme")
147
147
  File.open(theme, 'w') { |f| f.puts(YAML.dump(MDLess.theme)) } unless File.exist?(theme)
148
148
  `#{ENV['EDITOR']} '#{theme}'`
149
+ Process.exit 0
149
150
  end
150
151
 
151
152
  default(:inline_footnotes, false)
@@ -212,10 +213,15 @@ module CLIMarkdown
212
213
  end
213
214
 
214
215
  default(:update_config, false)
215
- opts.on('--update_config', 'Update the configuration file with new keys and current command line options') do
216
+ opts.on('--update-config', '--update_config', 'Update the configuration file with new keys and current command line options') do
216
217
  MDLess.options[:update_config] = true
217
218
  end
218
219
 
220
+ default(:update_theme, false)
221
+ opts.on('--update-theme', 'Update the current theme file with all available keys') do
222
+ MDLess.options[:update_theme] = true
223
+ end
224
+
219
225
  default(:wiki_links, false)
220
226
  opts.on('--[no-]wiki-links', 'Highlight [[wiki links]]') do |opt|
221
227
  MDLess.options[:wiki_links] = opt
@@ -229,6 +235,17 @@ module CLIMarkdown
229
235
  exit 1
230
236
  end
231
237
 
238
+ if MDLess.options[:update_theme]
239
+ FileUtils.mkdir_p(File.dirname(config))
240
+
241
+ theme = MDLess.options[:theme] =~ /default/ ? 'mdless' : MDLess.options[:theme]
242
+ theme = File.join(File.dirname(config), "#{theme}.theme")
243
+ contents = YAML.dump(MDLess.theme)
244
+
245
+ File.open(theme, 'w') { |f| f.puts contents }
246
+ Process.exit 0
247
+ end
248
+
232
249
  if !File.exist?(config) || MDLess.options[:update_config]
233
250
  FileUtils.mkdir_p(File.dirname(config))
234
251
  File.open(config, 'w') do |f|
@@ -236,6 +253,7 @@ module CLIMarkdown
236
253
  opts.delete(:list)
237
254
  opts.delete(:section)
238
255
  opts.delete(:update_config)
256
+ opts.delete(:update_theme)
239
257
  opts = opts.keys.map(&:to_s).sort.map { |k| [k.to_sym, opts[k.to_sym]] }.to_h
240
258
  f.puts YAML.dump(opts)
241
259
  warn "Config file saved to #{config}"
data/lib/mdless/hash.rb CHANGED
@@ -1,8 +1,9 @@
1
1
  module CLIMarkdown
2
+ # Hash helpers
2
3
  class ::Hash
3
- def deep_merge(second)
4
- merger = proc { |key, v1, v2| Hash === v1 && Hash === v2 ? v1.merge(v2, &merger) : Array === v1 && Array === v2 ? v1 | v2 : [:undefined, nil, :nil].include?(v2) ? v1 : v2 }
5
- self.merge(second.to_h, &merger)
6
- end
4
+ def deep_merge(second)
5
+ merger = proc { |key, v1, v2| Hash === v1 && Hash === v2 ? v1.merge(v2, &merger) : Array === v1 && Array === v2 ? v1 | v2 : [:undefined, nil, :nil].include?(v2) ? v1 : v2 }
6
+ self.merge(second ? second.to_h : second, &merger)
7
+ end
7
8
  end
8
9
  end
data/lib/mdless/theme.rb CHANGED
@@ -118,16 +118,21 @@ module CLIMarkdown
118
118
  }
119
119
 
120
120
  def load_theme_file(theme_file)
121
- new_theme = YAML.load(IO.read(theme_file))
121
+ raise "Theme #{theme_file} doesn't exist" unless File.exist?(theme_file)
122
+
122
123
  begin
124
+ theme_contents = IO.read(theme_file)
125
+ new_theme = YAML.load(theme_contents)
123
126
  theme = THEME_DEFAULTS.deep_merge(new_theme)
124
127
  # # write merged theme back in case there are new keys since
125
128
  # # last updated
126
129
  # File.open(theme_file,'w') {|f|
127
130
  # f.puts theme.to_yaml
128
131
  # }
129
- rescue StandardError
132
+ rescue StandardError => e
130
133
  @log.warn('Error merging user theme')
134
+ warn e
135
+ warn e.backtrace
131
136
  theme = THEME_DEFAULTS
132
137
  if File.basename(theme_file) =~ /mdless\.theme/
133
138
  FileUtils.rm(theme_file)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module CLIMarkdown
4
- VERSION = '2.1.7'
4
+ VERSION = '2.1.8'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mdless
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.7
4
+ version: 2.1.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brett Terpstra