pandocomatic 0.2.5.0.betad → 0.2.5.0.betae

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: c46b6b2c7d745668a59b28bb2f38823ece50c90f24bd53e31c586489e429cb88
4
- data.tar.gz: 336889e4f77b7511034f62cb21ab42c01095818e79ebd3d758f30aecc8e10278
3
+ metadata.gz: 8fc5078287ef035d1bd1734f28d6248f095ca6ec2ccf8c7bf6a4d702d3f7919b
4
+ data.tar.gz: e06523b3dd232c7688c30903082fdadc5133f413e651aeddb86c983690fd9700
5
5
  SHA512:
6
- metadata.gz: f1f6304e2838a32387b88fd4a18f855e1ee90159262635b9f2cd2b3f568523868dcb157499dcd6fb886f77769ca5a687f68427f24ffb233cb8e6f914e0de9e00
7
- data.tar.gz: 5f13e1a64e6b012726d55053df8bf0eb9a7bca879201f3c71d164ae526f6ad7db721b0032616471223e7910d88b202cc44791361ec1812e1fc06ae459e16bcc1
6
+ metadata.gz: 33669dd83b7de3921af91a19468dbbb4d5a640c9dd69886fb1d4fd673a523a2a53b5b8844f5aaea10e793b93fb54327a9dd6e9a8c5070557f522904d911e26eb
7
+ data.tar.gz: 530bb6418f57a25d780e83e338f0fd37484eb30c0e765aa79fa634368eba58061724d2858a670dc07c09ad993e180fa2584d719a027c3a6b397d5be0e9faa190
@@ -81,7 +81,7 @@ module Pandocomatic
81
81
  def create_temp_file()
82
82
  # Concatenate all input files into one (temporary) input file
83
83
  # created in the same directory as the first input file
84
- @tmp_file = Tempfile.new(@input_files.first, File.dirname(self.absolute_path))
84
+ @tmp_file = Tempfile.new("pandocomatic_tmp_", File.dirname(self.absolute_path))
85
85
 
86
86
  contents = @input_files.map{|file|
87
87
  @errors.push IOError.new(:file_does_not_exist, nil, file) unless File.exist? file
@@ -90,8 +90,10 @@ module Pandocomatic
90
90
  File.read File.absolute_path(file)
91
91
  }.join("\n\n")
92
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"
93
+ metadata = PandocMetadata.load contents
94
+
95
+ if not metadata.unique?
96
+ warn "\nWarning: Encountered the pandocomatic metadata property in more than one YAML metadata block. Only the pandocomatic property from the first YAML metadata block is being used; the other pandocomatic properties have been discarded.\n\n"
95
97
  end
96
98
 
97
99
  @tmp_file.write contents
@@ -32,48 +32,12 @@ module Pandocomatic
32
32
  # templates and input files.
33
33
  class PandocMetadata < Hash
34
34
 
35
- # Extract the metadata from an input file
36
- #
37
- # @param input_document [String] a path to an input file
38
- # @return [String] the input document's metadata in the YAML format.
39
- def self.extract_metadata(input_document)
40
- begin
41
- pandoc2yaml File.read(input_document)
42
- rescue StandardError => e
43
- raise IOError.new(:error_opening_file, e, input_document)
44
- end
45
- end
46
-
47
- # Remove all metadata from an input string
48
- #
49
- # @param input [String] the input to remove all metadata from
50
- # @return [String] the input with all metadata blocks removed
51
- def self.remove_metadata(input)
52
- input.gsub(METADATA_BLOCK, "\n");
53
- end
54
-
55
35
  # Extract the YAML metadata from an input string
56
36
  #
57
37
  # @param input [String] the input string
58
38
  # @return [String] the YAML data embedded in the input string
59
39
  def self.pandoc2yaml(input)
60
- mined_metadata = input.scan(METADATA_BLOCK)
61
-
62
- mined_metadata
63
- .flatten
64
- .map{|yaml| yaml.strip}
65
- .join("\n")
66
- end
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"}
40
+ extract_metadata(input).first
77
41
  end
78
42
 
79
43
  # Collect the metadata embedded in the src file and create a new
@@ -83,13 +47,22 @@ module Pandocomatic
83
47
  # @return [PandocMetadata] the metadata in the source file, or an empty
84
48
  # one if no such metadata is contained in the source file.
85
49
  def self.load_file(src)
86
- input = File.read src
87
- yaml_metadata = pandoc2yaml input
50
+ load(File.read src)
51
+ end
52
+
53
+ # Collect the metadata embedded in the src file and create a new
54
+ # PandocMetadata instance
55
+ #
56
+ # @param input [String] the string to load the metadata from
57
+ # @return [PandocMetadata] the metadata in the source file, or an empty
58
+ # one if no such metadata is contained in the source file.
59
+ def self.load(input)
60
+ yaml, pandocomatic_blocks = extract_metadata(input)
88
61
 
89
- if yaml_metadata.empty? then
62
+ if yaml.empty? then
90
63
  PandocMetadata.new
91
64
  else
92
- PandocMetadata.new YAML.load(yaml_metadata), unique_pandocomatic_property?(input)
65
+ PandocMetadata.new YAML.load(yaml), 1 >= pandocomatic_blocks
93
66
  end
94
67
  end
95
68
 
@@ -196,6 +169,47 @@ module Pandocomatic
196
169
  has_pandocomatic? and pandocomatic.has_key? 'pandoc' and not pandocomatic['pandoc'].nil?
197
170
  end
198
171
 
172
+ private
173
+
174
+ # Extract the metadata from an input file
175
+ #
176
+ # @param input [String] the string to extract metadata from
177
+ # @return [Array] The return value is an array with the following two
178
+ # values:
179
+ #
180
+ # 1. The extracted metadata as a YAML string
181
+ # 2. The number of times the pandocomatic properties did occur in the
182
+ # input.
183
+ #
184
+ # If more than one pandocomatic property is contained in the input,
185
+ # all but the first are discarded and are not present in the
186
+ # extracted metadata YAML string.
187
+ def self.extract_metadata(input)
188
+ metadata_blocks = input
189
+ .scan(METADATA_BLOCK)
190
+ .map {|match| YAML.load "---#{match.join()}..."}
191
+
192
+ pandocomatic_blocks = 0
193
+
194
+ metadata_blocks = metadata_blocks.each do |metadata|
195
+ metadata.delete_if do |key|
196
+ if key == "pandocomatic_" or key == "pandocomatic"
197
+ pandocomatic_blocks += 1
198
+
199
+ 1 < pandocomatic_blocks
200
+ else
201
+ false
202
+ end
203
+ end
204
+ end
205
+
206
+ yaml_string = metadata_blocks
207
+ .map {|metadata| YAML.dump(metadata)}
208
+ .join("\n")
209
+
210
+ return [yaml_string, pandocomatic_blocks]
211
+ end
212
+
199
213
  end
200
214
 
201
215
  end
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.betad
4
+ version: 0.2.5.0.betae
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-27 00:00:00.000000000 Z
11
+ date: 2019-04-02 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.0
20
17
  - - "~>"
21
18
  - !ruby/object:Gem::Version
22
19
  version: 0.3.2
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 0.3.2.0
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.0
30
27
  - - "~>"
31
28
  - !ruby/object:Gem::Version
32
29
  version: 0.3.2
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: 0.3.2.0
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
@@ -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: 3.0.0.beta1
159
+ rubygems_version: 2.7.7
160
160
  signing_key:
161
161
  specification_version: 4
162
162
  summary: Automating the use of pandoc