pandocomatic 0.2.7.8 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
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 -286
  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 +70 -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
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 91995a26ead8889da6be567516dae8ab7160f373dd7edffbb18e7ab57e92a2b9
4
- data.tar.gz: a995337c74dc70bd6ced86e74c6863ab657ed0e99fd27a9545195541b6b4077b
3
+ metadata.gz: e435d5e708267a647124289aceaede648c297fd6a488c37d8c53e44b7b9c9706
4
+ data.tar.gz: 60fd5761776d2573c80b2694e4cc30956416aad1b5fff62426f14ee3cd7c92fc
5
5
  SHA512:
6
- metadata.gz: 44ce951df58b0ea5f0e88a708bc3f4662e723406df0105b7946c7d96a82a32ccf49feac965338e2afe8296cc60389f8b476d295fad1502e9b4148007399f1910
7
- data.tar.gz: 0dcf32e8b5e2613d0978763a3e0676ace705ca67009451ddde19c8dc0a0c9b1b6389eb9409bb72798ce0571e4b4ed1bc004b44743765d79ce419820e56568208
6
+ metadata.gz: c3dd28212e932b9b62ba012008a972c6b9666624444e689d7aeb64ba961c2849a643f6c644b02a4427e3262bdc6c6e155d1b3698d5927ffc5a0f39bc1dcee2bb
7
+ data.tar.gz: 1cc12f1cceaa6facf2455c6268e8dbda82b80c7580178f6b9f95de8e297207863c5cf953e63c0706113dab45960c9598d28a57d98487dedfd728b9f61814f268
@@ -1,37 +1,38 @@
1
+ # frozen_string_literal: true
2
+
1
3
  #--
2
- # Copyright 2017-2019, 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
22
  require 'optimist'
21
23
 
22
- require_relative './error/cli_error.rb'
23
- require_relative './configuration.rb'
24
+ require_relative './error/cli_error'
25
+ require_relative './configuration'
24
26
 
25
27
  ##
26
28
  # Command line options parser for pandocomatic using optimist.
27
29
  #
28
30
  class CLI
29
-
30
31
  ##
31
32
  # Parse the arguments, returns a triplet with the global options, an
32
33
  # optional subcommand, and the (optional) options for that subcommand.
33
34
  #
34
- # @param args [String, Array] A command line invocation string or a list of strings like ARGV
35
+ # @param args [String, Array] A command-line invocation string or a list of strings like ARGV
35
36
  #
36
37
  # @return [Configuration] The configuration for running pandocomatic given
37
38
  # the command-line options.
@@ -39,39 +40,38 @@ module Pandocomatic
39
40
  args = args.split if args.is_a? String
40
41
 
41
42
  begin
42
- parse_options args || Configuration.new({:help => true, :help_given => true})
43
+ parse_options args || Configuration.new({ help: true, help_given: true })
43
44
  rescue Optimist::CommandlineError => e
44
45
  raise CLIError.new(:problematic_invocation, e, args)
45
46
  end
46
47
  end
47
48
 
48
- private
49
+ # rubocop:disable Metrics
49
50
 
50
51
  # Parse pandocomatic's global options.
51
52
  #
52
53
  # @return [Configuration]
53
- def self.parse_options(args)
54
+ private_class_method def self.parse_options(args)
54
55
  parser = Optimist::Parser.new do
55
- # General options
56
- opt :dry_run, 'Do a dry run', :short => '-y'
57
- opt :quiet, 'Run quietly', :short => '-q'
58
- opt :debug, 'Debug mode, shows pandoc invocations', :short => '-b'
59
- opt :modified_only, 'Modified files only', :short => '-m'
56
+ # General options
57
+ opt :dry_run, 'Do a dry run', short: '-y'
58
+ opt :verbose, 'Run verbosely', short: '-V'
59
+ opt :debug, 'Debug mode, shows pandoc invocations', short: '-b'
60
+ opt :modified_only, 'Modified files only', short: '-m'
60
61
 
61
62
  # Configuration of the converter
62
- opt :data_dir, 'Data dir', :short => '-d', :type => String
63
- opt :config, 'Configuration file', :short => '-c', :type => String
63
+ opt :data_dir, 'Data dir', short: '-d', type: String
64
+ opt :config, 'Configuration file', short: '-c', type: String
65
+ opt :root_path, 'Root path', short: '-r', type: String
64
66
 
65
67
  # What to convert and where to put it
