pandocomatic 0.1.4.4 → 0.1.4.5

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: f8928f929e83b3ac62ed3f679c3d98aafd7a6914
4
- data.tar.gz: 68e8de19c03ed89c05ba74cba5c13bcde9bb2dbf
3
+ metadata.gz: 1f08978eb4a68143d4e153d76f4a4beddda54d68
4
+ data.tar.gz: 40ceb29138023555c57298a186552b9f2a601fba
5
5
  SHA512:
6
- metadata.gz: 0aaa3f82416f0879d29b762a845c402b14cab19629f3136a21dcfd5313b7f24f2bb2c3e2fe4346ef6cf8849a67f0ee51b1fca3462f7e91cb1e8c781473fcc33b
7
- data.tar.gz: 2353782f70b437c92d665b7f90ca6ebee9a0aa5ba2f66e1730705a40e6706db5c5a613801cba33b2148a2a7fc384f180c8467c8020245145cec90753767610ec
6
+ metadata.gz: dd4d77c97a2f3fa6df7a09600bf15907cf1e7ee44b9bd6350aa53e895a02e44589dc35aa273ff3051b1d8b3fc663f9a07fc6cf89d8d199ed1fce46186de467c9
7
+ data.tar.gz: 2a99078d6afd28190cd586a73cb3d2600e1b63cf9127ee0bb4e403698e14e8c8c0d3a6451097348e521ea487232572c9dcd35b79a84eb4aeaadad43a44d2886b
@@ -20,6 +20,17 @@ module Pandocomatic
20
20
 
21
21
  require_relative '../printer/command_printer.rb'
22
22
 
23
+ # Command is a base class of all actions pandocomatic executes while
24
+ # converting a file or a directory of files.
25
+ #
26
+ # @!attribute errors
27
+ # @return [Error[]] list of errors created while preparing and running a
28
+ # command
29
+ #
30
+ # @!attribute index
31
+ # @return [Number] the index of this Command in the list with all commands
32
+ # to run when running pandocomatic.
33
+
23
34
  class Command
24
35
 
25
36
  attr_reader :errors, :index
@@ -31,13 +42,22 @@ module Pandocomatic
31
42
  @@src_root = "."
32
43
  @@modified_only = false
33
44
 
45
+ # Create a new Command
34
46
  def initialize()
35
47
  @errors = []
36
48
  @@total += 1
37
49
  @index = @@total
38
50
  end
39
51
 
40
- def self.reset(src_root = ".", dry_run = false, quiet = false, debug = false, modified_only)
52
+ # Reset all Commands
53
+ #
54
+ # @param src_root [String = "."] the root directory to convert
55
+ # @param dry_run [Boolean = false] should Commands actually run or not?
56
+ # @param quiet [Boolean = false] should Commands run silently?
57
+ # @param debug [Boolean = false] should Commands be run in debug mode?
58
+ # @param modified_only [Boolean = false] should only modified files be
59
+ # converted?
60
+ def self.reset(src_root = ".", dry_run = false, quiet = false, debug = false, modified_only = false)
41
61
  @@src_root = src_root
42
62
  @@dry_run = dry_run
43
63
  @@quiet = quiet
@@ -46,79 +66,133 @@ module Pandocomatic
46
66
  @@total = 0
47
67
  end
48
68
 
69
+ # Get the root directory of this Command's conversion process
70
+ #
71
+ # @return [String]
49
72
  def src_root()
50
73
  @@src_root
51
74
  end
52
75
 
76
+ # Does this Command not actually execute?
77
+ #
78
+ # @return [Boolean]
53
79
  def dry_run?()
54
80
  @@dry_run
55
81
  end
56
82
 
83
+ # Is this Command executed silently?
84
+ #
85
+ # @return [Boolean]
57
86
  def quiet?()
58
87
  @@quiet
59
88
  end
60
89
 
90
+ # Is this Command executed in debug mode?
91
+ #
92
+ # @return [Boolean]
61
93
  def debug?()
62
94
  @@debug
63
95
  end
64
96
 
97
+ # Is this Command only executed on modified files?
98
+ #
99
+ # @return [Boolean]
65
100
  def modified_only?()
66
101
  @@modified_only
67
102
  end
68
103
 
104
+ # The number of commands executed by this Command; a Command can have sub
105
+ # commands as well.
106
+ #
107
+ # @return [Number]
69
108
  def count()
70
109
  1
71
110
  end
72
111
 
112
+ # Get all the errors generated while executing this Command
113
+ #
114
+ # @return [Error[]]
73
115
  def all_errors()
74
116
  @errors
75
117
  end
76
118
 
119
+ # Make this Command run quietly
77
120
  def make_quiet()
78
121
  @@quiet = true
79
122
  end
80
123
 
124
+ # Convert this Command's index to a string representation
125
+ #
126
+ # @return [String]
81
127
  def index_to_s()
82
128
  "#{@@total - @index + 1}".rjust(@@total.to_s.size)
