pandocomatic 0.2.1.1 → 0.2.2.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
  SHA1:
3
- metadata.gz: 741eb81107f1b196f3032903067452e0e502ad63
4
- data.tar.gz: 145818d50f2c8dd74e7ee38dc7e32d11305ae27c
3
+ metadata.gz: 17475912055aaa53d0a3113b5f48c79326ed2b6a
4
+ data.tar.gz: f705fd3f20fa7b0b8136ff8b5673e0841fd27ad1
5
5
  SHA512:
6
- metadata.gz: aadb3e5fb153ca4790ac558dc552a5193aceb518c7cd8966c04101aad0bfa883827addb9f01b02abbefbfa7c393c9b3622b110fd3e8d8f5b02e33ef1950d1717
7
- data.tar.gz: 1993a9d9335a9899076729e68bb6220722154461493a274f2d0618fe827518f637f5515438e92939356446c65b326c9a301bccf00bfd1b47ec718b4af6f54b6a
6
+ metadata.gz: b7276c19b1871049a7b9c6ae49c46dae39ee8fd4942820ea3fc207cf66a2c94913dc507c40009cff520e493d726dda3a9c3c67e9840afaff9b6ec4ff9ddd65f3
7
+ data.tar.gz: 51e91ceb8504537f1646df08cc3b18f4f63e205ae0026eeb0e1871ada8a8b6d37fa809e193fb581558dbe1fb215ebf75b066d0fef85fc207047a90cb285f35db
@@ -199,7 +199,7 @@ 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 option == 'output' or option == 'use_extension'
203
203
  # don't let pandoc write the output to enable postprocessing
204
204
  rescue
205
205
  warn "The pandoc option '#{option}' (with value '#{value}') is not recognized by paru. This option is skipped." if debug?
@@ -49,11 +49,34 @@ module Pandocomatic
49
49
 
50
50
  metadata = PandocMetadata.load_file @src
51
51
 
52
- metadata.templates.each do |template_name|
53
- raise ConfigurationError.new(:no_such_template, nil, template_name) unless template_name.empty? or config.has_template? template_name
54
-
55
- if not modified_only? or file_modified? @src, dst then
56
- subcommand = ConvertFileCommand.new(@config, @src, dst, template_name)
52
+ subcommands = []
53
+
54
+ if metadata.has_template?
55
+ # There are templates in this document's metadata, try to use
56
+ # those.
57
+ metadata.templates.each do |template_name|
58
+ raise ConfigurationError.new(:no_such_template, nil, template_name) unless template_name.empty? or config.has_template? template_name
59
+
60
+ subcommands.push ConvertFileCommand.new(@config, @src, dst, template_name)
61
+ end
62
+ else
63
+ # Try to match any global templates using the glob patterns
64
+ global_templates = @config.determine_templates(@src)
65
+
66
+ if global_templates.empty?
67
+
68
+ subcommands.push ConvertFileCommand.new(@config, @src, dst)
69
+ else
70
+ global_templates.each do |template_name|
71
+ subcommands.push ConvertFileCommand.new(@config, @src, dst, template_name)
72
+ end
73
+ end
74
+ end
75
+
76
+ # Only run a command if the src file is modified, or if the modified
77
+ # setting is ignored.
78
+ subcommands.each do |subcommand|
79
+ if not modified_only? or file_modified? @src, subcommand.dst then
57
80
  push subcommand unless subcommand.nil? or subcommand.skip?
58
81
  end
59
82
  end
@@ -92,7 +92,8 @@ module Pandocomatic
92
92
  @settings = {
93
93
  'skip' => ['.*', 'pandocomatic.yaml'],
94
94
  'recursive' => true,
95
- 'follow-links' => false
95
+ 'follow-links' => false,
96
+ 'match-files' => 'first'
96
97
  }
97
98
 
98
99
  @templates = {}
@@ -174,7 +175,7 @@ module Pandocomatic
174
175
  # @return [Boolean] True if the setting 'recursive' is true, false
175
176
  # otherwise
176
177
  def recursive?()
177
- @settings['recursive']
178
+ @settings.has_key? 'recursive' and @settings['recursive']
178
179
  end
179
180
 
180
181
  # Should pandocomatic follow symbolic links given this Configuration?
@@ -182,9 +183,30 @@ module Pandocomatic
182
183
  # @return [Boolean] True if the setting 'follow_links' is true, false
183
184
  # otherwise
184
185
  def follow_links?()
185
- @settings['follow_links']
186
+ @settings.has_key? 'follow_links' and @settings['follow_links']
186
187
  end
187
188
 
189
+ # Should pandocomatic convert a file with all matching templates or
190
+ # only with the first matching template? Note. A 'use-template'
191
+ # statement in a document will overrule this setting.
192
+ #
193
+ # @return [Boolean] True if the setting 'match-files' is 'all', false
194
+ # otherwise.
195
+ def match_all_templates?()
196
+ @settings.has_key? 'match-files' and 'all' == @settings['match-files']
197
+ end
198
+
199
+ # Should pandocomatic convert a file with the first matching templates
200
+ # or with all matching templates? Note. Multiple 'use-template'
201
+ # statements in a document will overrule this setting.
202
+ #
203
+ # @return [Boolean] True if the setting 'match-files' is 'first', false
204
+ # otherwise.
205
+ def match_first_template?()
206
+ @settings.has_key? 'match-files' and 'first' == @settings['match-files']
207
+ end
208
+
209
+
188
210
  # Set the extension of the destination file given this Confguration,
189
211
  # template, and metadata
190
212
  #
@@ -288,12 +310,12 @@ module Pandocomatic
288
310
  end
289
311
  end
290
312
  else
291
- # TODO: what if there is no pandoc.to?
292
313
  if @templates[template_name].has_key? "pandoc"
293
314
  pandoc = @templates[template_name]["pandoc"]
294
315
  ext = use_extension.call pandoc
316
+
295
317
  if not ext.nil?
296
- extension = nil
318
+ extension = ext
297
319
  elsif pandoc.has_key? "to"
298
320
  extension = strip_extensions.call(pandoc["to"])
299
321
  end
@@ -334,6 +356,25 @@ module Pandocomatic
334
356
  end.keys.first
335
357
  end
336
358
 
359
+ # Determine the templates to use with this source document given this
360
+ # Configuration.
361
+ #
362
+ # @param src [String] path to the source document
363
+ # @return [Array[String]] the template's name to use
364
+ def determine_templates(src)
365
+ matches = @convert_patterns.select do |template_name, globs|
366
+ globs.any? {|glob| File.fnmatch glob, File.basename(src)}
367
+ end.keys
368
+
369
+ if matches.empty?
370
+ []
371
+ elsif match_all_templates?
372
+ matches
373
+ else
374
+ [matches.first]
375
+ end
376
+ end
377
+
337
378
  # Update the path to an executable processor or executor given this
338
379
  # Configuration
339
380
  #
@@ -2,3 +2,4 @@ settings:
2
2
  recursive: true
3
3
  follow-symlinks: false
4
4
  skip: ['.*', 'pandocomatic.yaml']
5
+ match-files: 'first'
@@ -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, 1, 1]
53
+ VERSION = [0, 2, 2, 0]
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.1.1
4
+ version: 0.2.2.0
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-13 00:00:00.000000000 Z
11
+ date: 2017-12-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: paru