66
- opt :output, 'Output', :short => '-o', :type => String
67
- opt :input, 'Input', :short => '-i', :type => String, :multi => true
68
-
69
- # Experimental
70
- opt :root_path, 'Root path', :short => '-r', :type => String
68
+ opt :output, 'Output', short: '-o', type: String
69
+ opt :input, 'Input', short: '-i', type: String, multi: true
70
+ opt :stdout, 'Output to standard out', short: '-s'
71
71
 
72
72
  # Common
73
- opt :show_version, 'Version', :short => '-v', :long => 'version'
74
- opt :show_help, 'Help', :short => '-h', :long => 'help'
73
+ opt :show_version, 'Version', short: '-v', long: 'version'
74
+ opt :show_help, 'Help', short: '-h', long: 'help'
75
75
  end
76
76
 
77
77
  # All options should be parsed according to the specification given in the parser
@@ -80,55 +80,71 @@ module Pandocomatic
80
80
  rescue Optimist::CommandlineError => e
81
81
  raise CLIError.new(:problematic_invocation, e, args)
82
82
  end
83
-
83
+
84
84
  options = use_custom_version options
85
85
  options = use_custom_help options
86
86
 
87
87
  if options_need_to_be_validated? options
88
88
  # if no input option is specified, all items following the last option
89
89
  # are treated as input files.
90
- if not options[:input_given]
90
+ if !(options[:input_given])
91
91
  options[:input] = args
92
92
  options[:input_given] = true
93
- elsif not args.empty?
94
- raise CLIError.new(:no_mixed_inputs)
93
+ elsif !args.empty?
94
+ raise CLIError, :no_mixed_inputs
95
95
  end
96
96
 
97
97
  # There should be an input specified
98
- raise CLIError.new(:no_input_given) if options[:input].nil? or options[:input].empty?
98
+ raise CLIError, :no_input_given if options[:input].nil? || options[:input].empty?
99
99
 
100
100
  # Support multiple input files for conversion
101
- multiple_inputs = 1 < options[:input].size
101
+ multiple_inputs = options[:input].size > 1
102
102
 
103
103
  # The input files or directories should exist
104
104
  input = options[:input].map do |input_file|
105
105
  raise CLIError.new(:input_does_not_exist, nil, input_file) unless File.exist? input_file
106
106
  raise CLIError.new(:input_is_not_readable, nil, input_file) unless File.readable? input_file
107
-
107
+
108
108
  # If there are multiple input files, these files cannot be directories
109
- raise CLIError.new(:multiple_input_files_only, nil, input_file) if multiple_inputs and File.directory? input_file
110
-
109
+ if multiple_inputs && File.directory?(input_file)
110
+ raise CLIError.new(:multiple_input_files_only, nil,
111
+ input_file)
112
+ end
113
+
111
114
  File.absolute_path input_file
112
115
  end
113
116
 
117
+ # You cannot use the --stdout option while converting directories
118
+ if options[:stdout_given] && File.directory?(input.first)
119
+ options[:stdout] = false
120
+ raise CLIError, :cannot_use_stdout_with_directory
121
+ end
122
+
114
123
  if options[:output_given]
115
- output = File.absolute_path options[:output]
116
- # Input and output should be both files or directories
117
- match_file_types input.first, output
118
-
119
- # The output, if it already exist, should be writable
120
- raise CLIError.new(:output_is_not_writable, nil, output) unless not File.exist? output or File.writable? output
121
- else
122
- # If the input is a directory, an output directory should be
123
- # specified as well. If the input is a file, the output could be
124
- # specified in the input file, or STDOUT could be used.
125
- raise CLIError.new(:no_output_given) if not multiple_inputs and File.directory? input.first
124
+ # You cannot use --stdout with --output
125
+ if options[:stdout_given]
126
+ options[:stdout] = false
127
+ raise CLIError, :cannot_use_both_output_and_stdout
128
+ else
129
+ output = File.absolute_path options[:output]
130
+ # Input and output should be both files or directories
131
+ match_file_types input.first, output
132
+
133
+ # The output, if it already exist, should be writable
134
+ unless (!File.exist? output) || File.writable?(output)
135
+ raise CLIError.new(:output_is_not_writable, nil,
136
+ output)
137
+ end
138
+ end
139
+ elsif !multiple_inputs && File.directory?(input.first)
140
+ raise CLIError, :no_output_given
126
141
  end
142
+ # If the input is a directory, an output directory should be
143
+ # specified as well. If the input is a file, the output could be
144
+ # specified in the input file, or STDOUT could be used.
127
145
 
128
146
  # No check for root_path: a user can supply one that does not exists
129
147
  # at this location and still work on the output location.
130
- if options[:root_path_given]
131
- end
132
148
 
