pandocomatic 0.2.2.0 → 0.2.2.1

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
  SHA1:
3
- metadata.gz: 17475912055aaa53d0a3113b5f48c79326ed2b6a
4
- data.tar.gz: f705fd3f20fa7b0b8136ff8b5673e0841fd27ad1
3
+ metadata.gz: 855c75e46b4727ccd6acf84d9ba735ffd800d8b5
4
+ data.tar.gz: a9f5e62d4e9fb6e857e6aea6ff5b8c7d9f8bf740
5
5
  SHA512:
6
- metadata.gz: b7276c19b1871049a7b9c6ae49c46dae39ee8fd4942820ea3fc207cf66a2c94913dc507c40009cff520e493d726dda3a9c3c67e9840afaff9b6ec4ff9ddd65f3
7
- data.tar.gz: 51e91ceb8504537f1646df08cc3b18f4f63e205ae0026eeb0e1871ada8a8b6d37fa809e193fb581558dbe1fb215ebf75b066d0fef85fc207047a90cb285f35db
6
+ metadata.gz: da17a2290744567aadb6327a6cf20c88ed700366e653ce73ea17f8fb422347a418c7747d81d47fe12e5e00dc493d5f4ed4343cbe45e8be06f96646dd6aea6419
7
+ data.tar.gz: 736633dc32721b84a7c62743cd11c77f944b12ced0f8b9378f4b2b11401ebef494aab32df5afb3a115cca642c780dc4cc9021b5d2a5c757042b05ddfb51b86df
@@ -66,7 +66,7 @@ module Pandocomatic
66
66
  @config = config
67
67
  @src = src
68
68
  @dst = dst
69
-
69
+
70
70
  if template_name.nil? or template_name.empty?
71
71
  @template_name = @config.determine_template @src
72
72
  else
@@ -199,7 +199,10 @@ module Pandocomatic
199
199
  # Pandoc multi-word options can have the multiple words separated by
200
200
  # both underscore (_) and dash (-).
201
201
  option = option.gsub "-", "_"
202
- converter.send option, value unless option == 'output' or option == 'use_extension'
202
+ converter.send option, value unless
203
+ option == 'output' or
204
+ option == 'use_extension' or
205
+ option == 'rename'
203
206
  # don't let pandoc write the output to enable postprocessing
204
207
  rescue
205
208
  warn "The pandoc option '#{option}' (with value '#{value}') is not recognized by paru. This option is skipped." if debug?
@@ -217,24 +220,43 @@ module Pandocomatic
217
220
  end
218
221
  end
219
222
 
223
+ # Preprocess the input
224
+ #
225
+ # @param input [String] the input to preprocess
226
+ # @param config [Hash] template
227
+ #
228
+ # @return [String] the generated output
220
229
  def preprocess(input, config = {})
221
230
  process input, 'preprocessors', config
222
231
  end
223
232
 
233
+ # Postprocess the input
234
+ #
235
+ # @param input [String] the input to postprocess
236
+ # @param config [Hash] template
237
+ #
238
+ # @return [String] the generated output
224
239
  def postprocess(input, config = {})
225
240
  process input, 'postprocessors', config
226
241
  end
227
242
 
243
+ # Run setup scripts
244
+ #
245
+ # @param config [Hash] template
228
246
  def setup(config = {})
229
247
  process "", 'setup', config
230
248
  end
231
249
 
250
+ # Run cleanup scripts
251
+ #
252
+ # @param config [Hash] template
232
253
  def cleanup(config = {})
233
254
  process "", 'cleanup', config
234
255
  end
235
256
 
236
257
  # Run the input string through a list of filters called processors. There
237
- # are to types: preprocessors and postprocessors
258
+ # are various types: preprocessors and postprocessors, setup and
259
+ # cleanup, and rename
238
260
  def process(input, type, config = {})
239
261
  if config.has_key? type then
240
262
  processors = config[type]
@@ -267,6 +289,9 @@ module Pandocomatic
267
289
 
268
290
  private
269
291
 
292
+ def run_processor
293
+ end
294
+
270
295
  def use_output_option(dst)
271
296
  OUTPUT_FORMATS.include?(File.extname(dst).slice(1..-1))
272
297
  end
@@ -231,35 +231,39 @@ module Pandocomatic
231
231
  def set_destination(dst, template_name, metadata)
232
232
  dir = File.dirname dst
