pandocomatic 0.2.8 → 1.0.0
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/lib/pandocomatic/cli.rb +81 -64
- data/lib/pandocomatic/command/command.rb +37 -35
- data/lib/pandocomatic/command/convert_dir_command.rb +44 -46
- data/lib/pandocomatic/command/convert_file_command.rb +314 -290
- data/lib/pandocomatic/command/convert_file_multiple_command.rb +56 -53
- data/lib/pandocomatic/command/convert_list_command.rb +31 -34
- data/lib/pandocomatic/command/copy_file_command.rb +14 -15
- data/lib/pandocomatic/command/create_link_command.rb +24 -27
- data/lib/pandocomatic/command/skip_command.rb +12 -15
- data/lib/pandocomatic/configuration.rb +682 -867
- data/lib/pandocomatic/default_configuration.yaml +4 -0
- data/lib/pandocomatic/error/cli_error.rb +30 -26
- data/lib/pandocomatic/error/configuration_error.rb +10 -9
- data/lib/pandocomatic/error/io_error.rb +13 -13
- data/lib/pandocomatic/error/pandoc_error.rb +10 -9
- data/lib/pandocomatic/error/pandocomatic_error.rb +15 -14
- data/lib/pandocomatic/error/processor_error.rb +9 -9
- data/lib/pandocomatic/error/template_error.rb +50 -0
- data/lib/pandocomatic/input.rb +53 -54
- data/lib/pandocomatic/multiple_files_input.rb +79 -72
- data/lib/pandocomatic/output.rb +29 -0
- data/lib/pandocomatic/pandoc_metadata.rb +193 -181
- data/lib/pandocomatic/pandocomatic.rb +101 -97
- data/lib/pandocomatic/pandocomatic_yaml.rb +69 -0
- data/lib/pandocomatic/path.rb +171 -0
- data/lib/pandocomatic/printer/command_printer.rb +7 -5
- data/lib/pandocomatic/printer/configuration_errors_printer.rb +7 -6
- data/lib/pandocomatic/printer/error_printer.rb +12 -7
- data/lib/pandocomatic/printer/finish_printer.rb +11 -10
- data/lib/pandocomatic/printer/help_printer.rb +8 -6
- data/lib/pandocomatic/printer/printer.rb +34 -34
- data/lib/pandocomatic/printer/summary_printer.rb +39 -33
- data/lib/pandocomatic/printer/version_printer.rb +8 -8
- data/lib/pandocomatic/printer/views/cli_error.txt +5 -0
- data/lib/pandocomatic/printer/views/configuration_error.txt +2 -1
- data/lib/pandocomatic/printer/views/error.txt +1 -1
- data/lib/pandocomatic/printer/views/finish.txt +1 -1
- data/lib/pandocomatic/printer/views/help.txt +27 -15
- data/lib/pandocomatic/printer/views/summary.txt +7 -1
- data/lib/pandocomatic/printer/views/template_error.txt +1 -0
- data/lib/pandocomatic/printer/views/version.txt +3 -3
- data/lib/pandocomatic/printer/views/warning.txt +1 -1
- data/lib/pandocomatic/printer/warning_printer.rb +21 -19
- data/lib/pandocomatic/processor.rb +28 -28
- data/lib/pandocomatic/processors/fileinfo_preprocessor.rb +35 -30
- data/lib/pandocomatic/processors/metadata_preprocessor.rb +23 -22
- data/lib/pandocomatic/template.rb +244 -0
- data/lib/pandocomatic/warning.rb +24 -25
- metadata +32 -12
@@ -1,28 +1,30 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
#--
|
2
4
|
# Copyright 2017, Huub de Beer <Huub@heerdebeer.org>
|
3
|
-
#
|
5
|
+
#
|
4
6
|
# This file is part of pandocomatic.
|
5
|
-
#
|
7
|
+
#
|
6
8
|
# Pandocomatic is free software: you can redistribute it and/or modify
|
7
9
|
# it under the terms of the GNU General Public License as published by the
|
8
10
|
# Free Software Foundation, either version 3 of the License, or (at your
|
9
11
|
# option) any later version.
|
10
|
-
#
|
12
|
+
#
|
11
13
|
# Pandocomatic is distributed in the hope that it will be useful, but
|
12
14
|
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
13
15
|
# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
14
16
|
# for more details.
|
15
|
-
#
|
17
|
+
#
|
16
18
|
# You should have received a copy of the GNU General Public License along
|
17
19
|
# with pandocomatic. If not, see <http://www.gnu.org/licenses/>.
|
18
20
|
#++
|
19
21
|
module Pandocomatic
|
20
|
-
require_relative './printer
|
22
|
+
require_relative './printer'
|
21
23
|
|
22
24
|
# Printer for pandocomatic's help
|
23
25
|
class HelpPrinter < Printer
|
24
26
|
# Create a new HelpPrinter
|
25
|
-
def initialize
|
27
|
+
def initialize
|
26
28
|
super 'help.txt'
|
27
29
|
end
|
28
30
|
end
|
@@ -1,55 +1,55 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
#--
|
2
4
|
# Copyright 2017, Huub de Beer <Huub@heerdebeer.org>
|
3
|
-
#
|
5
|
+
#
|
4
6
|
# This file is part of pandocomatic.
|
5
|
-
#
|
7
|
+
#
|
6
8
|
# Pandocomatic is free software: you can redistribute it and/or modify
|
7
9
|
# it under the terms of the GNU General Public License as published by the
|
8
10
|
# Free Software Foundation, either version 3 of the License, or (at your
|
9
11
|
# option) any later version.
|
10
|
-
#
|
12
|
+
#
|
11
13
|
# Pandocomatic is distributed in the hope that it will be useful, but
|
12
14
|
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
13
15
|
# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
14
16
|
# for more details.
|
15
|
-
#
|
17
|
+
#
|
16
18
|
# You should have received a copy of the GNU General Public License along
|
17
19
|
# with pandocomatic. If not, see <http://www.gnu.org/licenses/>.
|
18
20
|
#++
|
19
21
|
module Pandocomatic
|
20
|
-
|
21
|
-
|
22
|
-
# Printer base class for printing information from pandocomatic
|
23
|
-
class Printer
|
24
|
-
|
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
|
22
|
+
require 'erb'
|
32
23
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
24
|
+
# Printer base class for printing information from pandocomatic
|
25
|
+
class Printer
|
26
|
+
# Create a new Printer
|
27
|
+
#
|
28
|
+
# @param template_file [String = 'help.txt'] the template to use when
|
29
|
+
# printing.
|
30
|
+
def initialize(template_file = 'help.txt')
|
31
|
+
template template_file
|
32
|
+
end
|
40
33
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
34
|
+
# Set the template used by this Printer
|
35
|
+
#
|
36
|
+
# @param template_file [String] the template to use
|
37
|
+
def template(template_file)
|
38
|
+
dir = File.dirname(__FILE__)
|
39
|
+
@template = File.absolute_path(File.join(dir, 'views', template_file))
|
40
|
+
end
|
48
41
|
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
42
|
+
# Create a string based on this printer's template
|
43
|
+
#
|
44
|
+
# @return [String]
|
45
|
+
def to_s
|
46
|
+
erb = ERB.new(File.read(@template), trim_mode: '>')
|
47
|
+
erb.result(binding)
|
48
|
+
end
|
53
49
|
|
50
|
+
# Print to STDOUT
|
51
|
+
def print
|
52
|
+
puts to_s
|
54
53
|
end
|
54
|
+
end
|
55
55
|
end
|
@@ -1,53 +1,59 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
#--
|
2
|
-
# Copyright 2017, Huub de Beer <Huub@heerdebeer.org>
|
3
|
-
#
|
4
|
+
# Copyright 2017, 2022, Huub de Beer <Huub@heerdebeer.org>
|
5
|
+
#
|
4
6
|
# This file is part of pandocomatic.
|
5
|
-
#
|
7
|
+
#
|
6
8
|
# Pandocomatic is free software: you can redistribute it and/or modify
|
7
9
|
# it under the terms of the GNU General Public License as published by the
|
8
10
|
# Free Software Foundation, either version 3 of the License, or (at your
|
9
11
|
# option) any later version.
|
10
|
-
#
|
12
|
+
#
|
11
13
|
# Pandocomatic is distributed in the hope that it will be useful, but
|
12
14
|
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
13
15
|
# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
14
16
|
# for more details.
|
15
|
-
#
|
17
|
+
#
|
16
18
|
# You should have received a copy of the GNU General Public License along
|
17
19
|
# with pandocomatic. If not, see <http://www.gnu.org/licenses/>.
|
18
20
|
#++
|
19
21
|
module Pandocomatic
|
20
|
-
|
21
|
-
|
22
|
-
# Printer for printing a summary of the conversion process in non-quiet mode
|
23
|
-
class SummaryPrinter < Printer
|
22
|
+
require_relative './printer'
|
24
23
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
24
|
+
# Printer for printing a summary of the conversion process in non-quiet mode
|
25
|
+
class SummaryPrinter < Printer
|
26
|
+
# Create a new SummaryPrinter
|
27
|
+
#
|
28
|
+
# @param command [Command] the command to summarize
|
29
|
+
# @param configuration [Configuration] the configuration of the
|
30
|
+
# pandocomatic invokation
|
31
|
+
def initialize(command, configuration)
|
32
|
+
super 'summary.txt'
|
33
|
+
@command = command
|
34
|
+
@input = configuration.input.to_s
|
35
|
+
@output = if configuration.stdout?
|
36
|
+
nil
|
37
|
+
else
|
38
|
+
configuration.output
|
39
|
+
end
|
36
40
|
|
37
|
-
|
38
|
-
|
39
|
-
# @return [String]
|
40
|
-
def commands()
|
41
|
-
"#{@command.count} command#{'s' if @command.count != 1}"
|
42
|
-
end
|
41
|
+
@config_files = configuration.config_files
|
42
|
+
end
|
43
43
|
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
end
|
44
|
+
# A string representation of the commands being executed
|
45
|
+
#
|
46
|
+
# @return [String]
|
47
|
+
def commands
|
48
|
+
"#{@command.count} command#{'s' if @command.count != 1}"
|
49
|
+
end
|
51
50
|
|
51
|
+
# Is there an output file?
|
52
|
+
#
|
53
|
+
# @return [Boolean] True if there is an output defined in this
|
54
|
+
# SummaryPrinter, false otherwise
|
55
|
+
def output?
|
56
|
+
!@output.nil? and !@output.empty?
|
52
57
|
end
|
58
|
+
end
|
53
59
|
end
|
@@ -1,32 +1,32 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
#--
|
2
4
|
# Copyright 2017, Huub de Beer <Huub@heerdebeer.org>
|
3
|
-
#
|
5
|
+
#
|
4
6
|
# This file is part of pandocomatic.
|
5
|
-
#
|
7
|
+
#
|
6
8
|
# Pandocomatic is free software: you can redistribute it and/or modify
|
7
9
|
# it under the terms of the GNU General Public License as published by the
|
8
10
|
# Free Software Foundation, either version 3 of the License, or (at your
|
9
11
|
# option) any later version.
|
10
|
-
#
|
12
|
+
#
|
11
13
|
# Pandocomatic is distributed in the hope that it will be useful, but
|
12
14
|
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
13
15
|
# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
14
16
|
# for more details.
|
15
|
-
#
|
17
|
+
#
|
16
18
|
# You should have received a copy of the GNU General Public License along
|
17
19
|
# with pandocomatic. If not, see <http://www.gnu.org/licenses/>.
|
18
20
|
#++
|
19
21
|
module Pandocomatic
|
20
|
-
require_relative './printer
|
22
|
+
require_relative './printer'
|
21
23
|
|
22
24
|
# Printer to print pandocomatic's version
|
23
25
|
class VersionPrinter < Printer
|
24
|
-
|
25
26
|
# Create a new VersionPrinter
|
26
|
-
def initialize
|
27
|
+
def initialize(version)
|
27
28
|
super 'version.txt'
|
28
29
|
@version = version
|
29
30
|
end
|
30
|
-
|
31
31
|
end
|
32
32
|
end
|
@@ -12,6 +12,11 @@ See `pandocomatic --help` which options are allowed.
|
|
12
12
|
<%= @error.data.join(" ") %>.
|
13
13
|
<% when :problematic_invocation %>
|
14
14
|
<%=@error.error.message%>.
|
15
|
+
<% when :cannot_use_stdout_with_directory %>
|
16
|
+
Using `--stdout/-s` with an input directory is not allowed.
|
17
|
+
<% when :cannot_use_both_output_and_stdout %>
|
18
|
+
Using both `--output/-o` and `--stdout/-s` is not allowed.
|
19
|
+
Use eiter a specific output file or directory, or standard out, not both.
|
15
20
|
<% else %>
|
16
21
|
'<%= @error.data %>'.
|
17
22
|
<% end %>
|
@@ -1 +1,2 @@
|
|
1
|
-
<%=@error.message%>: '<%= @error.data %>'.
|
1
|
+
<%=@error.message%>: '<%= @error.data %>'.<% if @error.error? %> <%=
|
2
|
+
@error.error.to_s %><% end %>
|
@@ -1 +1 @@
|
|
1
|
-
Pandocomatic needed <%=duration%> to convert '<%= @input %>'<%if
|
1
|
+
Pandocomatic needed <%=duration%> to convert '<%= @input %>'<%if output?%> to '<%= @output %>'<%end%>.
|
@@ -11,17 +11,20 @@ DESCRIPTION
|
|
11
11
|
tree. Configure the conversion process through configuration files. Each
|
12
12
|
input file that is converted by pandocomatic is processed as follows:
|
13
13
|
|
14
|
+
setup(0) ... setup(K)
|
14
15
|
input_file ->
|
15
16
|
preprocessor(0) -> ... -> preprocessor(N) ->
|
16
17
|
pandoc ->
|
17
18
|
postprocessor(0) -> ... -> postprocessor(M) ->
|
18
19
|
output_file
|
20
|
+
cleanup(0) ... cleanup(L)
|
19
21
|
|
20
|
-
The
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
22
|
+
The setup and cleanup scripts are run before and after the conversion
|
23
|
+
process, respectively. The preprocessors and postprocessors used in the
|
24
|
+
conversion process are configured in pandocomatic templates. Besides
|
25
|
+
processors, you can also specify pandoc options to use to convert the input
|
26
|
+
file. These templates are specified in a configuration file. Templates can
|
27
|
+
be used over and over, thus automating the use of pandoc.
|
25
28
|
|
26
29
|
OPTIONS
|
27
30
|
|
@@ -36,12 +39,18 @@ OPTIONS
|
|
36
39
|
are specified on the command-line. Pandocomatic treats
|
37
40
|
the concatenated files as a single input file.
|
38
41
|
|
39
|
-
-o PATH, --output PATH
|
40
|
-
Create converted files and directories in PATH.
|
41
|
-
|
42
42
|
|
43
43
|
Optional:
|
44
44
|
|
45
|
+
-o PATH, --output PATH
|
46
|
+
Create converted files and directories in PATH. Cannot be
|
47
|
+
used together with the `--stdout` option.
|
48
|
+
|
49
|
+
-s, --stdout
|
50
|
+
Write the converted files to STDOUT. Cannot be used when
|
51
|
+
converting directories, nor in combination with the
|
52
|
+
`--output` option.
|
53
|
+
|
45
54
|
-d PATH, --data-dir PATH
|
46
55
|
Configure pandocomatic to use PATH as its data directory.
|
47
56
|
Default is PANDOC's data dir. (See `pandoc --version` to
|
@@ -95,14 +104,17 @@ OPTIONS
|
|
95
104
|
destination files will be converted, copied, or linked.
|
96
105
|
Default is FALSE.
|
97
106
|
|
98
|
-
-
|
107
|
+
-V, --verbose Run pandocomatic verbosely. Default is FALSE. Pandocomatic
|
108
|
+
runs quietly unless the verbose, debug, or dry-run options
|
109
|
+
are given.
|
99
110
|
|
100
111
|
-b, --debug Run pandocomatic in debug mode: show the pandoc invocations
|
101
|
-
before each conversion. Default is FALSE.
|
102
|
-
|
112
|
+
before each conversion. Default is FALSE. In debug mode,
|
113
|
+
pandocomatic runs verbosely.
|
103
114
|
|
104
115
|
-y, --dry-run Configure pandocomatic to run the conversion process, but do
|
105
|
-
not actually run it. Default is FALSE.
|
116
|
+
not actually run it. Default is FALSE. When using this
|
117
|
+
dry-run option, pandocomatic runs verbosely.
|
106
118
|
|
107
119
|
|
108
120
|
Experimental:
|
@@ -135,7 +147,7 @@ EXAMPLE:
|
|
135
147
|
|
136
148
|
SEE ALSO
|
137
149
|
|
138
|
-
- Pandocomatic's
|
150
|
+
- Pandocomatic's manual
|
139
151
|
https://heerdebeer.org/Software/markdown/pandocomatic/
|
140
152
|
|
141
153
|
- Pandoc's user guide
|
@@ -146,11 +158,11 @@ SEE ALSO
|
|
146
158
|
|
147
159
|
AUTHOR
|
148
160
|
|
149
|
-
Huub de Beer <
|
161
|
+
Huub de Beer <huub@heerdebeer.org>
|
150
162
|
|
151
163
|
LICENSE
|
152
164
|
|
153
|
-
Copyright 2014—
|
165
|
+
Copyright 2014—2021 Huub de Beer <huub@heerdebeer.org>
|
154
166
|
|
155
167
|
Pandocomatic is free software: you can redistribute it and/or modify
|
156
168
|
it under the terms of the GNU General Public License as published by the
|
@@ -1 +1,7 @@
|
|
1
|
-
|
1
|
+
Using configuration hierarchy:
|
2
|
+
<% @config_files.each do |file| %>
|
3
|
+
- <%= file %>
|
4
|
+
|
5
|
+
<% end %>
|
6
|
+
|
7
|
+
<% if @command.count <= 0 then%>Nothing to do<% else %><%= commands %> to execute to convert '<%= @input %>'<%if output?%> to '<%= @output %>'<%end%><% end %>.
|
@@ -0,0 +1 @@
|
|
1
|
+
<%=@error.message%>
|
@@ -1,8 +1,8 @@
|
|
1
1
|
Pandocomatic version <%=@version.join('.')%>
|
2
2
|
|
3
|
-
© 2014—
|
3
|
+
© 2014—2021 Huub de Beer <huub@heerdebeer.org>
|
4
4
|
|
5
5
|
Pandocomatic is free software; pandocomatic is released under the GPLv3.
|
6
6
|
|
7
|
-
For more information about pandocomatic run 'pandocomatic --help' or read
|
8
|
-
|
7
|
+
For more information about pandocomatic run 'pandocomatic --help' or read
|
8
|
+
pandocomatic's manual at https://heerdebeer.org/Software/markdown/pandocomatic/.
|
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
[WARNING] <%=@warning.message.to_s%>: <%=@warning.src%>
|
@@ -1,38 +1,40 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
#--
|
2
4
|
# Copyright 2017, Huub de Beer <Huub@heerdebeer.org>
|
3
|
-
#
|
5
|
+
#
|
4
6
|
# This file is part of pandocomatic.
|
5
|
-
#
|
7
|
+
#
|
6
8
|
# Pandocomatic is free software: you can redistribute it and/or modify
|
7
9
|
# it under the terms of the GNU General Public License as published by the
|
8
10
|
# Free Software Foundation, either version 3 of the License, or (at your
|
9
11
|
# option) any later version.
|
10
|
-
#
|
12
|
+
#
|
11
13
|
# Pandocomatic is distributed in the hope that it will be useful, but
|
12
14
|
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
13
15
|
# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
14
16
|
# for more details.
|
15
|
-
#
|
17
|
+
#
|
16
18
|
# You should have received a copy of the GNU General Public License along
|
17
19
|
# with pandocomatic. If not, see <http://www.gnu.org/licenses/>.
|
18
20
|
#++
|
19
21
|
module Pandocomatic
|
20
|
-
|
22
|
+
require_relative './printer'
|
21
23
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
24
|
+
# Printer for warnings
|
25
|
+
class WarningPrinter < Printer
|
26
|
+
# Create a new WarningPrinter
|
27
|
+
#
|
28
|
+
# @param warning [Warning] the warning to print
|
29
|
+
def initialize(warning)
|
30
|
+
template = 'warning.txt'
|
31
|
+
super template
|
32
|
+
@warning = warning
|
33
|
+
end
|
32
34
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
end
|
35
|
+
# Print warnings to STDERR rather than STDOUT
|
36
|
+
def print
|
37
|
+
warn to_s
|
37
38
|
end
|
39
|
+
end
|
38
40
|
end
|
@@ -1,49 +1,49 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
#--
|
2
4
|
# Copyright 2014, 2015, 2016, 2017, Huub de Beer <Huub@heerdebeer.org>
|
3
|
-
#
|
5
|
+
#
|
4
6
|
# This file is part of pandocomatic.
|
5
|
-
#
|
7
|
+
#
|
6
8
|
# Pandocomatic is free software: you can redistribute it and/or modify
|
7
9
|
# it under the terms of the GNU General Public License as published by the
|
8
10
|
# Free Software Foundation, either version 3 of the License, or (at your
|
9
11
|
# option) any later version.
|
10
|
-
#
|
12
|
+
#
|
11
13
|
# Pandocomatic is distributed in the hope that it will be useful, but
|
12
14
|
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
13
15
|
# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
14
16
|
# for more details.
|
15
|
-
#
|
17
|
+
#
|
16
18
|
# You should have received a copy of the GNU General Public License along
|
17
19
|
# with pandocomatic. If not, see <http://www.gnu.org/licenses/>.
|
18
20
|
#++
|
19
21
|
module Pandocomatic
|
20
|
-
|
21
|
-
|
22
|
+
require 'open3'
|
23
|
+
require_relative 'error/processor_error'
|
22
24
|
|
23
|
-
|
24
|
-
|
25
|
+
# Generic class for processors used to preprocess, postproces, setup, and
|
26
|
+
# cleanup with external scripts or programs during the conversion process.
|
27
|
+
#
|
28
|
+
# For preprocessors and postprocessors it is assumed that the input is the
|
29
|
+
# contents of the file to convert and the output the processed input. In
|
30
|
+
# the end, the output will be put through pandoc.
|
31
|
+
class Processor
|
32
|
+
# Run script on input and return captured output
|
25
33
|
#
|
26
|
-
#
|
27
|
-
#
|
28
|
-
#
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
# @param script [String] path to script to run
|
34
|
-
# @param input [String] input to process in the script
|
35
|
-
#
|
36
|
-
# @return [String] output of script.
|
37
|
-
def self.run script, input
|
38
|
-
output, error, status = Open3.capture3(script, :stdin_data => input)
|
39
|
-
warn error unless error.empty?
|
40
|
-
|
41
|
-
if status.exitstatus > 0
|
42
|
-
raise ProcessorError.new(:error_processing_script, StandardError.new(error), [script, input])
|
43
|
-
end
|
34
|
+
# @param script [String] path to script to run
|
35
|
+
# @param input [String] input to process in the script
|
36
|
+
#
|
37
|
+
# @return [String] output of script.
|
38
|
+
def self.run(script, input)
|
39
|
+
output, error, status = Open3.capture3(script, stdin_data: input)
|
40
|
+
warn error unless error.empty?
|
44
41
|
|
45
|
-
|
46
|
-
|
42
|
+
if status.exitstatus.positive?
|
43
|
+
raise ProcessorError.new(:error_processing_script, StandardError.new(error), [script, input])
|
44
|
+
end
|
47
45
|
|
46
|
+
output
|
48
47
|
end
|
48
|
+
end
|
49
49
|
end
|
@@ -1,50 +1,55 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
#--
|
2
4
|
# Copyright 2014, 2015, 2016, 2017, Huub de Beer <Huub@heerdebeer.org>
|
3
|
-
#
|
5
|
+
#
|
4
6
|
# This file is part of pandocomatic.
|
5
|
-
#
|
7
|
+
#
|
6
8
|
# Pandocomatic is free software: you can redistribute it and/or modify
|
7
9
|
# it under the terms of the GNU General Public License as published by the
|
8
10
|
# Free Software Foundation, either version 3 of the License, or (at your
|
9
11
|
# option) any later version.
|
10
|
-
#
|
12
|
+
#
|
11
13
|
# Pandocomatic is distributed in the hope that it will be useful, but
|
12
14
|
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
13
15
|
# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
14
16
|
# for more details.
|
15
|
-
#
|
17
|
+
#
|
16
18
|
# You should have received a copy of the GNU General Public License along
|
17
19
|
# with pandocomatic. If not, see <http://www.gnu.org/licenses/>.
|
18
20
|
#++
|
19
21
|
module Pandocomatic
|
22
|
+
require_relative '../processor'
|
20
23
|
|
21
|
-
|
24
|
+
# FileInfoPreprocessor collects information about a file to be converted and
|
25
|
+
# mixes that information into that file's metadata. It is a default
|
26
|
+
# preprocessor.
|
27
|
+
#
|
28
|
+
class FileInfoPreprocessor < Processor
|
29
|
+
# rubocop:disable Metrics/AbcSize
|
22
30
|
|
23
|
-
#
|
24
|
-
# mixes that information into that file's metadata. It is a default
|
25
|
-
# preprocessor.
|
31
|
+
# Run this FileInfoPreprocessor
|
26
32
|
#
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
output << " created: #{created_at.strftime '%Y-%m-%d'}\n"
|
46
|
-
output << " modified: #{modified_at.strftime '%Y-%m-%d'}\n"
|
47
|
-
output << "...\n\n"
|
48
|
-
end
|
33
|
+
# @param input [String] the contents of the document being preprocessed
|
34
|
+
# @param path [String] the path to the input document
|
35
|
+
# @param options [Hash] pandoc options collected by pandocomatic to run on
|
36
|
+
# this file
|
37
|
+
def self.run(input, path, src_path, options)
|
38
|
+
created_at = File.stat(path).ctime
|
39
|
+
modified_at = File.stat(path).mtime
|
40
|
+
output = input
|
41
|
+
output << "\n\n---\n"
|
42
|
+
output << "pandocomatic-fileinfo:\n"
|
43
|
+
output << " from: #{options['from']}\n" if options.key? 'from'
|
44
|
+
output << " to: #{options['to']}\n" if options.key? 'to'
|
45
|
+
output << " template: #{options['template']}\n" if options.key? 'template'
|
46
|
+
output << " path: '#{path}'\n"
|
47
|
+
output << " src_path: '#{src_path}'\n"
|
48
|
+
output << " created: #{created_at.strftime '%Y-%m-%d'}\n"
|
49
|
+
output << " modified: #{modified_at.strftime '%Y-%m-%d'}\n"
|
50
|
+
output << "...\n\n"
|
49
51
|
end
|
52
|
+
|
53
|
+
# rubocop:enable Metrics/AbcSize
|
54
|
+
end
|
50
55
|
end
|