pandocomatic 0.2.8 → 1.0.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.
Files changed (50) hide show
  1. checksums.yaml +4 -4
  2. data/lib/pandocomatic/cli.rb +81 -64
  3. data/lib/pandocomatic/command/command.rb +37 -35
  4. data/lib/pandocomatic/command/convert_dir_command.rb +44 -46
  5. data/lib/pandocomatic/command/convert_file_command.rb +314 -290
  6. data/lib/pandocomatic/command/convert_file_multiple_command.rb +56 -53
  7. data/lib/pandocomatic/command/convert_list_command.rb +31 -34
  8. data/lib/pandocomatic/command/copy_file_command.rb +14 -15
  9. data/lib/pandocomatic/command/create_link_command.rb +24 -27
  10. data/lib/pandocomatic/command/skip_command.rb +12 -15
  11. data/lib/pandocomatic/configuration.rb +682 -867
  12. data/lib/pandocomatic/default_configuration.yaml +4 -0
  13. data/lib/pandocomatic/error/cli_error.rb +30 -26
  14. data/lib/pandocomatic/error/configuration_error.rb +10 -9
  15. data/lib/pandocomatic/error/io_error.rb +13 -13
  16. data/lib/pandocomatic/error/pandoc_error.rb +10 -9
  17. data/lib/pandocomatic/error/pandocomatic_error.rb +15 -14
  18. data/lib/pandocomatic/error/processor_error.rb +9 -9
  19. data/lib/pandocomatic/error/template_error.rb +50 -0
  20. data/lib/pandocomatic/input.rb +53 -54
  21. data/lib/pandocomatic/multiple_files_input.rb +79 -72
  22. data/lib/pandocomatic/output.rb +29 -0
  23. data/lib/pandocomatic/pandoc_metadata.rb +193 -181
  24. data/lib/pandocomatic/pandocomatic.rb +101 -97
  25. data/lib/pandocomatic/pandocomatic_yaml.rb +69 -0
  26. data/lib/pandocomatic/path.rb +171 -0
  27. data/lib/pandocomatic/printer/command_printer.rb +7 -5
  28. data/lib/pandocomatic/printer/configuration_errors_printer.rb +7 -6
  29. data/lib/pandocomatic/printer/error_printer.rb +12 -7
  30. data/lib/pandocomatic/printer/finish_printer.rb +11 -10
  31. data/lib/pandocomatic/printer/help_printer.rb +8 -6
  32. data/lib/pandocomatic/printer/printer.rb +34 -34
  33. data/lib/pandocomatic/printer/summary_printer.rb +39 -33
  34. data/lib/pandocomatic/printer/version_printer.rb +8 -8
  35. data/lib/pandocomatic/printer/views/cli_error.txt +5 -0
  36. data/lib/pandocomatic/printer/views/configuration_error.txt +2 -1
  37. data/lib/pandocomatic/printer/views/error.txt +1 -1
  38. data/lib/pandocomatic/printer/views/finish.txt +1 -1
  39. data/lib/pandocomatic/printer/views/help.txt +27 -15
  40. data/lib/pandocomatic/printer/views/summary.txt +7 -1
  41. data/lib/pandocomatic/printer/views/template_error.txt +1 -0
  42. data/lib/pandocomatic/printer/views/version.txt +3 -3
  43. data/lib/pandocomatic/printer/views/warning.txt +1 -1
  44. data/lib/pandocomatic/printer/warning_printer.rb +21 -19
  45. data/lib/pandocomatic/processor.rb +28 -28
  46. data/lib/pandocomatic/processors/fileinfo_preprocessor.rb +35 -30
  47. data/lib/pandocomatic/processors/metadata_preprocessor.rb +23 -22
  48. data/lib/pandocomatic/template.rb +244 -0
  49. data/lib/pandocomatic/warning.rb +24 -25
  50. metadata +32 -12
@@ -1,40 +1,41 @@
1
+ # frozen_string_literal: true
2
+
1
3
  #--
2
4
  # Copyright 2017, Huub de Beer <Huub@heerdebeer.org>
3
- #
5
+ #
4
6
  # This file is part of pandocomatic.
