pandocomatic 0.1.4.10 → 0.1.4.11
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/pandocomatic/command/command.rb +0 -1
- data/lib/pandocomatic/command/convert_dir_command.rb +26 -0
- data/lib/pandocomatic/command/convert_file_command.rb +12 -0
- data/lib/pandocomatic/command/convert_file_multiple_command.rb +15 -19
- data/lib/pandocomatic/command/convert_list_command.rb +23 -0
- data/lib/pandocomatic/command/copy_file_command.rb +12 -0
- data/lib/pandocomatic/command/create_link_command.rb +26 -0
- data/lib/pandocomatic/command/skip_command.rb +22 -0
- data/lib/pandocomatic/configuration.rb +11 -3
- data/lib/pandocomatic/error/cli_error.rb +2 -0
- data/lib/pandocomatic/error/configuration_error.rb +2 -0
- data/lib/pandocomatic/error/io_error.rb +2 -0
- data/lib/pandocomatic/error/pandoc_error.rb +3 -1
- data/lib/pandocomatic/error/pandocomatic_error.rb +27 -0
- data/lib/pandocomatic/error/processor_error.rb +2 -0
- data/lib/pandocomatic/pandocomatic.rb +160 -152
- data/lib/pandocomatic/printer/command_printer.rb +2 -0
- data/lib/pandocomatic/printer/configuration_errors_printer.rb +2 -0
- data/lib/pandocomatic/printer/error_printer.rb +3 -0
- data/lib/pandocomatic/printer/finish_printer.rb +6 -1
- data/lib/pandocomatic/printer/help_printer.rb +2 -0
- data/lib/pandocomatic/printer/printer.rb +29 -17
- data/lib/pandocomatic/printer/summary_printer.rb +29 -15
- data/lib/pandocomatic/printer/version_printer.rb +2 -0
- data/lib/pandocomatic/printer/warning_printer.rb +15 -10
- data/lib/pandocomatic/processor.rb +19 -7
- data/lib/pandocomatic/processors/fileinfo_preprocessor.rb +26 -24
- data/lib/pandocomatic/processors/metadata_preprocessor.rb +17 -16
- data/lib/pandocomatic/warning.rb +19 -12
- metadata +3 -3
@@ -19,8 +19,12 @@
|
|
19
19
|
module Pandocomatic
|
20
20
|
require_relative './summary_printer.rb'
|
21
21
|
|
22
|
+
# Printer for the end of the conversion process in non-quiet mode
|
22
23
|
class FinishPrinter < SummaryPrinter
|
23
|
-
|
24
|
+
# A minute has 60 seconds
|
25
|
+
MINUTE = 60
|
26
|
+
|
27
|
+
# Create a new FinishPrinter
|
24
28
|
def initialize(command, input, output, start_time)
|
25
29
|
super command, input, output
|
26
30
|
set_template 'finish.txt'
|
@@ -29,6 +33,7 @@ module Pandocomatic
|
|
29
33
|
@end_time = Time.now
|
30
34
|
end
|
31
35
|
|
36
|
+
# Calculate the duration of the whole conversion process
|
32
37
|
def duration()
|
33
38
|
seconds = @end_time - @start_time
|
34
39
|
if seconds > MINUTE
|
@@ -17,27 +17,39 @@
|
|
17
17
|
# with pandocomatic. If not, see <http://www.gnu.org/licenses/>.
|
18
18
|
#++
|
19
19
|
module Pandocomatic
|
20
|
-
|
20
|
+
require 'erb'
|
21
21
|
|
22
|
-
|
22
|
+
# Printer base class for printing information from pandocomatic
|
23
|
+
class Printer
|
23
24
|
|
24
|
-
|
25
|
-
|
26
|
-
|
25
|
+
# Create a new Printer
|
26
|
+
#
|
27
|
+
# @param template_file [String = 'help.txt'] the template to use when
|
28
|
+
# printing.
|
29
|
+
def initialize(template_file = 'help.txt')
|
30
|
+
set_template template_file
|
31
|
+
end
|
27
32
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
33
|
+
# Set the template used by this Printer
|
34
|
+
#
|
35
|
+
# @param template_file [String] the template to use
|
36
|
+
def set_template(template_file)
|
37
|
+
dir = File.dirname(__FILE__)
|
38
|
+
@template = File.absolute_path(File.join(dir, 'views', template_file))
|
39
|
+
end
|
32
40
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
41
|
+
# Create a string based on this printer's template
|
42
|
+
#
|
43
|
+
# @return [String]
|
44
|
+
def to_s()
|
45
|
+
erb = ERB.new(File.read(@template), 0, '>')
|
46
|
+
erb.result(binding())
|
47
|
+
end
|
37
48
|
|
38
|
-
|
39
|
-
|
40
|
-
|
49
|
+
# Print to STDOUT
|
50
|
+
def print()
|
51
|
+
puts to_s()
|
52
|
+
end
|
41
53
|
|
42
|
-
|
54
|
+
end
|
43
55
|
end
|
@@ -17,23 +17,37 @@
|
|
17
17
|
# with pandocomatic. If not, see <http://www.gnu.org/licenses/>.
|
18
18
|
#++
|
19
19
|
module Pandocomatic
|
20
|
-
|
20
|
+
require_relative './printer.rb'
|
21
21
|
|
22
|
-
|
23
|
-
|
24
|
-
super 'summary.txt'
|
25
|
-
@command = command
|
26
|
-
@input = input
|
27
|
-
@output = output
|
28
|
-
end
|
22
|
+
# Printer for printing a summary of the conversion process in non-quiet mode
|
23
|
+
class SummaryPrinter < Printer
|
29
24
|
|
30
|
-
|
31
|
-
|
32
|
-
|
25
|
+
# Create a new SummaryPrinter
|
26
|
+
#
|
27
|
+
# @param command [Command] the command to summarize
|
28
|
+
# @param input [String] the filename of the input file
|
29
|
+
# @param output [String] the filename of the output file
|
30
|
+
def initialize(command, input, output)
|
31
|
+
super 'summary.txt'
|
32
|
+
@command = command
|
33
|
+
@input = input
|
34
|
+
@output = output
|
35
|
+
end
|
33
36
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
+
# A string representation of the commands being executed
|
38
|
+
#
|
39
|
+
# @return [String]
|
40
|
+
def commands()
|
41
|
+
"#{@command.count} command#{'s' if @command.count != 1}"
|
42
|
+
end
|
37
43
|
|
38
|
-
|
44
|
+
# Is there an output file?
|
45
|
+
#
|
46
|
+
# @return [Boolean] True if there is an output defined in this
|
47
|
+
# SummaryPrinter, false otherwise
|
48
|
+
def has_output?()
|
49
|
+
not @output.nil? and not @output.empty?
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
39
53
|
end
|
@@ -17,17 +17,22 @@
|
|
17
17
|
# with pandocomatic. If not, see <http://www.gnu.org/licenses/>.
|
18
18
|
#++
|
19
19
|
module Pandocomatic
|
20
|
-
|
20
|
+
require_relative './printer.rb'
|
21
21
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
22
|
+
# Printer for warnings
|
23
|
+
class WarningPrinter < Printer
|
24
|
+
# Create a new WarningPrinter
|
25
|
+
#
|
26
|
+
# @param warning [Warning] the warning to print
|
27
|
+
def initialize(warning)
|
28
|
+
template = 'warning.txt'
|
29
|
+
super template
|
30
|
+
@warning = warning
|
31
|
+
end
|
28
32
|
|
29
|
-
|
30
|
-
|
33
|
+
# Print warnings to STDERR rather than STDOUT
|
34
|
+
def print
|
35
|
+
warn to_s
|
36
|
+
end
|
31
37
|
end
|
32
|
-
end
|
33
38
|
end
|
@@ -17,14 +17,26 @@
|
|
17
17
|
# with pandocomatic. If not, see <http://www.gnu.org/licenses/>.
|
18
18
|
#++
|
19
19
|
module Pandocomatic
|
20
|
-
|
20
|
+
require 'open3'
|
21
21
|
|
22
|
-
|
22
|
+
# Generic class for processors used to preprocess, postproces, setup, and
|
23
|
+
# cleanup with external scripts or programs during the conversion process.
|
24
|
+
#
|
25
|
+
# For preprocessors and postprocessors it is assumed that the input is the
|
26
|
+
# contents of the file to convert and the output the processed input. In
|
27
|
+
# the end, the output will be put through pandoc.
|
28
|
+
class Processor
|
23
29
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
30
|
+
# Run script on input and return captured output
|
31
|
+
#
|
32
|
+
# @param script [String] path to script to run
|
33
|
+
# @param input [String] input to process in the script
|
34
|
+
#
|
35
|
+
# @return [String] output of script.
|
36
|
+
def self.run script, input
|
37
|
+
output, _ = Open3.capture2(script, :stdin_data => input)
|
38
|
+
output
|
39
|
+
end
|
28
40
|
|
29
|
-
|
41
|
+
end
|
30
42
|
end
|
@@ -18,30 +18,32 @@
|
|
18
18
|
#++
|
19
19
|
module Pandocomatic
|
20
20
|
|
21
|
-
|
21
|
+
require_relative '../processor.rb'
|
22
22
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
23
|
+
# FileInfoPreprocessor collects information about a file to be converted and
|
24
|
+
# mixes that information into that file's metadata. It is a default
|
25
|
+
# preprocessor.
|
26
|
+
#
|
27
|
+
class FileInfoPreprocessor < Processor
|
28
|
+
# Run this FileInfoPreprocessor
|
29
|
+
#
|
30
|
+
# @param input [String] the contents of the document being preprocessed
|
31
|
+
# @param path [String] the path to the input document
|
32
|
+
# @param options [Hash] pandoc options collected by pandocomatic to run on
|
33
|
+
# this file
|
34
|
+
def self.run input, path, options
|
35
|
+
created_at = File.stat(path).ctime
|
36
|
+
modified_at = File.stat(path).mtime
|
37
|
+
output = input
|
38
|
+
output << "\n\n---\n"
|
39
|
+
output << "pandocomatic-fileinfo:\n"
|
40
|
+
output << " from: #{options['from']}\n" if options.has_key? 'from'
|
41
|
+
output << " to: #{options['to']}\n" if options.has_key? 'to'
|
42
|
+
output << " template: #{options['template']}\n" if options.has_key? 'template'
|
43
|
+
output << " path: '#{path}'\n"
|
44
|
+
output << " created: #{created_at.strftime '%Y-%m-%d'}\n"
|
45
|
+
output << " modified: #{modified_at.strftime '%Y-%m-%d'}\n"
|
46
|
+
output << "...\n\n"
|
47
|
+
end
|
45
48
|
end
|
46
|
-
end
|
47
49
|
end
|
@@ -18,22 +18,23 @@
|
|
18
18
|
#++
|
19
19
|
module Pandocomatic
|
20
20
|
|
21
|
-
|
22
|
-
|
21
|
+
require 'yaml'
|
22
|
+
require_relative '../processor.rb'
|
23
23
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
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
|
37
39
|
end
|
38
|
-
end
|
39
40
|
end
|
data/lib/pandocomatic/warning.rb
CHANGED
@@ -17,20 +17,27 @@
|
|
17
17
|
# with pandocomatic. If not, see <http://www.gnu.org/licenses/>.
|
18
18
|
#++
|
19
19
|
module Pandocomatic
|
20
|
-
|
21
|
-
class Warning
|
22
20
|
|
23
|
-
#
|
24
|
-
|
25
|
-
def initialize(message = :unknown, data = nil)
|
26
|
-
@message = message
|
27
|
-
@data = data
|
28
|
-
end
|
21
|
+
# A warning given during the conversion process.
|
22
|
+
class Warning
|
29
23
|
|
30
|
-
|
31
|
-
|
32
|
-
|
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
|
33
34
|
|
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
|
35
41
|
|
42
|
+
end
|
36
43
|
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
|
+
version: 0.1.4.11
|
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-07-
|
11
|
+
date: 2017-07-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: paru
|
@@ -153,7 +153,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
153
153
|
requirements:
|
154
154
|
- pandoc, a universal document converer <http://pandoc.org>
|
155
155
|
rubyforge_project:
|
156
|
-
rubygems_version: 2.
|
156
|
+
rubygems_version: 2.5.2
|
157
157
|
signing_key:
|
158
158
|
specification_version: 4
|
159
159
|
summary: Automating the use of pandoc
|