133
149
  # Data dir, if specified, should be an existing and readable directory
134
150
  if options[:data_dir_given]
@@ -148,13 +164,15 @@ module Pandocomatic
148
164
  raise CLIError.new(:config_file_is_not_a_file, nil, config) unless File.file? config
149
165
  end
150
166
 
151
- end
167
+ end
152
168
 
153
169
  Configuration.new options, input
154
170
  end
155
171
 
156
- def self.options_need_to_be_validated? options
157
- not options[:version_given] and not options[:help_given]
172
+ # rubocop:enable Metrics
173
+
174
+ private_class_method def self.options_need_to_be_validated?(options)
175
+ !(options[:version_given]) and !(options[:help_given])
158
176
  end
159
177
 
160
178
  #--
@@ -163,8 +181,8 @@ module Pandocomatic
163
181
  # set, these are put in the options as "version" and "help"
164
182
  # respectively.
165
183
  #++
166
-
167
- def self.use_custom_version options
184
+
185
+ private_class_method def self.use_custom_version(options)
168
186
  if options[:show_version]
169
187
  options.delete :show_version
170
188
  options.delete :show_version_given
@@ -174,29 +192,28 @@ module Pandocomatic
174
192
  options
175
193
  end
176
194
 
177
- def self.use_custom_help options
195
+ private_class_method def self.use_custom_help(options)
178
196
  if options[:show_help]
179
197
  options.delete :show_help
180
198
  options.delete :show_help_given
181
199
  options[:help] = true
182
200
  options[:help_given] = true
183
201
  end
184
- options
202
+ options
185
203
  end
186
204
 
187
205
  # If output does not exist, the output can be
188
206
  # created with the same type. If output does exist, however, it should
189
207
  # have the same type as the input.
190
- def self.matching_file_types?(input, output)
191
- not File.exist?(output) or File.ftype(input) == File.ftype(output)
192
- end
193
-
194
- def self.match_file_types(input, output)
195
- if not matching_file_types? input, output
196
- raise CLIError.new(:output_is_not_a_file, nil, input) if File.file? input
197
- raise CLIError.new(:output_is_not_a_directory, nil, input) if File.directory? input
198
- end
208
+ private_class_method def self.matching_file_types?(input, output)
209
+ !File.exist?(output) or File.ftype(input) == File.ftype(output)
199
210
  end
200
211
 
212
+ private_class_method def self.match_file_types(input, output)
213
+ return if matching_file_types? input, output
214
+
215
+ raise CLIError.new(:output_is_not_a_file, nil, input) if File.file? input
216
+ raise CLIError.new(:output_is_not_a_directory, nil, input) if File.directory? input
217
+ end
201
218
  end
202
219
  end
@@ -1,24 +1,25 @@
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
- require_relative '../printer/command_printer.rb'
22
+ require_relative '../printer/command_printer'
22
23
 
23
24
  # Command is a base class of all actions pandocomatic executes while
24
25
  # converting a file or a directory of files.
@@ -31,18 +32,19 @@ module Pandocomatic
31
32
  # @return [Number] the index of this Command in the list with all commands
32
33
  # to run when running pandocomatic.
33
34
  class Command
34
-
35
35
  attr_reader :errors, :index
36
36
 
37
+ # rubocop:disable Style/ClassVars
38
+
37
39
  @@total = 0
38
40
  @@dry_run = false
39
41
  @@quiet = false
40
42
  @@debug = false
41
- @@src_root = "."
43
+ @@src_root = '.'
42
44
  @@modified_only = false
43
45
 
44
46
  # Create a new Command
45
- def initialize()
47
+ def initialize
46
48
  @errors = []
47
49
  @@total += 1
48
50
  @index = @@total
@@ -63,35 +65,35 @@ module Pandocomatic
63
65
  # Get the root directory of this Command's conversion process
64
66
  #
65
67
  # @return [String]
66
- def src_root()
68
+ def src_root
67
69
  @@src_root
68
70
  end
69
71
 
70
72
  # Does this Command not actually execute?
71
73
  #
72
74
  # @return [Boolean]
73
- def dry_run?()
75
+ def dry_run?
74
76
  @@dry_run
75
77
  end
76
78
 
77
79
  # Is this Command executed silently?
78
80
  #
79
81
  # @return [Boolean]
80
- def quiet?()
82
+ def quiet?
81
83
  @@quiet
82
84
  end
83
85
 
84
86
  # Is this Command executed in debug mode?
85
87
  #
86
88
  # @return [Boolean]
87
- def debug?()
89
+ def debug?
88
90
  @@debug
