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
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0f420d7805d00a32e2c3d512ef5e417e0d271747
|
4
|
+
data.tar.gz: 1f24021a1464b79431dc35fc7d65e208074e3914
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 831b0ebc2839e740b9d66a0b80938ec4ba98da4d0a7ba68101ff5293f58d5604d9991154c01af16f2a62c33469b97e10b47c9f433e9997cd8cb45106ea03f413
|
7
|
+
data.tar.gz: 70b08044e7a6810d4ed48f5d787c2fe182917aeaa3c8d1b256da5bd80a3652b313c61561825bb7e1e6ffae0b4aebff346242eaf1f8b95d79e47e6109a4c8cfeb
|
@@ -28,10 +28,26 @@ module Pandocomatic
|
|
28
28
|
require_relative 'copy_file_command.rb'
|
29
29
|
require_relative 'skip_command.rb'
|
30
30
|
|
31
|
+
# Commmand to convert a directory
|
32
|
+
#
|
33
|
+
# @!attribute config
|
34
|
+
# @return [Configuration] configuration to use when converting directory
|
35
|
+
#
|
36
|
+
# @!attribute src_dir
|
37
|
+
# @return [String] the source directory to convert from
|
38
|
+
#
|
39
|
+
# @!attribute dst_dir
|
40
|
+
# @return [String] the destination directory to convert to
|
31
41
|
class ConvertDirCommand < ConvertListCommand
|
32
42
|
|
33
43
|
attr_reader :config, :src_dir, :dst_dir
|
34
44
|
|
45
|
+
# Create a new ConvertDirCommand
|
46
|
+
#
|
47
|
+
# @param current_config [Configuration] The configuration of pandocomatic
|
48
|
+
# as it was before entering the source directory
|
49
|
+
# @param src_dir [String] the directory to convert
|
50
|
+
# @param dst_dir [String] the directory to convert to
|
35
51
|
def initialize(current_config, src_dir, dst_dir)
|
36
52
|
super()
|
37
53
|
@src_dir = src_dir
|
@@ -87,18 +103,28 @@ module Pandocomatic
|
|
87
103
|
uncount if skip?
|
88
104
|
end
|
89
105
|
|
106
|
+
# Should this command be skipped?
|
107
|
+
#
|
108
|
+
# @return [Boolean] True if this command has no sub commands
|
90
109
|
def skip?()
|
91
110
|
@subcommands.empty?
|
92
111
|
end
|
93
112
|
|
113
|
+
# Converts this command a directory?
|
114
|
+
#
|
115
|
+
# @return [Boolean] true
|
94
116
|
def directory?()
|
95
117
|
true
|
96
118
|
end
|
97
119
|
|
120
|
+
# Convert this command to a String representation for a Printer
|
121
|
+
#
|
122
|
+
# @return [String]
|
98
123
|
def to_s()
|
99
124
|
"convert #{@src_dir}" + '; ' + if create_directory? then 'create and ' else '' end + "enter #{@dst_dir}"
|
100
125
|
end
|
101
126
|
|
127
|
+
# Run this command
|
102
128
|
def run()
|
103
129
|
begin
|
104
130
|
Dir.mkdir @dst_dir if create_directory?
|
@@ -35,8 +35,20 @@ module Pandocomatic
|
|
35
35
|
|
36
36
|
require_relative 'command.rb'
|
37
37
|
|
38
|
+
# Output formats used in pandocomatic
|
38
39
|
OUTPUT_FORMATS = ["docx", "odt", "pdf", "beamer"]
|
39
40
|
|
41
|
+
# Command to convert a file
|
42
|
+
#
|
43
|
+
# @!attribute config
|
44
|
+
# @return [Configuration] the configuration of pandocomatic used to
|
45
|
+
# convert the file
|
46
|
+
#
|
47
|
+
# @!attribute src
|
48
|
+
# @return [String] the path to the file to convert
|
49
|
+
#
|
50
|
+
# @!attribute dst
|
51
|
+
# @return [String] the path to the output file
|
40
52
|
class ConvertFileCommand < Command
|
41
53
|
|
42
54
|
attr_reader :config, :src, :dst
|
@@ -27,10 +27,21 @@ module Pandocomatic
|
|
27
27
|
require_relative 'copy_file_command.rb'
|
28
28
|
require_relative 'skip_command.rb'
|
29
29
|
|
30
|
+
# Create a command to convert one file multiple times
|
31
|
+
#
|
32
|
+
# @!attribute subcommands
|
33
|
+
# @return [Command[]] the subcommands to execute when running this
|
34
|
+
# ConvertFileMultipleCommand
|
30
35
|
class ConvertFileMultipleCommand < ConvertListCommand
|
31
36
|
|
32
37
|
attr_reader :subcommands
|
33
38
|
|
39
|
+
# Create a new ConvertFileMultipleCommand
|
40
|
+
#
|
41
|
+
# @param config [Configuration] Pandocomatic's configuration used to
|
42
|
+
# convert the source file
|
43
|
+
# @param src [String] the file to convert
|
44
|
+
# @param dst [String] the output file
|
34
45
|
def initialize(config, src, dst)
|
35
46
|
super()
|
36
47
|
@config = config
|
@@ -48,30 +59,15 @@ module Pandocomatic
|
|
48
59
|
end
|
49
60
|
end
|
50
61
|
|
51
|
-
def push(command)
|
52
|
-
@subcommands.push command
|
53
|
-
end
|
54
|
-
|
55
|
-
def skip?()
|
56
|
-
@subcommands.empty?
|
57
|
-
end
|
58
|
-
|
59
|
-
def count()
|
60
|
-
@subcommands.reduce(if skip? then 0 else 1 end) do |total, subcommand|
|
61
|
-
total += subcommand.count
|
62
|
-
end
|
63
|
-
end
|
64
|
-
|
65
|
-
def all_errors()
|
66
|
-
@subcommands.reduce(@errors) do |total, subcommand|
|
67
|
-
total += subcommand.all_errors
|
68
|
-
end
|
69
|
-
end
|
70
62
|
|
63
|
+
# A string representation of this command
|
64
|
+
#
|
65
|
+
# @return [String]
|
71
66
|
def to_s()
|
72
67
|
"converting #{@src} #{@subcommands.size} time#{'s' if @subcommands.size != 1}:"
|
73
68
|
end
|
74
69
|
|
70
|
+
# Execute this ConvertFileMultipleCommand
|
75
71
|
def execute()
|
76
72
|
if not @subcommands.empty?
|
77
73
|
CommandPrinter.new(self).print unless quiet? or @subcommands.size == 1
|
@@ -26,43 +26,66 @@ module Pandocomatic
|
|
26
26
|
require_relative 'copy_file_command.rb'
|
27
27
|
require_relative 'skip_command.rb'
|
28
28
|
|
29
|
+
# A Command with sub commands
|
30
|
+
#
|
31
|
+
# @!attribute subcommands
|
32
|
+
# @return [Command[]] the subcommands of this ConvertListCommand
|
29
33
|
class ConvertListCommand < Command
|
30
34
|
|
31
35
|
attr_reader :subcommands
|
32
36
|
|
37
|
+
# Create a new ConvertListCommand
|
33
38
|
def initialize()
|
34
39
|
super()
|
35
40
|
@subcommands = []
|
36
41
|
end
|
37
42
|
|
43
|
+
# Push a command to this ConvertListCommand
|
44
|
+
#
|
45
|
+
# @param command [Command] command to add
|
38
46
|
def push(command)
|
39
47
|
@subcommands.push command
|
40
48
|
end
|
41
49
|
|
50
|
+
# Skip this ConvertListCommand when there are no sub commands
|
51
|
+
#
|
52
|
+
# @return [Boolean]
|
42
53
|
def skip?()
|
43
54
|
@subcommands.empty?
|
44
55
|
end
|
45
56
|
|
57
|
+
# The number of commands to execute when this ConvertListCommand
|
58
|
+
# is executed.
|
46
59
|
def count()
|
47
60
|
@subcommands.reduce(if skip? then 0 else 1 end) do |total, subcommand|
|
48
61
|
total += subcommand.count
|
49
62
|
end
|
50
63
|
end
|
51
64
|
|
65
|
+
# Get a list of all errors generated while running this command
|
66
|
+
#
|
67
|
+
# @return [Error[]]
|
52
68
|
def all_errors()
|
53
69
|
@subcommands.reduce(@errors) do |total, subcommand|
|
54
70
|
total += subcommand.all_errors
|
55
71
|
end
|
56
72
|
end
|
57
73
|
|
74
|
+
# A string representation of this ConvertListCommand
|
75
|
+
#
|
76
|
+
# @return [String]
|
58
77
|
def to_s()
|
59
78
|
"converting #{@subcommands.size} items:"
|
60
79
|
end
|
61
80
|
|
81
|
+
# Can this command have multiple commands?
|
82
|
+
#
|
83
|
+
# @return [Boolean] true
|
62
84
|
def multiple?
|
63
85
|
true
|
64
86
|
end
|
65
87
|
|
88
|
+
# Execute this ConvertListCommand
|
66
89
|
def execute()
|
67
90
|
if not @subcommands.empty?
|
68
91
|
CommandPrinter.new(self).print unless quiet?
|
@@ -22,9 +22,17 @@ module Pandocomatic
|
|
22
22
|
require_relative '../error/io_error.rb'
|
23
23
|
require_relative 'command.rb'
|
24
24
|
|
25
|
+
# A command to copy a file
|
26
|
+
#
|
27
|
+
# @!attribute src
|
28
|
+
# @return [String] path to the file to copy
|
25
29
|
class CopyFileCommand < Command
|
26
30
|
attr_reader :src
|
27
31
|
|
32
|
+
# Create a new CopyFileCommand
|
33
|
+
#
|
34
|
+
# @param src [String] path to the file to copy
|
35
|
+
# @param dst [String] path to the place to copy the source file to
|
28
36
|
def initialize(src, dst)
|
29
37
|
super()
|
30
38
|
@src = src
|
@@ -33,6 +41,7 @@ module Pandocomatic
|
|
33
41
|
@errors.push IOError.new(:file_is_not_writable, nil, @dst) unless not File.exist?(@dst) or File.writable?(@dst)
|
34
42
|
end
|
35
43
|
|
44
|
+
# Run this CopyFileCommand
|
36
45
|
def run()
|
37
46
|
begin
|
38
47
|
FileUtils.cp(@src, @dst) if file_modified?(@src, @dst)
|
@@ -41,6 +50,9 @@ module Pandocomatic
|
|
41
50
|
end
|
42
51
|
end
|
43
52
|
|
53
|
+
# A string representation of this CopyFileCommand
|
54
|
+
#
|
55
|
+
# @return [String]
|
44
56
|
def to_s()
|
45
57
|
"copy #{File.basename @src}"
|
46
58
|
end
|
@@ -24,10 +24,24 @@ module Pandocomatic
|
|
24
24
|
require_relative '../error/io_error.rb'
|
25
25
|
require_relative '../printer/warning_printer.rb'
|
26
26
|
|
27
|
+
# A command to create a link to a file
|
28
|
+
#
|
29
|
+
# @!attribute src
|
30
|
+
# @return [String] the path to the file to link to
|
31
|
+
#
|
32
|
+
# @!attribute dst
|
33
|
+
# @return [String] the link name to create
|
34
|
+
#
|
35
|
+
# @!attribute dst_target
|
36
|
+
# @return [String] the link in the destination tree to link to
|
27
37
|
class CreateLinkCommand < Command
|
28
38
|
|
29
39
|
attr_reader :src, :dst, :dst_target
|
30
40
|
|
41
|
+
# Create a new CreateLinkCommand
|
42
|
+
#
|
43
|
+
# @param src [String] the path to the file to link
|
44
|
+
# @param dst [String] the path to the name of the link to create
|
31
45
|
def initialize(src, dst)
|
32
46
|
super()
|
33
47
|
@src = src
|
@@ -51,6 +65,7 @@ module Pandocomatic
|
|
51
65
|
end
|
52
66
|
end
|
53
67
|
|
68
|
+
# Run this CreateLinkCommand
|
54
69
|
def run()
|
55
70
|
begin
|
56
71
|
File.symlink @dst_target, @dst unless File.exist? @dst
|
@@ -59,18 +74,29 @@ module Pandocomatic
|
|
59
74
|
end
|
60
75
|
end
|
61
76
|
|
77
|
+
# Can this CreateLinkCommand be run?
|
78
|
+
#
|
79
|
+
# @return [Boolean] True if there are no errors and both source and
|
80
|
+
# destination do exist
|
62
81
|
def runnable?()
|
63
82
|
not (has_errors? or @dst.nil? or @dst_target.nil? or @src.nil?)
|
64
83
|
end
|
65
84
|
|
85
|
+
# Create a string representation of this CreateLinkCommand
|
66
86
|
def to_s()
|
67
87
|
"link #{File.basename @dst} -> #{@dst_target}"
|
68
88
|
end
|
69
89
|
|
90
|
+
# Should this CreateLinkCommand be skipped?
|
91
|
+
#
|
92
|
+
# @return [Boolean]
|
70
93
|
def skip?()
|
71
94
|
not modified_only? or not modified?
|
72
95
|
end
|
73
96
|
|
97
|
+
# Has the source file been modified?
|
98
|
+
#
|
99
|
+
# @return [Boolean]
|
74
100
|
def modified?()
|
75
101
|
if File.exist? @dst then
|
76
102
|
absolute_dst = File.realpath @dst
|
@@ -20,26 +20,48 @@ module Pandocomatic
|
|
20
20
|
|
21
21
|
require_relative 'command.rb'
|
22
22
|
|
23
|
+
# A command to skip a file or directory
|
24
|
+
#
|
25
|
+
# @!attribute src
|
26
|
+
# @return [String] the file or directory to skip
|
27
|
+
#
|
28
|
+
# @!attribute message
|
29
|
+
# @return [String] message explaining why the file or directory is being skipped.
|
23
30
|
class SkipCommand < Command
|
24
31
|
attr_reader :src, :message
|
25
32
|
|
33
|
+
# Create a new SkipCommand
|
34
|
+
#
|
35
|
+
# @param src [String] path to the file to skip
|
36
|
+
# @param message [String] the message explaining why this file is being
|
37
|
+
# skipped
|
26
38
|
def initialize(src, message)
|
27
39
|
super()
|
28
40
|
@src = src
|
29
41
|
@message = message
|
30
42
|
end
|
31
43
|
|
44
|
+
# Has this SkipCommand a message?
|
45
|
+
#
|
46
|
+
# @return [Boolean]
|
32
47
|
def has_message?()
|
33
48
|
not(@message.nil? or @message.empty?)
|
34
49
|
end
|
35
50
|
|
51
|
+
# 'Run' this SkipCommand by doing nothing
|
36
52
|
def run()
|
37
53
|
end
|
38
54
|
|
55
|
+
# Skip this command
|
56
|
+
#
|
57
|
+
# @return [Boolean] true
|
39
58
|
def skip?()
|
40
59
|
true
|
41
60
|
end
|
42
61
|
|
62
|
+
# A string representation of this SkipCommand
|
63
|
+
#
|
64
|
+
# @return [String]
|
43
65
|
def to_s
|
44
66
|
"skipping #{File.basename @src}" + if has_message?
|
45
67
|
": #{@message.to_s}"
|
@@ -282,7 +282,7 @@ module Pandocomatic
|
|
282
282
|
|
283
283
|
# Reset the settings for pandocomatic based on a new settings Hash
|
284
284
|
#
|
285
|
-
# @settings [Hash] the new settings to use to reset the settings in
|
285
|
+
# @param settings [Hash] the new settings to use to reset the settings in
|
286
286
|
# this Configuration with.
|
287
287
|
def reset_settings(settings)
|
288
288
|
settings.each do |setting, value|
|
@@ -297,6 +297,14 @@ module Pandocomatic
|
|
297
297
|
end
|
298
298
|
end
|
299
299
|
|
300
|
+
# Deep copy a template
|
301
|
+
#
|
302
|
+
# @param template [Hash] the template to clone
|
303
|
+
# @return [Hash]
|
304
|
+
def clone_template(template)
|
305
|
+
Marshal.load(Marshal.dump(template))
|
306
|
+
end
|
307
|
+
|
300
308
|
# Merge two templates
|
301
309
|
#
|
302
310
|
# @param base_template [Hash] the base template
|
@@ -370,7 +378,7 @@ module Pandocomatic
|
|
370
378
|
|
371
379
|
to_extend.each do |name|
|
372
380
|
if @templates.has_key? name
|
373
|
-
|
381
|
+
merge resolved_template, clone_template(@templates[name])
|
374
382
|
else
|
375
383
|
warn "Cannot find template with name '#{parent_template_name}'. Skipping this template while extending: '#{template.to_s}'."
|
376
384
|
end
|
@@ -392,7 +400,7 @@ module Pandocomatic
|
|
392
400
|
extended_template = extend_template template
|
393
401
|
|
394
402
|
if @templates.has_key? name then
|
395
|
-
|
403
|
+
merge @templates[name], extended_template
|
396
404
|
else
|
397
405
|
@templates[name] = extended_template
|
398
406
|
end
|
@@ -19,8 +19,10 @@
|
|
19
19
|
module Pandocomatic
|
20
20
|
require_relative './pandocomatic_error.rb'
|
21
21
|
|
22
|
+
# A ConfigurationError
|
22
23
|
class ConfigurationError < PandocomaticError
|
23
24
|
|
25
|
+
# The template to print this ConfigurationError
|
24
26
|
def template()
|
25
27
|
'configuration_error.txt'
|
26
28
|
end
|