5
- #
7
+ #
6
8
  # Pandocomatic is free software: you can redistribute it and/or modify
7
9
  # it under the terms of the GNU General Public License as published by the
8
10
  # Free Software Foundation, either version 3 of the License, or (at your
9
11
  # option) any later version.
10
- #
12
+ #
11
13
  # Pandocomatic is distributed in the hope that it will be useful, but
12
14
  # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13
15
  # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14
16
  # for more details.
15
- #
17
+ #
16
18
  # You should have received a copy of the GNU General Public License along
17
19
  # with pandocomatic. If not, see <http://www.gnu.org/licenses/>.
18
20
  #++
19
21
  module Pandocomatic
22
+ require 'yaml'
23
+ require_relative '../processor'
20
24
 
21
- require 'yaml'
22
- require_relative '../processor.rb'
23
-
24
- # MetadataPreprocessor mixes in the metadata section of a template into a
25
- # document before pandoc is run to convert that document. It is a default
26
- # preprocessor.
27
- class MetadataPreprocessor < Processor
28
- # Run this MetadataPreprocessor
29
- #
30
- # @param input [String] the contents of the document that is being
31
- # preprocessed
32
- # @param metadata [Hash = {}] the metadata to mix-in
33
- def self.run input, metadata = {}
34
- output = input
35
- output << "\n\n"
36
- output << YAML.dump(metadata)
37
- output << "...\n\n"
38
- end
25
+ # MetadataPreprocessor mixes in the metadata section of a template into a
26
+ # document before pandoc is run to convert that document. It is a default
27
+ # preprocessor.
28
+ class MetadataPreprocessor < Processor
29
+ # Run this MetadataPreprocessor
30
+ #
31
+ # @param input [String] the contents of the document that is being
32
+ # preprocessed
33
+ # @param metadata [Hash = {}] the metadata to mix-in
34
+ def self.run(input, metadata = {})
35
+ output = input
36
+ output << "\n\n"
37
+ output << YAML.dump(metadata)
38
+ output << "...\n\n"
39
39
  end
40
+ end
40
41
  end
