pandocomatic 0.0.13 → 0.1.0.b
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 +4 -4
- data/bin/pandocomatic +2 -78
- data/lib/pandocomatic/cli.rb +183 -0
- data/lib/pandocomatic/command/command.rb +113 -0
- data/lib/pandocomatic/command/convert_dir_command.rb +155 -0
- data/lib/pandocomatic/command/convert_file_command.rb +163 -0
- data/lib/pandocomatic/command/copy_file_command.rb +49 -0
- data/lib/pandocomatic/command/create_link_command.rb +85 -0
- data/lib/pandocomatic/command/skip_command.rb +50 -0
- data/lib/pandocomatic/configuration.rb +212 -164
- data/lib/pandocomatic/error/cli_error.rb +49 -0
- data/lib/pandocomatic/error/configuration_error.rb +39 -0
- data/lib/pandocomatic/error/io_error.rb +50 -0
- data/lib/pandocomatic/error/pandoc_error.rb +30 -0
- data/lib/pandocomatic/error/pandocomatic_error.rb +48 -0
- data/lib/pandocomatic/error/processor_error.rb +33 -0
- data/lib/pandocomatic/fileinfo_preprocessor.rb +34 -13
- data/lib/pandocomatic/pandoc_metadata.rb +66 -34
- data/lib/pandocomatic/pandocomatic.rb +176 -0
- data/lib/pandocomatic/printer/command_printer.rb +28 -0
- data/lib/pandocomatic/printer/configuration_errors_printer.rb +29 -0
- data/lib/pandocomatic/printer/error_printer.rb +34 -0
- data/lib/pandocomatic/printer/finish_printer.rb +44 -0
- data/lib/pandocomatic/printer/help_printer.rb +27 -0
- data/lib/pandocomatic/printer/printer.rb +43 -0
- data/lib/pandocomatic/printer/summary_printer.rb +35 -0
- data/lib/pandocomatic/printer/version_printer.rb +30 -0
- data/lib/pandocomatic/printer/views/cli_error.txt +12 -0
- data/lib/pandocomatic/printer/views/command.txt +1 -0
- data/lib/pandocomatic/printer/views/configuration_error.txt +1 -0
- data/lib/pandocomatic/printer/views/configuration_errors.txt +10 -0
- data/lib/pandocomatic/printer/views/error.txt +5 -0
- data/lib/pandocomatic/printer/views/finish.txt +1 -0
- data/lib/pandocomatic/printer/views/help.txt +135 -0
- data/lib/pandocomatic/printer/views/io_error.txt +12 -0
- data/lib/pandocomatic/printer/views/pandoc_error.txt +1 -0
- data/lib/pandocomatic/printer/views/processor_error.txt +6 -0
- data/lib/pandocomatic/printer/views/summary.txt +1 -0
- data/lib/pandocomatic/printer/views/version.txt +7 -0
- data/lib/pandocomatic/printer/views/warning.txt +1 -0
- data/lib/pandocomatic/printer/warning_printer.rb +33 -0
- data/lib/pandocomatic/processor.rb +25 -8
- data/lib/pandocomatic/warning.rb +36 -0
- metadata +79 -17
- data/lib/pandocomatic/dir_converter.rb +0 -119
- data/lib/pandocomatic/file_converter.rb +0 -99
@@ -0,0 +1,50 @@
|
|
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
|
+
require_relative './pandocomatic_error.rb'
|
21
|
+
|
22
|
+
class IOError < PandocomaticError
|
23
|
+
|
24
|
+
def template()
|
25
|
+
'io_error.txt'
|
26
|
+
end
|
27
|
+
|
28
|
+
# :file_does_not_exist file
|
29
|
+
# :file_is_not_a_file file
|
30
|
+
# :file_is_not_readable file
|
31
|
+
# :file_is_not_writable file
|
32
|
+
|
33
|
+
# :error_opening_file file
|
34
|
+
# :error_writing_file file
|
35
|
+
|
36
|
+
# :directory_does_not_exist dir
|
37
|
+
# :directory_is_not_a_directory dir
|
38
|
+
# :directory_is_not_readable dir
|
39
|
+
# :directory_is_not_writable dir
|
40
|
+
|
41
|
+
# :error_opening_directory dir
|
42
|
+
# :error_creating_directory dir
|
43
|
+
|
44
|
+
# :file_or_directory_does_not_exist src
|
45
|
+
# :unable_to_copy_file [src, dst]
|
46
|
+
# :unable_to_create_symbolic_link [src, dst]
|
47
|
+
# :unable_to_read_symbolic_link [src]
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
@@ -0,0 +1,30 @@
|
|
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
|
+
require_relative './pandocomatic_error.rb'
|
21
|
+
|
22
|
+
class PandocError < PandocomaticError
|
23
|
+
|
24
|
+
def template()
|
25
|
+
'pandoc_error.txt'
|
26
|
+
end
|
27
|
+
|
28
|
+
# :error_running_pandoc
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,48 @@
|
|
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
|
+
require_relative '../printer/error_printer.rb'
|
21
|
+
|
22
|
+
class PandocomaticError < StandardError
|
23
|
+
attr_reader :type, :error, :data
|
24
|
+
def initialize(type = :unknown, error = nil, data = nil)
|
25
|
+
super type.to_s.gsub("_", " ").capitalize
|
26
|
+
@type = type
|
27
|
+
@error = error
|
28
|
+
@data = data
|
29
|
+
end
|
30
|
+
|
31
|
+
def has_error?()
|
32
|
+
not @error.nil?
|
33
|
+
end
|
34
|
+
|
35
|
+
def has_data?()
|
36
|
+
not @data.nil?
|
37
|
+
end
|
38
|
+
|
39
|
+
def print()
|
40
|
+
ErrorPrinter.new(self).print
|
41
|
+
end
|
42
|
+
|
43
|
+
def show()
|
44
|
+
ErrorPrinter.new(self).to_s
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,33 @@
|
|
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
|
+
require_relative './pandocomatic_error.rb'
|
21
|
+
|
22
|
+
class ProcessorError < PandocomaticError
|
23
|
+
|
24
|
+
def template()
|
25
|
+
'processor_error.txt'
|
26
|
+
end
|
27
|
+
|
28
|
+
# :script_does_not_exist script
|
29
|
+
# :script_is_not_executable script
|
30
|
+
# :error_processing_script [script, src]
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
@@ -1,16 +1,37 @@
|
|
1
|
+
#--
|
2
|
+
# Copyright 2014, 2015, 2016, 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
|
+
#++
|
1
19
|
module Pandocomatic
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
20
|
+
|
21
|
+
# FileInfoPreprocessor collects information about a file to be converted and
|
22
|
+
# mixes that information into that file's metadata. It is a default
|
23
|
+
# preprocessor.
|
24
|
+
class FileInfoPreprocessor < Processor
|
25
|
+
def self.run input, path
|
26
|
+
created_at = File.stat(path).ctime
|
27
|
+
modified_at = File.stat(path).mtime
|
28
|
+
output = input
|
29
|
+
output << "\n---\n"
|
30
|
+
output << "fileinfo:\n"
|
31
|
+
output << " path: '#{path}'\n"
|
32
|
+
output << " created: #{created_at.strftime '%Y-%m-%d'}\n"
|
33
|
+
output << " modified: #{modified_at.strftime '%Y-%m-%d'}\n"
|
34
|
+
output << "..."
|
15
35
|
end
|
36
|
+
end
|
16
37
|
end
|
@@ -1,64 +1,93 @@
|
|
1
|
+
#--
|
2
|
+
# Copyright 2014, 2015, 2016, 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
|
+
#++
|
1
19
|
module Pandocomatic
|
2
20
|
|
3
21
|
require 'json'
|
4
22
|
require 'yaml'
|
5
|
-
require 'paru
|
23
|
+
require 'paru'
|
6
24
|
|
7
|
-
|
25
|
+
require_relative './error/pandoc_error.rb'
|
26
|
+
require_relative './error/io_error.rb'
|
8
27
|
|
28
|
+
class PandocMetadata < Hash
|
29
|
+
|
9
30
|
# Paru converters:
|
10
31
|
# Note. When converting metadata back to the pandoc markdown format, you have
|
11
|
-
# to use the option
|
12
|
-
PANDOC_2_JSON = Paru::Pandoc.new {from
|
13
|
-
JSON_2_PANDOC = Paru::Pandoc.new {from
|
32
|
+
# to use the option 'standalone', otherwise the metadata is skipped
|
33
|
+
PANDOC_2_JSON = Paru::Pandoc.new {from 'markdown'; to 'json'}
|
34
|
+
JSON_2_PANDOC = Paru::Pandoc.new {from 'json'; to 'markdown'; standalone}
|
14
35
|
|
15
36
|
# When converting a pandoc document to JSON, or vice versa, the JSON object
|
16
37
|
# has the following three properties:
|
17
|
-
VERSION =
|
18
|
-
META =
|
19
|
-
BLOCKS =
|
20
|
-
|
21
|
-
def initialize hash = {}
|
22
|
-
super
|
23
|
-
merge! hash
|
24
|
-
end
|
38
|
+
VERSION = 'pandoc-api-version'
|
39
|
+
META = 'meta'
|
40
|
+
BLOCKS = 'blocks'
|
25
41
|
|
26
|
-
|
27
|
-
def self.load_file src
|
42
|
+
def self.extract_metadata input_document
|
28
43
|
begin
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
else
|
33
|
-
return PandocMetadata.new YAML.load(yaml_metadata)
|
34
|
-
end
|
35
|
-
rescue Exception => e
|
36
|
-
raise "Error while reading metadata from #{src}; Are you sure it is a pandoc markdown file?\n#{e.message}"
|
44
|
+
pandoc2yaml File.read(input_document)
|
45
|
+
rescue StandardError => e
|
46
|
+
raise IOError.new(:error_opening_file, e, input_document)
|
37
47
|
end
|
38
48
|
end
|
39
49
|
|
40
|
-
def self.pandoc2yaml
|
41
|
-
json = JSON.parse(PANDOC_2_JSON << document)
|
50
|
+
def self.pandoc2yaml(input)
|
42
51
|
yaml = ""
|
52
|
+
begin
|
53
|
+
json = JSON.parse(PANDOC_2_JSON << input)
|
43
54
|
|
44
|
-
|
55
|
+
version, metadata = json.values_at(VERSION, META)
|
45
56
|
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
57
|
+
if not metadata.empty? then
|
58
|
+
metadata_document = {
|
59
|
+
VERSION => version,
|
60
|
+
META => metadata,
|
61
|
+
BLOCKS => []
|
62
|
+
}
|
52
63
|
|
53
|
-
|
64
|
+
yaml = JSON_2_PANDOC << JSON.generate(metadata_document)
|
65
|
+
end
|
66
|
+
rescue Paru::Error => e
|
67
|
+
raise PandocError.new(:error_running_pandoc, e, input_document)
|
54
68
|
end
|
55
69
|
|
56
70
|
yaml
|
57
71
|
end
|
58
72
|
|
73
|
+
# Collect the metadata embedded in the src file
|
74
|
+
def self.load_file src
|
75
|
+
yaml_metadata = extract_metadata src
|
76
|
+
if yaml_metadata.empty? then
|
77
|
+
return PandocMetadata.new
|
78
|
+
else
|
79
|
+
return PandocMetadata.new YAML.load(yaml_metadata)
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
def initialize hash = {}
|
84
|
+
super
|
85
|
+
merge! hash
|
86
|
+
end
|
87
|
+
|
59
88
|
def has_template?
|
60
89
|
self['pandocomatic'] and self['pandocomatic']['use-template'] and
|
61
|
-
|
90
|
+
not self['pandocomatic']['use-template'].empty?
|
62
91
|
end
|
63
92
|
|
64
93
|
def template_name
|
@@ -69,6 +98,9 @@ module Pandocomatic
|
|
69
98
|
end
|
70
99
|
end
|
71
100
|
|
101
|
+
# TODO: allow a pandoc block outside a pandocomatic block to make
|
102
|
+
# pandocomatic work like paru's do-pandoc.rb.
|
103
|
+
|
72
104
|
def has_pandoc_options?
|
73
105
|
self['pandocomatic'] and self['pandocomatic']['pandoc']
|
74
106
|
end
|
@@ -0,0 +1,176 @@
|
|
1
|
+
#--
|
2
|
+
# Copyright 2014, 2015, 2016, 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 'paru'
|
22
|
+
|
23
|
+
require_relative './error/pandocomatic_error.rb'
|
24
|
+
require_relative './error/pandoc_error.rb'
|
25
|
+
require_relative './error/configuration_error.rb'
|
26
|
+
|
27
|
+
require_relative './cli.rb'
|
28
|
+
|
29
|
+
require_relative './configuration.rb'
|
30
|
+
|
31
|
+
require_relative './printer/help_printer.rb'
|
32
|
+
require_relative './printer/version_printer.rb'
|
33
|
+
require_relative './printer/error_printer.rb'
|
34
|
+
require_relative './printer/configuration_errors_printer.rb'
|
35
|
+
require_relative './printer/finish_printer.rb'
|
36
|
+
require_relative './printer/summary_printer.rb'
|
37
|
+
|
38
|
+
require_relative './command/command.rb'
|
39
|
+
require_relative './command/convert_dir_command.rb'
|
40
|
+
require_relative './command/convert_file_command.rb'
|
41
|
+
|
42
|
+
class Pandocomatic
|
43
|
+
VERSION = [0, 1, 0]
|
44
|
+
CONFIG_FILE = 'pandocomatic.yaml'
|
45
|
+
|
46
|
+
def self.run(args)
|
47
|
+
begin
|
48
|
+
start_time = Time.now
|
49
|
+
options = CLI.parse args
|
50
|
+
|
51
|
+
if options[:version_given]
|
52
|
+
# The version option has precedence over all other options; if
|
53
|
+
# given, the version is printed
|
54
|
+
VersionPrinter.new(VERSION).print
|
55
|
+
elsif options[:help_given]
|
56
|
+
# The help option has precedence over all other options except the
|
57
|
+
# version option. If given, the help is printed.
|
58
|
+
HelpPrinter.new().print
|
59
|
+
else
|
60
|
+
# Run the pandocomatic converter configured according to the options
|
61
|
+
# given.
|
62
|
+
input = options[:input]
|
63
|
+
output = options[:output]
|
64
|
+
configuration = configure options
|
65
|
+
|
66
|
+
# Extend the command classes by setting the source tree root
|
67
|
+
# directory, and the options quiet and dry-run, which are used when
|
68
|
+
# executing a command: if dry-run the command is not actually
|
69
|
+
# executed and if quiet the command is not printed to STDOUT
|
70
|
+
src_root = File.absolute_path input
|
71
|
+
dry_run = if options[:dry_run_given] then options[:dry_run] else false end
|
72
|
+
quiet = if options[:quiet_given] then options[:quiet] else false end
|
73
|
+
modified_only = if options[:modified_only_given] then options[:modified_only_given] else false end
|
74
|
+
|
75
|
+
Command.reset(src_root, dry_run, quiet, modified_only)
|
76
|
+
|
77
|
+
# Pandocomatic has two modes: converting a directory tree or
|
78
|
+
# converting a single file. The mode is selected by the input.
|
79
|
+
if File.directory? input
|
80
|
+
command = ConvertDirCommand.new(configuration, input, output)
|
81
|
+
else
|
82
|
+
command = ConvertFileCommand.new(configuration, input, output)
|
83
|
+
end
|
84
|
+
|
85
|
+
# Notify the user about all configuration errors collected when
|
86
|
+
# determining the commands to run to perform this pandocomatic
|
87
|
+
# conversion.
|
88
|
+
if command.all_errors.size > 0
|
89
|
+
ConfigurationErrorsPrinter.new(command.all_errors).print
|
90
|
+
exit
|
91
|
+
end
|
92
|
+
|
93
|
+
# Pandocomatic is successfully configured: running the
|
94
|
+
# actual conversion now.
|
95
|
+
SummaryPrinter.new(command, input, output).print unless quiet
|
96
|
+
|
97
|
+
# Depending on the options dry-run and quiet, the command.execute
|
98
|
+
# method will actually performing the commands (dry-run = false) and
|
99
|
+
# print the command to STDOUT (quiet = false)
|
100
|
+
command.execute()
|
101
|
+
|
102
|
+
FinishPrinter.new(command, input, output, start_time).print unless quiet
|
103
|
+
end
|
104
|
+
rescue PandocomaticError => e
|
105
|
+
# Report the error and break off the conversion process.
|
106
|
+
ErrorPrinter.new(e).print
|
107
|
+
rescue StandardError => e
|
108
|
+
# An unexpected error has occurred; break off the program drastically
|
109
|
+
# for now
|
110
|
+
raise e
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
private
|
115
|
+
|
116
|
+
def self.determine_config_file(options, data_dir = Dir.pwd)
|
117
|
+
config_file = ''
|
118
|
+
|
119
|
+
if options[:config_given]
|
120
|
+
config_file = options[:config]
|
121
|
+
elsif Dir.entries(data_dir).include? CONFIG_FILE
|
122
|
+
config_file = File.join(data_dir, CONFIG_FILE)
|
123
|
+
elsif Dir.entries(Dir.pwd()).include? CONFIG_FILE
|
124
|
+
config_file = File.join(Dir.pwd(), CONFIG_FILE)
|
125
|
+
else
|
126
|
+
# Fall back to default configuration file distributed with
|
127
|
+
# pandocomatic
|
128
|
+
config_file = File.join(__dir__, 'default_configuration.yaml')
|
129
|
+
end
|
130
|
+
|
131
|
+
path = File.absolute_path config_file
|
132
|
+
|
133
|
+
raise ConfigurationError.new(:config_file_does_not_exist, nil, path) unless File.exist? path
|
134
|
+
raise ConfigurationError.new(:config_file_is_not_a_file, nil, path) unless File.file? path
|
135
|
+
raise ConfigurationError.new(:config_file_is_not_readable, nil, path) unless File.readable? path
|
136
|
+
|
137
|
+
path
|
138
|
+
end
|
139
|
+
|
140
|
+
def self.determine_data_dir(options)
|
141
|
+
data_dir = ''
|
142
|
+
|
143
|
+
if options[:data_dir_given]
|
144
|
+
data_dir = options[:data_dir]
|
145
|
+
else
|
146
|
+
# No data-dir option given: try to find the default one from pandoc
|
147
|
+
begin
|
148
|
+
data_dir = Paru::Pandoc.info()[:data_dir]
|
149
|
+
rescue Paru::Error => e
|
150
|
+
# If pandoc cannot be run, continuing probably does not work out
|
151
|
+
# anyway, so raise pandoc error
|
152
|
+
raise PandocError.new(:error_running_pandoc, e, data_dir)
|
153
|
+
rescue StandardError => e
|
154
|
+
# Ignore error and use the current working directory as default working directory
|
155
|
+
data_dir = Dir.pwd
|
156
|
+
end
|
157
|
+
end
|
158
|
+
|
159
|
+
# check if data directory does exist and is readable
|
160
|
+
path = File.absolute_path data_dir
|
161
|
+
|
162
|
+
raise ConfigurationError.new(:data_dir_does_not_exist, nil, path) unless File.exist? path
|
163
|
+
raise ConfigurationError.new(:data_dir_is_not_a_directory, nil, path) unless File.directory? path
|
164
|
+
raise ConfigurationError.new(:data_dir_is_not_readable, nil, path) unless File.readable? path
|
165
|
+
|
166
|
+
path
|
167
|
+
end
|
168
|
+
|
169
|
+
def self.configure(options)
|
170
|
+
data_dir = determine_data_dir options
|
171
|
+
config_file = determine_config_file options, data_dir
|
172
|
+
Configuration.new options, data_dir, config_file
|
173
|
+
end
|
174
|
+
|
175
|
+
end
|
176
|
+
end
|
@@ -0,0 +1,28 @@
|
|
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
|
+
require_relative './printer.rb'
|
21
|
+
|
22
|
+
class CommandPrinter < Printer
|
23
|
+
def initialize(command)
|
24
|
+
super 'command.txt'
|
25
|
+
@command = command
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,29 @@
|
|
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
|
+
require_relative './printer.rb'
|
21
|
+
|
22
|
+
class ConfigurationErrorsPrinter < Printer
|
23
|
+
def initialize(errors)
|
24
|
+
super 'configuration_errors.txt'
|
25
|
+
@errors = errors
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,34 @@
|
|
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
|
+
require_relative './printer.rb'
|
21
|
+
|
22
|
+
class ErrorPrinter < Printer
|
23
|
+
def initialize(error)
|
24
|
+
template = if error.respond_to? :template then error.template else 'error.txt' end
|
25
|
+
super template
|
26
|
+
@error = error
|
27
|
+
end
|
28
|
+
|
29
|
+
def print
|
30
|
+
warn to_s
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,44 @@
|
|
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
|
+
require_relative './summary_printer.rb'
|
21
|
+
|
22
|
+
class FinishPrinter < SummaryPrinter
|
23
|
+
MINUTE = 60 # seconds
|
24
|
+
def initialize(command, input, output, start_time)
|
25
|
+
super command, input, output
|
26
|
+
set_template 'finish.txt'
|
27
|
+
|
28
|
+
@start_time = start_time
|
29
|
+
@end_time = Time.now
|
30
|
+
end
|
31
|
+
|
32
|
+
def duration()
|
33
|
+
seconds = @end_time - @start_time
|
34
|
+
if seconds > MINUTE
|
35
|
+
minutes = (seconds / MINUTE).floor
|
36
|
+
seconds = seconds - (minutes * MINUTE)
|
37
|
+
"#{minutes} minute#{'s' if minutes != 1} and #{seconds.round(1)} second#{'s' if seconds != 1}"
|
38
|
+
else
|
39
|
+
"#{seconds.round(1)} second#{'s' if seconds != 1}"
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
44
|
+
end
|