89
91
  end
90
92
 
91
93
  # Is this Command only executed on modified files?
92
94
  #
93
95
  # @return [Boolean]
94
- def modified_only?()
96
+ def modified_only?
95
97
  @@modified_only
96
98
  end
97
99
 
@@ -99,86 +101,87 @@ module Pandocomatic
99
101
  # commands as well.
100
102
  #
101
103
  # @return [Number]
102
- def count()
104
+ def count
103
105
  1
104
106
  end
105
107
 
106
108
  # Get all the errors generated while executing this Command
107
109
  #
108
110
  # @return [Error[]]
109
- def all_errors()
111
+ def all_errors
110
112
  @errors
111
113
  end
112
114
 
113
115
  # Make this Command run quietly
114
- def make_quiet()
116
+ def make_quiet
115
117
  @@quiet = true
116
118
  end
117
119
 
118
120
  # Convert this Command's index to a string representation
119
121
  #
120
122
  # @return [String]
121
- def index_to_s()
122
- "#{@@total - @index + 1}".rjust(@@total.to_s.size)
123
+ def index_to_s
124
+ (@@total - @index + 1).to_s.rjust(@@total.to_s.size)
123
125
  end
124
126
 
125
127
  # Execute this Command. A Command can be dry-run as well, in which it is
126
128
  # not actually run.
127
- def execute()
129
+ def execute
128
130
  CommandPrinter.new(self).print unless quiet?
129
- run if not dry_run? and runnable?
131
+ run if !dry_run? && runnable?
130
132
  end
131
133
 
132
134
  # Actually run this Command
133
- def run()
134
- end
135
+ def run; end
135
136
 
136
137
  # Are there any errors while configuring this Command? If not, this
137
138
  # Command is runnable.
138
139
  #
139
140
  # @return [Boolean]
140
- def runnable?()
141
- not has_errors?
141
+ def runnable?
142
+ !errors?
142
143
  end
143
144
 
144
145
  # Create a String representation of this Command
145
146
  #
146
147
  # @return [String]
147
- def to_s()
148
+ def to_s
148
149
  'command'
149
150
  end
150
-
151
+
151
152
  # Is this Command converting a directory?
152
153
  #
153
154
  # @return [Boolean] false
154
- def directory?()
155
+ def directory?
155
156
  false
156
157
  end
157
158
 
158
159
  # Does this Command convert a file multiple times?
159
160
  #
160
161
  # @return [Boolean] false
161
- def multiple?()
162
+ def multiple?
162
163
  false
163
164
  end
164
165
 
165
166
  # Will this Command be skipped, thus not executed?
166
167
  #
167
168
  # @return [Boolean] false
168
- def skip?()
169
+ def skip?
169
170
  false
170
171
  end
171
172
 
172
173
  # Decrement the total number of conversion commands by 1
173
- def uncount()
174
+ def uncount
174
175
  @@total -= 1
175
176
  end
176
177
 
178
+ # rubocop:enable Style/ClassVars
179
+
177
180
  # Has this Command run in any errors?
178
181
  #
179
182
  # @return [Error[]]
180
- def has_errors?()
181
- not @errors.empty?
183
+ def errors?
184
+ !@errors.empty?
182
185
  end
183
186
 
184
187
  # Is the source file newer than the destination file?
@@ -188,8 +191,7 @@ module Pandocomatic
188
191
  #
189
192
  # @return [Boolean] True if src has been modified after dst has been last
190
193
  def file_modified?(src, dst)
191
- not File.exist? dst or File.mtime(src) > File.mtime(dst)
194
+ !File.exist? dst or File.mtime(src) > File.mtime(dst)
192
195
  end
193
-
194
196
  end
195
197
  end
@@ -1,32 +1,33 @@
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
22
+ require_relative '../error/io_error'
20
23
 
21
- require_relative '../error/io_error.rb'
22
-
23
- require_relative 'command.rb'
24
- require_relative 'create_link_command.rb'
25
- require_relative 'convert_file_command.rb'
26
- require_relative 'convert_list_command.rb'
27
- require_relative 'convert_file_multiple_command.rb'
28
- require_relative 'copy_file_command.rb'
29
- require_relative 'skip_command.rb'
24
+ require_relative 'command'
25
+ require_relative 'create_link_command'
26
+ require_relative 'convert_file_command'
27
+ require_relative 'convert_list_command'
28
+ require_relative 'convert_file_multiple_command'
29
+ require_relative 'copy_file_command'
30
+ require_relative 'skip_command'
30
31
 
31
32
  # Commmand to convert a directory