83
129
  end
84
130
 
131
+ # Execute this Command. A Command can be dry-run as well, in which it is
132
+ # not actually run.
85
133
  def execute()
86
134
  CommandPrinter.new(self).print unless quiet?
87
135
  run if not dry_run? and runnable?
88
136
  end
89
137
 
138
+ # Actually run this Command
90
139
  def run()
91
140
  end
92
141
 
142
+ # Are there any errors while configuring this Command? If not, this
143
+ # Command is runnable.
144
+ #
145
+ # @return [Boolean]
93
146
  def runnable?()
94
147
  not has_errors?
95
148
  end
96
149
 
150
+ # Create a String representation of this Command
151
+ #
152
+ # @return [String]
97
153
  def to_s()
98
154
  'command'
99
155
  end
100
156
 
157
+ # Is this Command converting a directory?
158
+ #
159
+ # @return [Boolean] false
101
160
  def directory?()
102
161
  false
103
162
  end
104
163
 
164
+ # Does this Command convert a file multiple times?
165
+ #
166
+ # @return [Boolean] false
105
167
  def multiple?()
106
168
  false
107
169
  end
108
170
 
171
+ # Will this Command be skipped, thus not executed?
172
+ #
173
+ # @return [Boolean] false
109
174
  def skip?()
110
175
  false
111
176
  end
112
177
 
178
+ # Decrement the total number of conversion commands by 1
113
179
  def uncount()
114
180
  @@total -= 1
115
181
  end
116
182
 
183
+ # Has this Command run in any errors?
184
+ #
185
+ # @return [Error[]]
117
186
  def has_errors?()
118
187
  not @errors.empty?
119
188
  end
120
189
 
121
- # src file is newer than the dstination file?
190
+ # Is the source file newer than the destination file?
191
+ #
192
+ # @param src [String] the source file
193
+ # @param dst [String] the destination file
194
+ #
195
+ # @return [Boolean] True if src has been modified after dst has been last
122
196
  def file_modified?(src, dst)
123
197
  not File.exist? dst or File.mtime(src) > File.mtime(dst)
124
198
  end
@@ -21,8 +21,10 @@ module Pandocomatic
21
21
  require 'paru'
22
22
 
23
23
  require_relative '../pandoc_metadata.rb'
24
+
24
25
  require_relative '../processor.rb'
25
- require_relative '../fileinfo_preprocessor'
26
+ require_relative '../processors/fileinfo_preprocessor'
27
+ require_relative '../processors/metadata_preprocessor'
26
28
 
27
29
  require_relative '../configuration.rb'
28
30
 
@@ -38,6 +40,13 @@ module Pandocomatic
38
40
 
39
41
  attr_reader :config, :src, :dst
40
42
 
43
+ # Create a new ConvertFileCommand
44
+ #
45
+ # @param config [Configuration] pandocomatic's configuration
46
+ # @param src [String] the path to the file to convert
47
+ # @param dst [String] the path to save the output of the conversion
48
+ # @param template_name [String = nil] the template to use while converting
49
+ # this file
41
50
  def initialize(config, src, dst, template_name = nil)
42
51
  super()
43
52
  @config = config
@@ -55,10 +64,14 @@ module Pandocomatic
55
64
  @errors.push IOError.new(:file_is_not_readable, nil, @src) unless File.readable? @src
56
65
  end
57
66
 
67
+ # Execute this ConvertFileCommand
58
68
  def run
59
69
  convert_file
60
70
  end
61
71
 
72
+ # Create a string representation of this ConvertFileCommand
73
+ #
74
+ # @return [String]
62
75
  def to_s
63
76
  "convert #{File.basename @src} #{"-> #{File.basename @dst}" unless @dst.nil?}"
64
77
  end
@@ -70,6 +83,8 @@ module Pandocomatic
70
83
  pandoc_options = metadata.pandoc_options || {}
71
84
  template = {}
72
85
 
86
+ # Determine the actual options and settings to use when converting this
87
+ # file.
73
88
  if not @template_name.nil? and not @template_name.empty?
74
89
  raise ConfigurationError.new(:no_such_template, nil, @template_name) unless @config.has_template? @template_name
75
90
  template = @config.get_template @template_name
@@ -86,12 +101,22 @@ module Pandocomatic
86
101
  end
87
102
  end
88
103
 
104
+ # Read in the file to convert
89
105
  input = File.read @src
106
+
107
+ # Run the default preprocessors to mix-in information about the file
108
+ # that is being converted and mix-in the template's metadata section as
109
+ # well
90
110
  input = FileInfoPreprocessor.run input, @src, pandoc_options
111
+ input = MetadataPreprocessor.run input, template['metadata'] if template.has_key? 'metadata' and not template['metadata'].empty?
112
+
113
+ # Convert the file by preprocessing it, run pandoc on it, and
114
+ # postprocessing the output
91
115
  input = preprocess input, template
