pandocomatic 0.2.5.0.alpha → 0.2.5.0.betad

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: e0830abb917ca87c8d072ee5a4f88fee1f2f2d8da6359f14e74f9160614b23f9
4
- data.tar.gz: 68f2dbf9325b3ccaeeeae4c2c99b3de4486ff00a2e6c1951a6b14f3f4260232a
3
+ metadata.gz: c46b6b2c7d745668a59b28bb2f38823ece50c90f24bd53e31c586489e429cb88
4
+ data.tar.gz: 336889e4f77b7511034f62cb21ab42c01095818e79ebd3d758f30aecc8e10278
5
5
  SHA512:
6
- metadata.gz: e8c034acc735d84f56c95765a070a129bb522bfe2b6536d407dc067c86f954fad64c7679cb561551689f837d1c54186a9e6c69e7f9fa192eaf548dc948395a0b
7
- data.tar.gz: a625b92f99fdccfc5786cb8e2e234b572f4157f4efc894bdc6ed2be39eaad54cb4d33895014e410abfc37e3e983fa9bb6b9de805fa693fa5e1bab54a1f0cebf0
6
+ metadata.gz: f1f6304e2838a32387b88fd4a18f855e1ee90159262635b9f2cd2b3f568523868dcb157499dcd6fb886f77769ca5a687f68427f24ffb233cb8e6f914e0de9e00
7
+ data.tar.gz: 5f13e1a64e6b012726d55053df8bf0eb9a7bca879201f3c71d164ae526f6ad7db721b0032616471223e7910d88b202cc44791361ec1812e1fc06ae459e16bcc1
@@ -22,7 +22,6 @@ module Pandocomatic
22
22
  require_relative './error/cli_error.rb'
23
23
  require_relative './configuration.rb'
24
24
 
25
-
26
25
  ##
27
26
  # Command line options parser for pandocomatic using optimist.
28
27
  #
@@ -90,7 +90,9 @@ module Pandocomatic
90
90
  #
91
91
  # @return [String]
92
92
  def to_s
93
- "convert #{File.basename @src} #{"-> #{File.basename @dst}" unless @dst.nil?}"
93
+ str = "convert #{File.basename @src} #{"-> #{File.basename @dst}" unless @dst.nil?}"
94
+ str += "\n\t encountered multiple pandocomatic properties in the metadata. Only the last occurring pandocomatic property is being used." unless @metadata.unique?
95
+ str
94
96
  end
95
97
 
96
98
  private
@@ -46,7 +46,7 @@ module Pandocomatic
46
46
  super()
47
47
  @config = config
48
48
  @src = src
49
-
49
+
50
50
  metadata = PandocMetadata.load_file @src
51
51
 
52
52
  subcommands = []
@@ -61,6 +61,8 @@ module Pandocomatic
61
61
  # A Configuration object models a pandocomatic configuration.
62
62
  class Configuration
63
63
 
64
+ attr_reader :input
65
+
64
66
  # Pandocomatic's default configuration file
65
67
  CONFIG_FILE = 'pandocomatic.yaml'
66
68
 
@@ -75,7 +77,7 @@ module Pandocomatic
75
77
  @input = if input.nil? or input.empty? then
76
78
  nil
77
79
  elsif 1 < input.size then
78
- MultipleFilesInput.new(input)
80
+ MultipleFilesInput.new(input, self)
79
81
  else
80
82
  Input.new(input)
81
83
  end
@@ -265,7 +267,7 @@ module Pandocomatic
265
267
  # Get the input file name
266
268
  #
267
269
  # @return [String]
268
- def input()
270
+ def input_file()
269
271
  if @input.nil? then
270
272
  nil
271
273
  else
@@ -347,7 +349,6 @@ module Pandocomatic
347
349
  @settings.has_key? 'match-files' and 'first' == @settings['match-files']
348
350
  end
349
351
 
350
-
351
352
  # Set the extension of the destination file given this Confguration,
352
353
  # template, and metadata
353
354
  #
@@ -386,22 +387,13 @@ module Pandocomatic
386
387
  end
387
388
  end
388
389
 
389
- destination = nil
390
- rename_script = nil
391
-
392
- # Output option in pandoc property has precedence
393
- if metadata.has_pandocomatic?
394
- pandocomatic = metadata.pandocomatic
395
- if pandocomatic.has_key? "pandoc"
396
- pandoc = pandocomatic["pandoc"]
397
- destination = determine_output_in_pandoc.call pandoc
398
- rename_script = pandoc["rename"]
399
- end
400
- end
390
+ # Output options in pandoc property have precedence
391
+ destination = determine_output_in_pandoc.call metadata.pandoc_options
392
+ rename_script = metadata.pandoc_options["rename"]
401
393
 
402
394
  # Output option in template's pandoc property is next
403
395
  if destination.nil? and not template_name.nil? and not template_name.empty? then
404
- if @templates[template_name].has_key? "pandoc"
396
+ if @templates[template_name].has_key? "pandoc" and not @templates[template_name]["pandoc"].nil?
405
397
  pandoc = @templates[template_name]["pandoc"]
406
398
  destination = determine_output_in_pandoc.call pandoc
407
399
  rename_script ||= pandoc["rename"]
@@ -445,21 +437,14 @@ module Pandocomatic
445
437
  end
446
438
 
447
439
  if template_name.nil? or template_name.empty? then
448
- if metadata.has_pandocomatic?
449
- pandocomatic = metadata.pandocomatic
450
- if pandocomatic.has_key? "pandoc"
451
- pandoc = pandocomatic["pandoc"]
452
-
453
- ext = use_extension.call pandoc
454
- if not ext.nil?
455
- extension = ext
456
- elsif pandoc.has_key? "to"
457
- extension = strip_extensions.call(pandoc["to"])
458
- end
459
- end
460
- end
440
+ ext = use_extension.call metadata.pandoc_options
441
+ if not ext.nil?
442
+ extension = ext
443
+ elsif metadata.pandoc_options.has_key? "to"
444
+ extension = strip_extensions.call(metadata.pandoc_options["to"])
445
+ end
461
446
  else
462
- if @templates[template_name].has_key? "pandoc"
447
+ if @templates[template_name].has_key? "pandoc" and not @templates[template_name]["pandoc"].nil?
463
448
  pandoc = @templates[template_name]["pandoc"]
464
449
  ext = use_extension.call pandoc
465
450
 
@@ -475,6 +460,15 @@ module Pandocomatic
475
460
  extension
476
461
  end
477
462
 
463
+ def is_markdown_file?(filename)
464
+ if filename.nil? then
465
+ false
466
+ else
467
+ ext = File.extname(filename).delete_prefix(".");
468
+ "markdown" == DEFAULT_EXTENSION.key(ext)
469
+ end
470
+ end
471
+
478
472
  # Is there a template with template_name in this Configuration?
479
473
  #
480
474
  # @param template_name [String] a template's name
@@ -885,6 +879,5 @@ module Pandocomatic
885
879
 
886
880
  path
887
881
  end
888
-
889
882
  end
890
883
  end
@@ -23,11 +23,14 @@ module Pandocomatic
23
23
  # Generic class to handle input files and directories in a general manner.
24
24
  class Input
25
25
 
26
+ attr_reader :errors
27
+
26
28
  # Create a new Input
27
29
  #
28
30
  # @param input [String[]] a list of input files
29
31
  def initialize(input)
30
32
  @input_files = input
33
+ @errors = []
31
34
  end
32
35
 
33
36
  # The absolute path to this Input
@@ -57,6 +60,13 @@ module Pandocomatic
57
60
  def directory?()
58
61
  File.directory? @input_files.first
59
62
  end
63
+
64
+ # Does this input have encountered any errors?
65
+ #
66
+ # @return Boolean
67
+ def has_errors?()
68
+ not @errors.empty?
69
+ end
60
70
 
61
71
  # A string representation of this Input
62
72
  #
@@ -28,8 +28,9 @@ module Pandocomatic
28
28
  # is created as well containing the content of all the files in input.
29
29
  #