32
33
  #
@@ -39,9 +40,10 @@ module Pandocomatic
39
40
  # @!attribute dst_dir
40
41
  # @return [String] the destination directory to convert to
41
42
  class ConvertDirCommand < ConvertListCommand
42
-
43
43
  attr_reader :config, :src_dir, :dst_dir
44
44
 
45
+ # rubocop:disable Metrics
46
+
45
47
  # Create a new ConvertDirCommand
46
48
  #
47
49
  # @param current_config [Configuration] The configuration of pandocomatic
@@ -76,80 +78,76 @@ module Pandocomatic
76
78
 
77
79
  dst = File.join @dst_dir, filename
78
80
 
79
- if File.symlink? src and not config.follow_links?
81
+ if File.symlink?(src) && !config.follow_links?
80
82
  subcommand = CreateLinkCommand.new(src, dst)
81
- elsif File.directory? src then
82
- if config.recursive? then
83
- subcommand = ConvertDirCommand.new(config, src, dst)
84
- else
85
- subcommand = SkipCommand.new(src, :skipping_directory)
86
- end
87
- elsif File.file? src
88
- if config.convert? src then
89
- subcommand = ConvertFileMultipleCommand.new(config, src, dst)
90
- else
91
- if not modified_only? or file_modified? src, dst then
92
- subcommand = CopyFileCommand.new(src, dst)
93
- end
83
+ elsif File.directory? src
84
+ subcommand = if config.recursive?
85
+ ConvertDirCommand.new(config, src, dst)
86
+ else
87
+ SkipCommand.new(src, :skipping_directory)
88
+ end
89
+ elsif File.file? src
90
+ if config.convert? src
91
+ subcommand = ConvertFileMultipleCommand.new(config, src, dst)
92
+ elsif !modified_only? || file_modified?(src, dst)
93
+ subcommand = CopyFileCommand.new(src, dst)
94
94
  end
95
95
  else
96
96
  subcommand = SkipCommand.new(src, :unclear_what_to_do)
97
97
  end
98
98
 
99
- push subcommand unless subcommand.nil? or subcommand.skip?
99
+ push subcommand unless subcommand.nil? || subcommand.skip?
100
100
  end
101
101
 
102
102
  # Empty commands do not count to the total amount of commands to execute
103
103
  uncount if skip?
104
104
  end
105
105
 
106
+ # rubocop:enable Metrics
107
+
106
108
  # Should this command be skipped?
107
109
  #
108
110
  # @return [Boolean] True if this command has no sub commands
109
- def skip?()
111
+ def skip?
110
112
  @subcommands.empty?
111
113
  end
112
114
 
113
115
  # Converts this command a directory?
114
116
  #
115
117
  # @return [Boolean] true
116
- def directory?()
118
+ def directory?
117
119
  true
118
120
  end
119
121
 
120
122
  # Convert this command to a String representation for a Printer
121
123
  #
122
124
  # @return [String]
123
- def to_s()
124
- "convert #{@src_dir}" + '; ' + if create_directory? then 'create and ' else '' end + "enter #{@dst_dir}"
125
+ def to_s
126
+ "convert #{@src_dir}; #{create_directory? ? 'create and ' : ''}enter #{@dst_dir}"
125
127
  end
126
128
 
127
129
  # Run this command
128
- def run()
129
- begin
130
- Dir.mkdir @dst_dir if create_directory?
131
- rescue SystemError => e
132
- raise IOError.new(:error_creating_directory, e, @dst_dir)
133
- end
130
+ def run
131
+ Dir.mkdir @dst_dir if create_directory?
132
+ rescue SystemError => e
133
+ raise IOError.new(:error_creating_directory, e, @dst_dir)
134
134
  end
135
135
 
136
136
  private
137
137
 
138
- def create_directory?()
139
- not File.exist? @dst_dir or not File.directory? @dst_dir
138
+ def create_directory?
139
+ !File.exist? @dst_dir or !File.directory? @dst_dir
140
140
  end
141
141
 
142
142
  # If the source directory contains a configuration file, use it to
143
143
  # reconfigure the converter. Otherwise, use the current configuration
144
144
  def reconfigure(current_config, src_dir)
145
145
  config_file = File.join src_dir, Configuration::CONFIG_FILE
146
- if File.exist? config_file then
147
- config = current_config.reconfigure config_file
146
+ if File.exist? config_file
147
+ current_config.reconfigure config_file
148
148
  else
149
- config = current_config
149
+ current_config
150
150
  end
151
- config
152
151
  end
153
-
154
152
  end
155
153
  end