@@ -0,0 +1,244 @@
1
+ # frozen_string_literal: true
2
+
3
+ #--
4
+ # Copyright 2022, Huub de Beer <Huub@heerdebeer.org>
5
+ #
6
+ # This file is part of pandocomatic.
7
+ #
8
+ # Pandocomatic is free software: you can redistribute it and/or modify
9
+ # it under the terms of the GNU General Public License as published by the
10
+ # Free Software Foundation, either version 3 of the License, or (at you1r
11
+ # option) any later version.
12
+ #
13
+ # Pandocomatic is distributed in the hope that it will be useful, but
14
+ # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
15
+ # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16
+ # for more details.
17
+ #
18
+ # You should have received a copy of the GNU General Public License along
19
+ # with pandocomatic. If not, see <http://www.gnu.org/licenses/>.
20
+ #++
21
+ module Pandocomatic
22
+ # A pandocomatic template
23
+ class Template
24
+ attr_reader :name, :path
25
+
26
+ # The name of the 'extends' section in a template
27
+ EXTENDS = 'extends'
28
+
29
+ # The name of the 'glob' section in a template
30
+ GLOB = 'glob'
31
+
32
+ # The name of the 'setup' section in a template
33
+ SETUP = 'setup'
34
+
35
+ # The name of the 'preprocessors' section in a template
36
+ PREPROCESSORS = 'preprocessors'
37
+
38
+ # The name of the 'metadata' section in a template
39
+ METADATA = 'metadata'
40
+
41
+ # The name of the 'pandoc' section in a template
42
+ PANDOC = 'pandoc'
43
+
44
+ # The name of the 'postprocessors' section in a template
45
+ POSTPROCESSORS = 'postprocessors'
46
+
47
+ # The name of the 'cleanup' section in a template
48
+ CLEANUP = 'cleanup'
49
+
50
+ # List of the sections a template can contain
51
+ SECTIONS = [EXTENDS, GLOB, SETUP, PREPROCESSORS, METADATA, PANDOC, POSTPROCESSORS, CLEANUP].freeze
52
+
53
+ # For each section in a template, generate methods to check if the section
54
+ # exists and to get that section's content.
55
+ SECTIONS.each do |sec|
56
+ define_method(sec.downcase.to_sym) do
57
+ section sec
58
+ end
59
+
60
+ define_method("#{sec.downcase}?".to_sym) do
61
+ section? sec
62
+ end
63
+ end
64
+
65
+ # Create a new template based on a template hash
66
+ #
67
+ # @param name [String] this template's name
68
+ # @param template_hash [Hash] hash representing template
69
+ def initialize(name, template_hash = {}, path = nil)
70
+ @name = name
71
+ @path = path
72
+
73
+ @data = {
74
+ EXTENDS => [],
75
+ GLOB => [],
76
+ SETUP => [],
77
+ PREPROCESSORS => [],
78
+ METADATA => {},
79
+ PANDOC => {},
80
+ POSTPROCESSORS => [],
81
+ CLEANUP => []
82
+ }
83
+
84
+ @data.merge! template_hash
85
+ end
86
+
87
+ # Deep copy template
88
+ #
89
+ # @param template [Template] the template to copy
90
+ # @return [Template] a deep copy of the input template
91
+ def self.clone(template)
92
+ Template.new(template.name, Marshal.load(Marshal.dump(template.to_h)), template.path)
93
+ end
94
+
95
+ # Is this an internal template?
96
+ #
97
+ # @return [Bool]
98
+ def internal?
99
+ @path.nil?
100
+ end
101
+
102
+ # Is this an external template?
103
+ #
104
+ # @return [Bool]
105
+ def external?
106
+ !internal?
107
+ end
108
+
109
+ # List of template names that this template extends.
110
+ #
111
+ # @return [Array<String>]
112
+ def extends
113
+ # Overwriting automatically generated method with more specific
114
+ # behavior
115
+ to_extend = section(EXTENDS)
116
+ to_extend = [to_extend] if to_extend.is_a? String
117
+ to_extend
118
+ end
119
+
120
+ # Merge another template into this one.
121
+ #
122
+ # @param other [Template] other template to merge into this one.
123
+ def merge!(other)
124
+ SECTIONS.each do |section_name|
125
+ current_section = section(section_name)
126
+ other_section = other.send section_name
127
+ extended_section = Template.extend_value other_section, current_section
128
+
129
+ if extended_section.nil?
130
+ @data.delete section_name
131
+ else
132
+ @data[section_name] = extended_section
133
+ end
134
+ end
135
+ end
136
+
137
+ # Create Hash representation of this template
138
+ #
139
+ # @return [Hash]
140
+ def to_h
141
+ @data
142
+ end
143
+
144
+ # rubocop:disable Metrics
145
+
146
+ # Extend the current value with the parent value. Depending on the
147
+ # value and type of the current and parent values, the extension
148
+ # differs.
149
+ #
150
+ # For simple values, the current value takes precedence over the
151
+ # parent value
152
+ #
153
+ # For Hash values, each parent value's property is extended as well
154
+ #
155
+ # For Arrays, the current overwrites and adds to parent value's items
156
+ # unless the current value is a Hash with a 'remove' and 'add'
157
+ # property. Then the 'add' items are added to the parent value and the
158
+ # 'remove' items are removed from the parent value.
159
+ #
160
+ # @param current [Object] the current value
161
+ # @param parent [Object] the parent value the current might extend
162
+ # @return [Object] the extended value
163
+ def self.extend_value(current, parent)
164
+ if parent.nil?
165
+ # If no parent value is specified, the current takes
166
+ # precedence
167
+ current
168
+ elsif current.nil?
169
+ nil
170
+ # Current nil removes value of parent; follows YAML spec.
171
+ # Note. take care to actually remove this value from a
172
+ # Hash. (Like it is done in the next case)
173
+ else
174
+ case parent
175
+ when Hash
176
+ if current.is_a? Hash
177
+ # Mixin current and parent values
178
+ parent.each_pair do |property, value|
179
+ if current.key? property
180
+ extended_value = extend_value(current[property], value)
181
+ if extended_value.nil?
182
+ current.delete property
183
+ else
184
+ current[property] = extended_value
185
+ end
186
+ else
187
+ current[property] = value
188
+ end
189
+ end
190
+ end
191
+ current
192
+ when Array
193
+ case current
194
+ when Hash
195
+ if current.key? 'remove'
196
+ to_remove = current['remove']
197
+
198
+ if to_remove.is_a? Array
199
+ parent.delete_if { |v| current['remove'].include? v }
200
+ else
201
+ parent.delete to_remove
202
+ end
203
+ end
204
+
205
+ if current.key? 'add'
206
+ to_add = current['add']
207
+
208
+ if to_add.is_a? Array
209
+ parent = current['add'].concat(parent).uniq
210
+ else
211
+ parent.push(to_add).uniq
212
+ end
213
+ end
214
+
215
+ parent
216
+ when Array
217
+ # Just combine parent and current arrays, current
218
+ # values take precedence
219
+ current.concat(parent).uniq
220
+ else
221
+ # Unknown what to do, assuming current should take
222
+ # precedence
223
+ current
224
+ end
225
+ else
226
+ # Simple values: current replaces parent
227
+ current
228
+ end
229
+ end
230
+ end
231
+
232
+ # rubocop:enable Metrics
233
+
234
+ private
235
+
236
+ def section?(name)
237
+ @data[name] and !@data[name].empty?
238
+ end
239
+
240
+ def section(name, default = [])
241
+ @data[name] or default
242
+ end
243
+ end
244
+ end
@@ -1,43 +1,42 @@
1
+ # frozen_string_literal: true
2
+
1
3
  #--