30
30
  # @param input [String[]] a list with input files
31
- def initialize(input)
31
+ def initialize(input, config)
32
32
  super(input)
33
+ @config = config
33
34
  create_temp_file
34
35
  end
35
36
 
@@ -37,7 +38,7 @@ module Pandocomatic
37
38
  #
38
39
  # @return String
39
40
  def name()
40
- @tmp_file
41
+ @tmp_file.path
41
42
  end
42
43
 
43
44
  # Is this input a directory? A MultipleFilesInput cannot be a
@@ -60,7 +61,19 @@ module Pandocomatic
60
61
  #
61
62
  # @return String
62
63
  def to_s()
63
- @input_files.join(" + ")
64
+ input_string = @input_files.first
65
+ previous_dir = File.dirname @input_files.first
66
+ @input_files.slice(1..-1).each do |f|
67
+ current_dir = File.dirname f
68
+ if current_dir == previous_dir
69
+ input_string += " + #{File.basename f}"
70
+ else
71
+ previous_dir = current_dir
72
+ input_string += " + #{f}"
73
+ end
74
+ end
75
+
76
+ input_string
64
77
  end
65
78
 
66
79
  private
@@ -69,13 +82,19 @@ module Pandocomatic
69
82
  # Concatenate all input files into one (temporary) input file
70
83
  # created in the same directory as the first input file
71
84
  @tmp_file = Tempfile.new(@input_files.first, File.dirname(self.absolute_path))
72
-
73
- @input_files.each_with_index do |filename, index|
74
- input = File.read File.absolute_path(filename)
75
- input = if 0 === index then input else PandocMetadata.remove_metadata(input) end
76
- @tmp_file.write input
85
+
86
+ contents = @input_files.map{|file|
87
+ @errors.push IOError.new(:file_does_not_exist, nil, file) unless File.exist? file
88
+ @errors.push IOError.new(:file_is_not_a_file, nil, file) unless File.file? file
89
+ @errors.push IOError.new(:file_is_not_readable, nil, file) unless File.readable? file
90
+ File.read File.absolute_path(file)
91
+ }.join("\n\n")
92
+
93
+ if not PandocMetadata.unique_pandocomatic_property? contents
94
+ warn "\nWarning: Encountered the pandocomatic metadata property more than once. Only the last occurrence of the pandocomatic metadata property is being used. Most likely you only want to use a pandocomatic metadata property in the first input file.\n\n"
77
95
  end
78
96
 
97
+ @tmp_file.write contents
79
98
  @tmp_file.rewind
80
99
  end
81
100
  end
@@ -36,7 +36,7 @@ module Pandocomatic
36
36
  #
37
37
  # @param input_document [String] a path to an input file
38
38
  # @return [String] the input document's metadata in the YAML format.
39
- def self.extract_metadata input_document
39
+ def self.extract_metadata(input_document)
40
40
  begin
41
41
  pandoc2yaml File.read(input_document)
42
42
  rescue StandardError => e
@@ -65,19 +65,31 @@ module Pandocomatic
65
65
  .join("\n")
66
66
  end
67
67
 
68
+ # Does the pandocomatic metadata property occur at most once?
69
+ #
70
+ # @return [Boolean] False if the pandocomatic metadata property does
71
+ # occur multiple times.
72
+ def self.unique_pandocomatic_property?(input)
73
+ 1 >= input
74
+ .scan(METADATA_BLOCK)
75
+ .map {|match| YAML.load "---#{match.join()}..."}
76
+ .count {|yaml| yaml.key? "pandocomatic_" or yaml.key? "pandocomatic"}
77
+ end
78
+
68
79
  # Collect the metadata embedded in the src file and create a new
69
80
  # PandocMetadata instance
70
81
  #
71
82
  # @param src [String] the path to the file to load metadata from
72
83
  # @return [PandocMetadata] the metadata in the source file, or an empty
73
84
  # one if no such metadata is contained in the source file.
74
- def self.load_file src
75
- yaml_metadata = extract_metadata src
85
+ def self.load_file(src)
86
+ input = File.read src
87
+ yaml_metadata = pandoc2yaml input
76
88
 