233
233
 
234
+ # Use the output option when set.
234
235
  determine_output_in_pandoc = lambda do |pandoc|
235
236
  if pandoc.has_key? "output"
236
237
  output = pandoc["output"]
237
- if output.start_with? "/"
238
- # Treat as an absolute path. Note. this probably
239
- # does not work on windows?
240
- return output
241
- else
238
+ if not output.start_with? "/"
242
239
  # Put it relative to the current directory
243
- return File.join dir, output
240
+ output = File.join dir, output
244
241
  end
242
+ output
243
+ else
244
+ nil
245
245
  end
246
- return nil
247
246
  end
248
247
 
249
248
  destination = nil
249
+ rename_script = nil
250
250
 
251
251
  # Output option in pandoc property has precedence
252
252
  if metadata.has_pandocomatic?
253
253
  pandocomatic = metadata.pandocomatic
254
254
  if pandocomatic.has_key? "pandoc"
255
- destination = determine_output_in_pandoc.call pandocomatic["pandoc"]
255
+ pandoc = pandocomatic["pandoc"]
256
+ destination = determine_output_in_pandoc.call pandoc
257
+ rename_script = pandoc["rename"]
256
258
  end
257
259
  end
258
260
 
259
261
  # Output option in template's pandoc property is next
260
262
  if destination.nil? and not template_name.nil? and not template_name.empty? then
261
263
  if @templates[template_name].has_key? "pandoc"
262
- destination = determine_output_in_pandoc.call @templates[template_name]["pandoc"]
264
+ pandoc = @templates[template_name]["pandoc"]
265
+ destination = determine_output_in_pandoc.call pandoc
266
+ rename_script ||= pandoc["rename"]
263
267
  end
264
268
  end
265
269
 
@@ -267,6 +271,10 @@ module Pandocomatic
267
271
  # extension updated to the output format
268
272
  if destination.nil?
269
273
  destination = set_extension dst, template_name, metadata
274
+
275
+ if not rename_script.nil? then
276
+ destination = rename_destination(rename_script, destination)
277
+ end
270
278
  end
271
279
 
272
280
  destination
@@ -620,6 +628,39 @@ module Pandocomatic
620
628
  end
621
629
  return nil
622
630
  end
631
+
632
+ # Rename path by using rename script. If script fails somehow, warn
633
+ # and return the original destination.
634
+ #
635
+ # @param rename_script [String] absolute path to script to run
636
+ # @param dst [String] original destination to rename
637
+ def rename_destination(rename_script, dst)
638
+ script = update_path(rename_script, File.dirname(dst))
639
+
640
+ command, *parameters = script.shellsplit # split on spaces unless it is preceded by a backslash
641
+
642
+ if not File.exists? command
643
+ command = Configuration.which(command)
644
+ script = "#{command} #{parameters.join(' ')}"
645
+
646
+ raise ProcessorError.new(:script_does_not_exist, nil, command) if command.nil?
647
+ end
648
+
649
+ raise ProcessorError.new(:script_is_not_executable, nil, command) unless File.executable? command
650
+
651
+ begin
652
+ renamed_dst = Processor.run(script, dst)
653
+ if not renamed_dst.nil? and not renamed_dst.empty?
654
+ renamed_dst.strip
655
+ else
656
+ raise StandardError,new("Running rename script '#{script}' on destination '#{dst}' did not result in a renamed destination.")
657
+ dst
658
+ end
659
+ rescue StandardError => e
660
+ ProcessorError.new(:error_processing_script, e, [script, dst])
661
+ dst
662
+ end
663
+ end
623
664
 
624
665
  def marshal_dump()
625
666
  [@data_dir, @settings, @templates, @convert_patterns]
@@ -50,7 +50,7 @@ module Pandocomatic
50
50
  ERROR_STATUS = 1266 # This is the sum of the ascii values of the characters in 'pandocomatic'
51
51
 
52
52
  # Pandocomatic's current version
53
- VERSION = [0, 2, 2, 0]
53
+ VERSION = [0, 2, 2, 1]
54
54
 
55
55
  # Pandocomatic's default configuration file
56
56
  CONFIG_FILE = 'pandocomatic.yaml'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pandocomatic
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2.0
4
+ version: 0.2.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Huub de Beer
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-12-20 00:00:00.000000000 Z
11
+ date: 2018-01-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: paru