2
4
  # Copyright 2017, Huub de Beer <Huub@heerdebeer.org>
3
- #
5
+ #
4
6
  # This file is part of pandocomatic.
5
- #
7
+ #
6
8
  # Pandocomatic is free software: you can redistribute it and/or modify
7
9
  # it under the terms of the GNU General Public License as published by the
8
10
  # Free Software Foundation, either version 3 of the License, or (at your
9
11
  # option) any later version.
10
- #
12
+ #
11
13
  # Pandocomatic is distributed in the hope that it will be useful, but
12
14
  # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13
15
  # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14
16
  # for more details.
15
- #
17
+ #
16
18
  # You should have received a copy of the GNU General Public License along
17
19
  # with pandocomatic. If not, see <http://www.gnu.org/licenses/>.
18
20
  #++
19
21
  module Pandocomatic
22
+ # A warning given during the conversion process.
23
+ class Warning
24
+ # :skipping_link_because_it_points_outside_the_source_tree
20
25
 
21
- # A warning given during the conversion process.
22
- class Warning
23
-
24
- # :skipping_link_because_it_points_outside_the_source_tree
25
-
26
- # Create a new Warning with message and some extra data
27
- #
28
- # @param message [Symbol = :unknown] the message translation key.
29
- # @param data [Object = nil] optional data attached to the message.
30
- def initialize(message = :unknown, data = nil)
31
- @message = message
32
- @data = data
33
- end
34
-
35
- # Does this Warning have any data associated with it?
36
- #
37
- # @return [Boolean] True if there is data attached, false otherwise.
38
- def has_data?
39
- not @data.nil?
40
- end
26
+ # Create a new Warning with message and some extra data
27
+ #
28
+ # @param message [Symbol = :unknown] the message translation key.
29
+ # @param data [Object = nil] optional data attached to the message.
30
+ def initialize(message = :unknown, data = nil)
31
+ @message = message
32
+ @data = data
33
+ end
41
34
 
35
+ # Does this Warning have any data associated with it?
36
+ #
37
+ # @return [Boolean] True if there is data attached, false otherwise.
38
+ def data?
39
+ !@data.nil?
42
40
  end
43
- end
41
+ end
42
+ end
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.8
4
+ version: 1.0.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: 2021-11-20 00:00:00.000000000 Z
11
+ date: 2022-08-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: paru
@@ -16,20 +16,20 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '0.4'
19
+ version: '1.0'
20
20
  - - ">="
21
21
  - !ruby/object:Gem::Version