77
89
  if yaml_metadata.empty? then
78
- return PandocMetadata.new
90
+ PandocMetadata.new
79
91
  else
80
- return PandocMetadata.new YAML.load(yaml_metadata)
92
+ PandocMetadata.new YAML.load(yaml_metadata), unique_pandocomatic_property?(input)
81
93
  end
82
94
  end
83
95
 
@@ -86,10 +98,21 @@ module Pandocomatic
86
98
  #
87
99
  # @param hash [Hash] initial properties for this new PandocMetadata
88
100
  # object
101
+ # @param unique [Boolean = true] the pandocomatic property did occur
102
+ # at most once.
89
103
  # @return [PandocMetadata]
90
- def initialize hash = {}
91
- super
104
+ def initialize(hash = {}, unique = true)
105
+ super()
92
106
  merge! hash
107
+ @unique = unique
108
+ end
109
+
110
+ # Did the metadata contain multiple pandocomatic blocks?
111
+ #
112
+ # @return [Boolean] True if at most one pandocomatic block was present
113
+ # in the metadata
114
+ def unique?()
115
+ @unique
93
116
  end
94
117
 
95
118
  # Does this PandocMetadata object use a template?
@@ -170,7 +193,7 @@ module Pandocomatic
170
193
  # @return [Boolean] True if there is a pandoc options property in this
171
194
  # PandocMetadata object. False otherwise.
172
195
  def has_pandoc_options?()
173
- has_pandocomatic? and pandocomatic.has_key? 'pandoc'
196
+ has_pandocomatic? and pandocomatic.has_key? 'pandoc' and not pandocomatic['pandoc'].nil?
174
197
  end
175
198
 
176
199
  end
@@ -47,8 +47,8 @@ module Pandocomatic
47
47
  ERROR_STATUS = 1266 # This is the sum of the ascii values of the characters in 'pandocomatic'
48
48
 
49
49
  # Pandocomatic's current version
50
- VERSION = [0, 2, 5, 0, "α"]
51
-
50
+ VERSION = [0, 2, 5, 0, "beta"]
51
+
52
52
  # Run pandocomatic given options
53
53
  #
54
54
  # @param args [String[]] list of options to configure pandocomatic
@@ -66,15 +66,23 @@ module Pandocomatic
66
66
  # version option. If given, the help is printed.
67
67
  HelpPrinter.new().print
68
68
  else
69
+ # When using multiple input files, errors reading these
70
+ # files are already encountered at this point. If there
71
+ # are any errors, there is no reason to continue.
72
+ if configuration.input.has_errors?
73
+ ConfigurationErrorsPrinter.new(configuration.input.all_errors).print
74
+ exit ERROR_STATUS
75
+ end
76
+
69
77
  # Run the pandocomatic converter configured according to the options
70
78
  # given.
71
79
  #
72
80
  # Pandocomatic has two modes: converting a directory tree or
73
81
  # converting a single file. The mode is selected by the input.
74
82
  if configuration.directory?
75
- command = ConvertDirCommand.new(configuration, configuration.input, configuration.output)
83
+ command = ConvertDirCommand.new(configuration, configuration.input_file, configuration.output)
76
84
  else
77
- command = ConvertFileMultipleCommand.new(configuration, configuration.input, configuration.output)
85
+ command = ConvertFileMultipleCommand.new(configuration, configuration.input_file, configuration.output)
78
86
  command.make_quiet unless command.subcommands.size > 1
79
87
  end
80
88
 
@@ -108,7 +116,7 @@ module Pandocomatic
108
116
  warn "An unexpected error has occurred. You can report this bug via https://github.com/htdebeer/pandocomatic/issues/new."
109
117
  raise e
110
118
  ensure
111
- configuration.clean_up!
119
+ configuration.clean_up! unless configuration.nil?
112
120
  end
113
121
  end
114
122
  end
@@ -40,7 +40,7 @@ module Pandocomatic
40
40
 
41
41
  # Calculate the duration of the whole conversion process
42
42
  #
