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,49 @@
|
|
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 'fileutils'
|
21
|
+
|
22
|
+
require_relative '../error/io_error.rb'
|
23
|
+
require_relative 'command.rb'
|
24
|
+
|
25
|
+
class CopyFileCommand < Command
|
26
|
+
attr_reader :src
|
27
|
+
|
28
|
+
def initialize(src, dst)
|
29
|
+
super()
|
30
|
+
@src = src
|
31
|
+
@dst = dst
|
32
|
+
@errors.push IOError.new(:file_is_not_readable, nil, @src) unless File.readable? @src
|
33
|
+
@errors.push IOError.new(:file_is_not_writable, nil, @dst) unless not File.exist?(@dst) or File.writable?(@dst)
|
34
|
+
end
|
35
|
+
|
36
|
+
def run()
|
37
|
+
begin
|
38
|
+
FileUtils.cp(@src, @dst) if file_modified?(@src, @dst)
|
39
|
+
rescue StandardError => e
|
40
|
+
raise IOError.new(:unable_to_copy_file, e, [@src, @dst])
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def to_s()
|
45
|
+
"copy #{File.basename @src}"
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,85 @@
|
|
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_relative 'command.rb'
|
22
|
+
|
23
|
+
require_relative '../warning.rb'
|
24
|
+
require_relative '../error/io_error.rb'
|
25
|
+
require_relative '../printer/warning_printer.rb'
|
26
|
+
|
27
|
+
class CreateLinkCommand < Command
|
28
|
+
|
29
|
+
attr_reader :src, :dst, :dst_target
|
30
|
+
|
31
|
+
def initialize(src, dst)
|
32
|
+
super()
|
33
|
+
@src = src
|
34
|
+
begin
|
35
|
+
src_target = File.readlink @src
|
36
|
+
|
37
|
+
if src_target.start_with? '.' then
|
38
|
+
full_src_target = File.expand_path src_target, File.dirname(src)
|
39
|
+
|
40
|
+
if full_src_target.start_with? src_root()
|
41
|
+
@dst = dst
|
42
|
+
@dst_target = src_target
|
43
|
+
else
|
44
|
+
WarningPrinter.new(Warning.new(:skipping_link_because_it_points_outside_the_source_tree, @src)).print
|
45
|
+
end
|
46
|
+
|
47
|
+
uncount if skip?
|
48
|
+
end
|
49
|
+
rescue StandardError => e
|
50
|
+
@errors.push IOError.new(:unable_to_read_symbolic_link, e, @src)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def run()
|
55
|
+
begin
|
56
|
+
File.symlink @dst_target, @dst unless File.exist? @dst
|
57
|
+
rescue StandardError => e
|
58
|
+
raise IOError.new(:unable_to_create_symbolic_link, e, [@src, @dst])
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
def runnable?()
|
63
|
+
not (has_errors? or @dst.nil? or @dst_target.nil? or @src.nil?)
|
64
|
+
end
|
65
|
+
|
66
|
+
def to_s()
|
67
|
+
"link #{File.basename @dst} -> #{@dst_target}"
|
68
|
+
end
|
69
|
+
|
70
|
+
def skip?()
|
71
|
+
not modified_only? or not modified?
|
72
|
+
end
|
73
|
+
|
74
|
+
def modified?()
|
75
|
+
if File.exist? @dst then
|
76
|
+
absolute_dst = File.realpath @dst
|
77
|
+
target = File.expand_path(@dst_target, absolute_dst)
|
78
|
+
absolute_dst != target
|
79
|
+
else
|
80
|
+
true
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
end
|
85
|
+
end
|
@@ -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
|
+
|
21
|
+
require_relative 'command.rb'
|
22
|
+
|
23
|
+
class SkipCommand < Command
|
24
|
+
attr_reader :src, :message
|
25
|
+
|
26
|
+
def initialize(src, message)
|
27
|
+
super()
|
28
|
+
@src = src
|
29
|
+
@message = message
|
30
|
+
end
|
31
|
+
|
32
|
+
def has_message?()
|
33
|
+
not(@message.nil? or @message.empty?)
|
34
|
+
end
|
35
|
+
|
36
|
+
def run()
|
37
|
+
end
|
38
|
+
|
39
|
+
def skip?()
|
40
|
+
true
|
41
|
+
end
|
42
|
+
|
43
|
+
def to_s
|
44
|
+
"skipping #{File.basename @src}" + if has_message?
|
45
|
+
": #{@message.to_s}"
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
50
|
+
end
|
@@ -1,191 +1,239 @@
|
|
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
|
-
|
4
|
-
|
5
|
-
|
6
|
-
DEFAULT_CONFIG = YAML.load_file File.join(__dir__, 'default_configuration.yaml')
|
7
|
-
|
8
|
-
FORMAT_TO_EXT = {
|
9
|
-
'native' => 'hs',
|
10
|
-
'markdown_strict' => 'markdown',
|
11
|
-
'markdown_phpextra' => 'markdown',
|
12
|
-
'markdown_github' => 'markdown',
|
13
|
-
'html5' => 'html',
|
14
|
-
'docx' => 'docx',
|
15
|
-
'latex' => 'tex'
|
16
|
-
}
|
17
|
-
|
18
|
-
class Configuration
|
19
|
-
|
20
|
-
def initialize filename
|
21
|
-
begin
|
22
|
-
path = File.absolute_path filename
|
23
|
-
settings = YAML.load_file path
|
24
|
-
if settings['settings'] and settings['settings']['data-dir'] then
|
25
|
-
data_dir = settings['settings']['data-dir']
|
26
|
-
src_dir = File.dirname filename
|
27
|
-
if data_dir.start_with? '.' then
|
28
|
-
@data_dir = File.absolute_path data_dir, src_dir
|
29
|
-
else
|
30
|
-
@data_dir = data_dir
|
31
|
-
end
|
32
|
-
else
|
33
|
-
@data_dir = File.join Dir.home, '.pandocomatic'
|
34
|
-
end
|
35
|
-
rescue Exception => e
|
36
|
-
raise "Unable to load configuration file #{settings}: #{e.message}"
|
37
|
-
end
|
21
|
+
require 'yaml'
|
22
|
+
require 'paru/pandoc'
|
38
23
|
|
39
|
-
|
40
|
-
@templates = {}
|
41
|
-
@convert_patterns = {}
|
42
|
-
configure settings
|
43
|
-
end
|
24
|
+
DEFAULT_CONFIG = YAML.load_file File.join(__dir__, 'default_configuration.yaml')
|
44
25
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
end
|
26
|
+
FORMAT_TO_EXT = {
|
27
|
+
'native' => 'hs',
|
28
|
+
'markdown_strict' => 'markdown',
|
29
|
+
'markdown_phpextra' => 'markdown',
|
30
|
+
'markdown_github' => 'markdown',
|
31
|
+
'html5' => 'html',
|
32
|
+
'docx' => 'docx',
|
33
|
+
'latex' => 'tex'
|
34
|
+
}
|
55
35
|
|
56
|
-
|
57
|
-
|
58
|
-
if settings.has_key? 'templates' then
|
59
|
-
settings['templates'].each do |name, template|
|
60
|
-
full_template = {
|
61
|
-
'glob' => [],
|
62
|
-
'preprocessors' => [],
|
63
|
-
'pandoc' => {},
|
64
|
-
'postprocessors' => []
|
65
|
-
}
|
66
|
-
|
67
|
-
reset_template name, full_template.merge(template)
|
68
|
-
end
|
69
|
-
end
|
70
|
-
end
|
36
|
+
# Configuration describes a pandocomatic configuration.
|
37
|
+
class Configuration
|
71
38
|
|
72
|
-
|
73
|
-
|
74
|
-
end
|
39
|
+
def initialize options, data_dir, configuration_file
|
40
|
+
@data_dir = data_dir
|
75
41
|
|
76
|
-
|
77
|
-
|
78
|
-
end
|
79
|
-
|
80
|
-
def skip? src
|
81
|
-
if @settings.has_key? 'skip' then
|
82
|
-
@settings['skip'].any? {|glob| File.fnmatch glob, File.basename(src)}
|
83
|
-
else
|
84
|
-
false
|
85
|
-
end
|
86
|
-
end
|
42
|
+
load configuration_file
|
43
|
+
end
|
87
44
|
|
88
|
-
|
89
|
-
|
90
|
-
|
45
|
+
# Read a configuration file and create a pandocomatic configuration object
|
46
|
+
#
|
47
|
+
# @param [String] filename Path to the configuration yaml file
|
48
|
+
# @returns [Configuration] a pandocomatic configuration object
|
49
|
+
def load(filename)
|
50
|
+
begin
|
51
|
+
path = File.absolute_path filename
|
52
|
+
settings = YAML.load_file path
|
53
|
+
if settings['settings'] and settings['settings']['data-dir'] then
|
54
|
+
data_dir = settings['settings']['data-dir']
|
55
|
+
src_dir = File.dirname filename
|
56
|
+
if data_dir.start_with? '.' then
|
57
|
+
@data_dir = File.absolute_path data_dir, src_dir
|
58
|
+
else
|
59
|
+
@data_dir = data_dir
|
60
|
+
end
|
61
|
+
end
|
62
|
+
rescue StandardError => e
|
63
|
+
raise ConfigurationError.new(:unable_to_load_config_file, e, filename)
|
64
|
+
end
|
65
|
+
|
66
|
+
# hidden files will always be skipped, as will pandocomatic
|
67
|
+
# configuration files, unless explicitly set to not skip via the
|
68
|
+
# "unskip" option
|
69
|
+
|
70
|
+
@settings = {'skip' => ['.*', 'pandocomatic.yaml']}
|
71
|
+
|
72
|
+
@templates = {}
|
73
|
+
@convert_patterns = {}
|
74
|
+
|
75
|
+
configure settings
|
76
|
+
end
|
91
77
|
|
92
|
-
|
93
|
-
|
94
|
-
|
78
|
+
# Update this configuration with a configuration file
|
79
|
+
#
|
80
|
+
# @param [String] filename path to the configuration file
|
81
|
+
#
|
82
|
+
# @returns [Configuration] a new configuration
|
83
|
+
def reconfigure(filename)
|
84
|
+
begin
|
85
|
+
settings = YAML.load_file filename
|
86
|
+
new_config = Marshal.load(Marshal.dump(self))
|
87
|
+
new_config.configure settings
|
88
|
+
new_config
|
89
|
+
rescue StandardError => e
|
90
|
+
raise ConfigurationError.new(:unable_to_load_config_file, e, filename)
|
91
|
+
end
|
92
|
+
end
|
95
93
|
|
96
|
-
|
97
|
-
|
98
|
-
|
94
|
+
def configure(settings)
|
95
|
+
reset_settings settings['settings'] if settings.has_key? 'settings'
|
96
|
+
if settings.has_key? 'templates' then
|
97
|
+
settings['templates'].each do |name, template|
|
98
|
+
full_template = {
|
99
|
+
'glob' => [],
|
100
|
+
'preprocessors' => [],
|
101
|
+
'pandoc' => {},
|
102
|
+
'postprocessors' => []
|
103
|
+
}
|
99
104
|
|
100
|
-
|
101
|
-
dir = File.dirname dst
|
102
|
-
ext = File.extname dst
|
103
|
-
basename = File.basename dst, ext
|
104
|
-
File.join dir, "#{basename}.#{find_extension dst}"
|
105
|
+
reset_template name, full_template.merge(template)
|
105
106
|
end
|
107
|
+
end
|
108
|
+
end
|
106
109
|
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
extension = 'html'
|
111
|
-
else
|
112
|
-
to = @templates[template]['pandoc']['to']
|
113
|
-
extension = FORMAT_TO_EXT[to] || to
|
114
|
-
end
|
115
|
-
end
|
110
|
+
def marshal_dump()
|
111
|
+
[@data_dir, @settings, @templates, @convert_patterns]
|
112
|
+
end
|
116
113
|
|
117
|
-
|
118
|
-
|
119
|
-
|
114
|
+
def marshal_load(array)
|
115
|
+
@data_dir, @settings, @templates, @convert_patterns = array
|
116
|
+
end
|
120
117
|
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
end.keys.first
|
125
|
-
end
|
118
|
+
def to_s()
|
119
|
+
marshal_dump
|
120
|
+
end
|
126
121
|
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
# refers to data-dir
|
135
|
-
File.join @data_dir, path
|
136
|
-
end
|
137
|
-
end
|
122
|
+
def skip?(src)
|
123
|
+
if @settings.has_key? 'skip' then
|
124
|
+
@settings['skip'].any? {|glob| File.fnmatch glob, File.basename(src)}
|
125
|
+
else
|
126
|
+
false
|
127
|
+
end
|
128
|
+
end
|
138
129
|
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
130
|
+
def convert?(src)
|
131
|
+
@convert_patterns.values.flatten.any? {|glob| File.fnmatch glob, File.basename(src)}
|
132
|
+
end
|
133
|
+
|
134
|
+
def recursive?()
|
135
|
+
@settings['recursive']
|
136
|
+
end
|
137
|
+
|
138
|
+
def follow_links?()
|
139
|
+
@settings['follow_links']
|
140
|
+
end
|
141
|
+
|
142
|
+
def set_extension(dst)
|
143
|
+
dir = File.dirname dst
|
144
|
+
ext = File.extname dst
|
145
|
+
basename = File.basename dst, ext
|
146
|
+
File.join dir, "#{basename}.#{find_extension dst}"
|
147
|
+
end
|
148
|
+
|
149
|
+
def find_extension(dst)
|
150
|
+
template = determine_template dst
|
151
|
+
if template.nil? then
|
152
|
+
extension = 'html'
|
153
|
+
else
|
154
|
+
# TODO: what if there is no pandoc.to?
|
155
|
+
to = @templates[template]['pandoc']['to']
|
156
|
+
extension = FORMAT_TO_EXT[to] || to
|
157
|
+
end
|
158
|
+
end
|
159
|
+
|
160
|
+
def has_template?(template_name)
|
161
|
+
@templates.has_key? template_name
|
162
|
+
end
|
163
|
+
|
164
|
+
def get_template(template_name)
|
165
|
+
@templates[template_name]
|
166
|
+
end
|
167
|
+
|
168
|
+
def determine_template(src)
|
169
|
+
@convert_patterns.select do |template_name, globs|
|
170
|
+
globs.any? {|glob| File.fnmatch glob, File.basename(src)}
|
171
|
+
end.keys.first
|
172
|
+
end
|
173
|
+
|
174
|
+
def update_path(path, src_dir)
|
175
|
+
if path.start_with? './'
|
176
|
+
# refers to a local (to file) dir
|
177
|
+
File.join src_dir, path
|
178
|
+
elsif path.start_with? '/' then
|
179
|
+
path
|
180
|
+
else
|
181
|
+
# refers to data-dir
|
182
|
+
File.join @data_dir, path
|
183
|
+
end
|
184
|
+
end
|
185
|
+
|
186
|
+
private
|
187
|
+
|
188
|
+
def reset_settings(settings)
|
189
|
+
settings.each do |setting, value|
|
190
|
+
case setting
|
191
|
+
when 'skip'
|
192
|
+
@settings['skip'] = @settings['skip'].concat(value).uniq
|
193
|
+
when 'data-dir'
|
194
|
+
next # skip data-dir setting; is set once in initialization
|
195
|
+
else
|
196
|
+
@settings[setting] = value
|
152
197
|
end
|
198
|
+
end
|
199
|
+
end
|
153
200
|
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
else
|
165
|
-
if template[field] then
|
166
|
-
@templates[name][field] = template[field]
|
167
|
-
end
|
168
|
-
end
|
169
|
-
when 'pandoc'
|
170
|
-
if @templates[name][field] then
|
171
|
-
if template[field] then
|
172
|
-
@templates[name][field].merge! template[field]
|
173
|
-
end
|
174
|
-
else
|
175
|
-
if template[field] then
|
176
|
-
@templates[name][field] = template[field]
|
177
|
-
end
|
178
|
-
end
|
179
|
-
end
|
180
|
-
end
|
201
|
+
def reset_template(name, template)
|
202
|
+
if @templates.has_key? name then
|
203
|
+
fields = ['glob', 'preprocessors', 'pandoc', 'postprocessors']
|
204
|
+
fields.each do |field|
|
205
|
+
case field
|
206
|
+
when 'preprocessors', 'postprocessors', 'glob'
|
207
|
+
if @templates[name][field] then
|
208
|
+
if template[field] then
|
209
|
+
@templates[name][field].concat(template[field]).uniq!
|
210
|
+
end
|
181
211
|
else
|
182
|
-
|
212
|
+
if template[field] then
|
213
|
+
@templates[name][field] = template[field]
|
214
|
+
end
|
183
215
|
end
|
184
|
-
|
185
|
-
|
216
|
+
when 'pandoc'
|
217
|
+
if @templates[name][field] then
|
218
|
+
if template[field] then
|
219
|
+
@templates[name][field].merge! template[field]
|
220
|
+
end
|
221
|
+
else
|
222
|
+
if template[field] then
|
223
|
+
@templates[name][field] = template[field]
|
224
|
+
end
|
186
225
|
end
|
226
|
+
end
|
187
227
|
end
|
228
|
+
else
|
229
|
+
@templates[name] = template
|
230
|
+
end
|
188
231
|
|
232
|
+
if template.has_key? 'glob' then
|
233
|
+
@convert_patterns[name] = template['glob']
|
234
|
+
end
|
189
235
|
end
|
190
236
|
|
237
|
+
end
|
238
|
+
|
191
239
|
end
|
@@ -0,0 +1,49 @@
|
|
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 CLIError < PandocomaticError
|
23
|
+
|
24
|
+
def template()
|
25
|
+
'cli_error.txt'
|
26
|
+
end
|
27
|
+
|
28
|
+
# :no_input_given,
|
29
|
+
# :input_does_not_exist,
|
30
|
+
# :input_is_not_readable,
|
31
|
+
|
32
|
+
# :no_output_given,
|
33
|
+
# :output_is_not_a_directory,
|
34
|
+
# :output_is_not_a_file,
|
35
|
+
# :output_it_not_writable,
|
36
|
+
|
37
|
+
# :unknown_option,
|
38
|
+
# :too_many_options,
|
39
|
+
# :problematic_invocation,
|
40
|
+
|
41
|
+
# :data_dir_does_not_exist,
|
42
|
+
# :data_dir_is_not_a_directory,
|
43
|
+
# :data_dir_is_not_readable,
|
44
|
+
|
45
|
+
# :config_file_does_not_exist,
|
46
|
+
# :config_file_is_not_a_file,
|
47
|
+
# :config_file_is_not_readable
|
48
|
+
end
|
49
|
+
end
|
@@ -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
|
+
require_relative './pandocomatic_error.rb'
|
21
|
+
|
22
|
+
class ConfigurationError < PandocomaticError
|
23
|
+
|
24
|
+
def template()
|
25
|
+
'configuration_error.txt'
|
26
|
+
end
|
27
|
+
|
28
|
+
# :data_dir_does_not_exist,
|
29
|
+
# :data_dir_is_not_a_directory,
|
30
|
+
# :data_dir_is_not_readable,
|
31
|
+
|
32
|
+
# :config_file_does_not_exist,
|
33
|
+
# :config_file_is_not_a_file,
|
34
|
+
# :config_file_is_not_readable,
|
35
|
+
# :unable_to_load_config_file
|
36
|
+
|
37
|
+
# :no_such_template
|
38
|
+
end
|
39
|
+
end
|