22
- version: 0.4.3
22
+ version: 1.0.3
23
23
  type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
26
26
  requirements:
27
27
  - - "~>"
28
28
  - !ruby/object:Gem::Version
29
- version: '0.4'
29
+ version: '1.0'
30
30
  - - ">="
31
31
  - !ruby/object:Gem::Version
32
- version: 0.4.3
32
+ version: 1.0.3
33
33
  - !ruby/object:Gem::Dependency
34
34
  name: optimist
35
35
  requirement: !ruby/object:Gem::Requirement
@@ -56,28 +56,42 @@ dependencies:
56
56
  requirements:
57
57
  - - "~>"
58
58
  - !ruby/object:Gem::Version
59
- version: '1.3'
59
+ version: '1.5'
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: '1.3'
66
+ version: '1.5'
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.20
73
+ version: 0.9.27
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.20
80
+ version: 0.9.27
81
+ - !ruby/object:Gem::Dependency
82
+ name: rubocop
83
+ requirement: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - "~>"
86
+ - !ruby/object:Gem::Version
87
+ version: 1.25.0
88
+ type: :development
89
+ prerelease: false
90
+ version_requirements: !ruby/object:Gem::Requirement
91
+ requirements:
92
+ - - "~>"
93
+ - !ruby/object:Gem::Version
94
+ version: 1.25.0
81
95
  description: Pandocomatic is a tool to automate using pandoc. With pandocomatic you
82
96
  can express common patterns of using pandoc for generating your documents. Applied
83
97
  to a directory, pandocomatic can act as a static site generator.
@@ -105,10 +119,14 @@ files:
105
119
  - lib/pandocomatic/error/pandoc_error.rb
106
120
  - lib/pandocomatic/error/pandocomatic_error.rb
107
121
  - lib/pandocomatic/error/processor_error.rb
122
+ - lib/pandocomatic/error/template_error.rb
108
123
  - lib/pandocomatic/input.rb
109
124
  - lib/pandocomatic/multiple_files_input.rb
125
+ - lib/pandocomatic/output.rb
110
126
  - lib/pandocomatic/pandoc_metadata.rb
111
127
  - lib/pandocomatic/pandocomatic.rb
128
+ - lib/pandocomatic/pandocomatic_yaml.rb
129
+ - lib/pandocomatic/path.rb
112
130
  - lib/pandocomatic/printer/command_printer.rb
113
131
  - lib/pandocomatic/printer/configuration_errors_printer.rb
114
132
  - lib/pandocomatic/printer/error_printer.rb
@@ -128,12 +146,14 @@ files:
128
146
  - lib/pandocomatic/printer/views/pandoc_error.txt
129
147
  - lib/pandocomatic/printer/views/processor_error.txt
130
148
  - lib/pandocomatic/printer/views/summary.txt
149
+ - lib/pandocomatic/printer/views/template_error.txt
131
150
  - lib/pandocomatic/printer/views/version.txt
132
151
  - lib/pandocomatic/printer/views/warning.txt
133
152
  - lib/pandocomatic/printer/warning_printer.rb
134
153
  - lib/pandocomatic/processor.rb
135
154
  - lib/pandocomatic/processors/fileinfo_preprocessor.rb
136
155
  - lib/pandocomatic/processors/metadata_preprocessor.rb
156
+ - lib/pandocomatic/template.rb
137
157
  - lib/pandocomatic/warning.rb
138
158
  homepage: https://heerdebeer.org/Software/markdown/pandocomatic/
139
159
  licenses:
@@ -147,7 +167,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
147
167
  requirements:
148
168
  - - ">="
149
169
  - !ruby/object:Gem::Version
150
- version: 2.6.8
170
+ version: 2.7.6
151
171
  required_rubygems_version: !ruby/object:Gem::Requirement
152
172
  requirements:
153
173
  - - ">="
@@ -155,7 +175,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
155
175
  version: '0'
156
176
  requirements:
157
177
  - pandoc, a universal document converter
158
- rubygems_version: 3.2.3
178
+ rubygems_version: 3.3.7
159
179
  signing_key:
160
180
  specification_version: 4
161
181
  summary: Automate the use of pandoc