92
116
  input = pandoc input, pandoc_options, File.dirname(@src)
93
117
  output = postprocess input, template
94
118
 
119
+ # Write out the results of the conversion process to file.
95
120
  if @dst.to_s.empty? and metadata.pandoc_options.has_key? 'output'
96
121
  @dst = metadata.pandoc_options['output']
97
122
  end
@@ -123,6 +148,7 @@ module Pandocomatic
123
148
  'epub-cover-image',
124
149
  'epub-metadata',
125
150
  'epub-embed-font',
151
+ 'epub-subdirectory',
126
152
  'bibliography',
127
153
  'csl',
128
154
  'syntax-definition',
@@ -99,6 +99,7 @@ module Pandocomatic
99
99
  full_template = {
100
100
  'glob' => [],
101
101
  'preprocessors' => [],
102
+ 'metadata' => {},
102
103
  'pandoc' => {},
103
104
  'postprocessors' => []
104
105
  }
@@ -241,7 +242,7 @@ module Pandocomatic
241
242
  @templates[name][field] = template[field]
242
243
  end
243
244
  end
244
- when 'pandoc'
245
+ when 'pandoc', 'metadata'
245
246
  if @templates[name][field] then
246
247
  if template[field] then
247
248
  @templates[name][field].merge! template[field]
@@ -44,7 +44,7 @@ module Pandocomatic
44
44
  require_relative './command/convert_file_multiple_command.rb'
45
45
 
46
46
  class Pandocomatic
47
- VERSION = [0, 1, 4, 3]
47
+ VERSION = [0, 1, 4, 5]
48
48
  CONFIG_FILE = 'pandocomatic.yaml'
49
49
 
50
50
  def self.run(args)
@@ -18,9 +18,16 @@
18
18
  #++
19
19
  module Pandocomatic
20
20
 
21
+ require_relative '../processor.rb'
22
+
21
23
  # FileInfoPreprocessor collects information about a file to be converted and
22
24
  # mixes that information into that file's metadata. It is a default
23
25
  # preprocessor.
26
+ #
27
+ # @param input [String] the contents of the document being preprocessed
28
+ # @param path [String] the path to the input document
29
+ # @param options [Hash] pandoc options collected by pandocomatic to run on
30
+ # this file
24
31
  class FileInfoPreprocessor < Processor
25
32
  def self.run input, path, options
26
33
  created_at = File.stat(path).ctime
@@ -0,0 +1,39 @@
1
+ #--
2
+ # Copyright 2017, Huub de Beer <Huub@heerdebeer.org>
3
+ #
4
+ # This file is part of pandocomatic.
5
+ #
6
+ # Pandocomatic is free software: you can redistribute it and/or modify
7
+ # it under the terms of the GNU General Public License as published by the
8
+ # Free Software Foundation, either version 3 of the License, or (at your
9
+ # option) any later version.
10
+ #
11
+ # Pandocomatic is distributed in the hope that it will be useful, but
12
+ # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13
+ # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14
+ # for more details.
15
+ #
16
+ # You should have received a copy of the GNU General Public License along
17
+ # with pandocomatic. If not, see <http://www.gnu.org/licenses/>.
18
+ #++
19
+ module Pandocomatic
20
+
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
+ #
28
+ # @param input [String] the contents of the document that is being
29
+ # preprocessed
30
+ # @param metadata [Hash = {}] the metadata to mix-in
31
+ class MetadataPreprocessor < Processor
32
+ def self.run input, metadata = {}
33
+ output = input
34
+ output << "\n\n"
35
+ output << YAML.dump(metadata)
36
+ output << "...\n\n"
37
+ end
38
+ end
39
+ 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.1.4.4
4
+ version: 0.1.4.5
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-06-25 00:00:00.000000000 Z
11
+ date: 2017-06-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: paru
@@ -104,7 +104,6 @@ files:
104
104
  - lib/pandocomatic/error/pandoc_error.rb
105
105
  - lib/pandocomatic/error/pandocomatic_error.rb
106
106
  - lib/pandocomatic/error/processor_error.rb
107
- - lib/pandocomatic/fileinfo_preprocessor.rb
108
107
  - lib/pandocomatic/pandoc_metadata.rb
109
108
  - lib/pandocomatic/pandocomatic.rb
110
109
  - lib/pandocomatic/printer/command_printer.rb
@@ -130,6 +129,8 @@ files:
130
129
  - lib/pandocomatic/printer/views/warning.txt
131
130
  - lib/pandocomatic/printer/warning_printer.rb
132
131
  - lib/pandocomatic/processor.rb
132
+ - lib/pandocomatic/processors/fileinfo_preprocessor.rb
133
+ - lib/pandocomatic/processors/metadata_preprocessor.rb
133
134
  - lib/pandocomatic/warning.rb
134
135
  homepage: https://heerdebeer.org/Software/markdown/pandocomatic/
135
136
  licenses: