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.
Files changed (50) hide show
  1. checksums.yaml +4 -4
  2. data/lib/pandocomatic/cli.rb +81 -64
  3. data/lib/pandocomatic/command/command.rb +37 -35
  4. data/lib/pandocomatic/command/convert_dir_command.rb +44 -46
  5. data/lib/pandocomatic/command/convert_file_command.rb +314 -290
  6. data/lib/pandocomatic/command/convert_file_multiple_command.rb +56 -53
  7. data/lib/pandocomatic/command/convert_list_command.rb +31 -34
  8. data/lib/pandocomatic/command/copy_file_command.rb +14 -15
  9. data/lib/pandocomatic/command/create_link_command.rb +24 -27
  10. data/lib/pandocomatic/command/skip_command.rb +12 -15
  11. data/lib/pandocomatic/configuration.rb +682 -867
  12. data/lib/pandocomatic/default_configuration.yaml +4 -0
  13. data/lib/pandocomatic/error/cli_error.rb +30 -26
  14. data/lib/pandocomatic/error/configuration_error.rb +10 -9
  15. data/lib/pandocomatic/error/io_error.rb +13 -13
  16. data/lib/pandocomatic/error/pandoc_error.rb +10 -9
  17. data/lib/pandocomatic/error/pandocomatic_error.rb +15 -14
  18. data/lib/pandocomatic/error/processor_error.rb +9 -9
  19. data/lib/pandocomatic/error/template_error.rb +50 -0
  20. data/lib/pandocomatic/input.rb +53 -54
  21. data/lib/pandocomatic/multiple_files_input.rb +79 -72
  22. data/lib/pandocomatic/output.rb +29 -0
  23. data/lib/pandocomatic/pandoc_metadata.rb +193 -181
  24. data/lib/pandocomatic/pandocomatic.rb +101 -97
  25. data/lib/pandocomatic/pandocomatic_yaml.rb +69 -0
  26. data/lib/pandocomatic/path.rb +171 -0
  27. data/lib/pandocomatic/printer/command_printer.rb +7 -5
  28. data/lib/pandocomatic/printer/configuration_errors_printer.rb +7 -6
  29. data/lib/pandocomatic/printer/error_printer.rb +12 -7
  30. data/lib/pandocomatic/printer/finish_printer.rb +11 -10
  31. data/lib/pandocomatic/printer/help_printer.rb +8 -6
  32. data/lib/pandocomatic/printer/printer.rb +34 -34
  33. data/lib/pandocomatic/printer/summary_printer.rb +39 -33
  34. data/lib/pandocomatic/printer/version_printer.rb +8 -8
  35. data/lib/pandocomatic/printer/views/cli_error.txt +5 -0
  36. data/lib/pandocomatic/printer/views/configuration_error.txt +2 -1
  37. data/lib/pandocomatic/printer/views/error.txt +1 -1
  38. data/lib/pandocomatic/printer/views/finish.txt +1 -1
  39. data/lib/pandocomatic/printer/views/help.txt +27 -15
  40. data/lib/pandocomatic/printer/views/summary.txt +7 -1
  41. data/lib/pandocomatic/printer/views/template_error.txt +1 -0
  42. data/lib/pandocomatic/printer/views/version.txt +3 -3
  43. data/lib/pandocomatic/printer/views/warning.txt +1 -1
  44. data/lib/pandocomatic/printer/warning_printer.rb +21 -19
  45. data/lib/pandocomatic/processor.rb +28 -28
  46. data/lib/pandocomatic/processors/fileinfo_preprocessor.rb +35 -30
  47. data/lib/pandocomatic/processors/metadata_preprocessor.rb +23 -22
  48. data/lib/pandocomatic/template.rb +244 -0
  49. data/lib/pandocomatic/warning.rb +24 -25
  50. 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.rb'
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
- require 'erb'
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
- # 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
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
- # Create a string based on this printer's template
42
- #
43
- # @return [String]
44
- def to_s()
45
- erb = ERB.new(File.read(@template), trim_mode: '>')
46
- erb.result(binding())
47
- end
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
- # Print to STDOUT
50
- def print()
51
- puts to_s()
52
- end
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
- require_relative './printer.rb'
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
- # Create a new SummaryPrinter
26
- #
27
- # @param command [Command] the command to summarize
28
- # @param configuration [Configuration] the configuration of the
29
- # pandocomatic invokation
30
- def initialize(command, configuration)
31
- super 'summary.txt'
32
- @command = command
33
- @input = configuration.input.to_s
34
- @output = configuration.output
35
- end
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
- # 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
41
+ @config_files = configuration.config_files
42
+ end
43
43
 
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
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.rb'
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 version
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,4 +1,4 @@
1
- Pandocomatic has encountered an error:
1
+ [ERROR] Pandocomatic encountered the following error(s):
2
2
 
3
3
  <%= @error.message %>
4
4
  <%= @error.data %>
@@ -1 +1 @@
1
- Pandocomatic needed <%=duration%> to convert '<%= @input %>'<%if has_output?%> to '<%= @output %>'<%end%>.
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 preprocessors and postprocessors used in the conversion process are
21
- configured in pandocomatic templates. Besides processors, you can also
22
- specify pandoc options to use to convert the input file. These templates are
23
- specified in a configuration file. Templates can be used over and over, thus
24
- automating the use of pandoc.
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
- -q, --quiet Run pandocomatic quietly. Default is FALSE.
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. Only works
102
- when not quiet.
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 documentation
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 <Huub@heerdebeer.org>
161
+ Huub de Beer <huub@heerdebeer.org>
150
162
 
151
163
  LICENSE
152
164
 
153
- Copyright 2014—2020 Huub de Beer <huub@heerdebeer.org>
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
- <% if @command.count <= 0 then%>Nothing to do<% else %><%= commands %> to execute to convert '<%= @input %>'<%if has_output?%> to '<%= @output %>'<%end%><% end %>.
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—2020 Huub de Beer <Huub@heerdebeer.org>
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 its
8
- documentation at https://heerdebeer.org/Software/markdown/pandocomatic/.
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
- Warning. <%=@warning.message.to_s%>: <%=@warning.src%>
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
- require_relative './printer.rb'
22
+ require_relative './printer'
21
23
 
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
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
- # Print warnings to STDERR rather than STDOUT
34
- def print
35
- warn to_s
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
- require 'open3'
21
- require_relative 'error/processor_error.rb'
22
+ require 'open3'
23
+ require_relative 'error/processor_error'
22
24
 
23
- # Generic class for processors used to preprocess, postproces, setup, and
24
- # cleanup with external scripts or programs during the conversion process.
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
- # For preprocessors and postprocessors it is assumed that the input is the
27
- # contents of the file to convert and the output the processed input. In
28
- # the end, the output will be put through pandoc.
29
- class Processor
30
-
31
- # Run script on input and return captured output
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
- output
46
- end
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
- require_relative '../processor.rb'
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
- # 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.
31
+ # Run this FileInfoPreprocessor
26
32
  #
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, src_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 << " src_path: '#{src_path}'\n"
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