43
- # @erturn [Number]
43
+ # @return [Number]
44
44
  def duration()
45
45
  seconds = @end_time - @start_time
46
46
  if seconds > MINUTE
metadata CHANGED
@@ -1,53 +1,53 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pandocomatic
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.5.0.alpha
4
+ version: 0.2.5.0.betad
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: 2019-03-09 00:00:00.000000000 Z
11
+ date: 2019-03-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: paru
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
18
- - !ruby/object:Gem::Version
19
- version: 0.3.2
20
17
  - - ">="
21
18
  - !ruby/object:Gem::Version
22
19
  version: 0.3.2.0
20
+ - - "~>"
21
+ - !ruby/object:Gem::Version
22
+ version: 0.3.2
23
23
  type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
26
26
  requirements:
27
- - - "~>"
28
- - !ruby/object:Gem::Version
29
- version: 0.3.2
30
27
  - - ">="
31
28
  - !ruby/object:Gem::Version
32
29
  version: 0.3.2.0
30
+ - - "~>"
31
+ - !ruby/object:Gem::Version
32
+ version: 0.3.2
33
33
  - !ruby/object:Gem::Dependency
34
34
  name: optimist
35
35
  requirement: !ruby/object:Gem::Requirement
36
36
  requirements:
37
- - - "~>"
37
+ - - ">="
38
38
  - !ruby/object:Gem::Version
39
39
  version: 3.0.0
40
- - - ">="
40
+ - - "~>"
41
41
  - !ruby/object:Gem::Version
42
42
  version: 3.0.0
43
43
  type: :runtime
44
44
  prerelease: false
45
45
  version_requirements: !ruby/object:Gem::Requirement
46
46
  requirements:
47
- - - "~>"
47
+ - - ">="
48
48
  - !ruby/object:Gem::Version
49
49
  version: 3.0.0
50
- - - ">="
50
+ - - "~>"
51
51
  - !ruby/object:Gem::Version
52
52
  version: 3.0.0
53
53
  - !ruby/object:Gem::Dependency
@@ -56,28 +56,28 @@ dependencies:
56
56
  requirements:
57
57
  - - "~>"
58
58
  - !ruby/object:Gem::Version
59
- version: '0'
59
+ version: '1.3'
60
60
  type: :development
61
61
  prerelease: false
62
62
  version_requirements: !ruby/object:Gem::Requirement
63
63
  requirements:
64
64
  - - "~>"
65
65
  - !ruby/object:Gem::Version
66
- version: '0'
66
+ version: '1.3'
67
67
  - !ruby/object:Gem::Dependency
68
68
  name: yard
69
69
  requirement: !ruby/object:Gem::Requirement
70
70
  requirements:
71
71
  - - "~>"
72
72
  - !ruby/object:Gem::Version
73
- version: 0.9.8
73
+ version: 0.9.18
74
74
  type: :development
75
75
  prerelease: false
76
76
  version_requirements: !ruby/object:Gem::Requirement
77
77
  requirements:
78
78
  - - "~>"
79
79
  - !ruby/object:Gem::Version
80
- version: 0.9.8
80
+ version: 0.9.18
81
81
  description: Pandocomatic is a tool to automate using pandoc (<http://pandoc.org>).
82
82
  With pandocomatic you can express common patterns of using pandoc for generating
83
83
  your documents. Applied to a directory, pandocomatic can act as a static site generator.
@@ -147,7 +147,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
147
147
  requirements:
148
148
  - - ">="
149
149
  - !ruby/object:Gem::Version
150
- version: '0'
150
+ version: 2.4.4
151
151
  required_rubygems_version: !ruby/object:Gem::Requirement
152
152
  requirements:
153
153
  - - ">"
@@ -156,7 +156,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
156
156
  requirements:
157
157
  - pandoc, a universal document converer <http://pandoc.org>
158
158
  rubyforge_project:
159
- rubygems_version: 2.7.7
159
+ rubygems_version: 3.0.0.beta1
160
160
  signing_key:
161
161
  specification_version: 4
162
162
  summary: Automating the use of pandoc