Class: Pandocomatic::ConvertFileMultipleCommand
- Inherits:
-
ConvertListCommand
- Object
- Command
- ConvertListCommand
- Pandocomatic::ConvertFileMultipleCommand
- Defined in:
- lib/pandocomatic/command/convert_file_multiple_command.rb
Overview
Create a command to convert one file multiple times
Instance Attribute Summary collapse
-
#subcommands ⇒ Command[]
ConvertFileMultipleCommand.
Attributes inherited from Command
Instance Method Summary collapse
-
#execute ⇒ Object
Execute this ConvertFileMultipleCommand.
-
#initialize(config, src, dst) ⇒ ConvertFileMultipleCommand
constructor
Create a new ConvertFileMultipleCommand.
-
#to_s ⇒ String
A string representation of this command.
Methods inherited from ConvertListCommand
#all_errors, #count, #multiple?, #push, #skip?
Methods inherited from Command
#all_errors, #count, #debug?, #directory?, #dry_run?, #errors?, #file_modified?, #index_to_s, #make_quiet, #modified_only?, #multiple?, #quiet?, reset, #run, #runnable?, #skip?, #src_root, #uncount
Constructor Details
#initialize(config, src, dst) ⇒ ConvertFileMultipleCommand
Create a new ConvertFileMultipleCommand
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/pandocomatic/command/convert_file_multiple_command.rb', line 47 def initialize(config, src, dst) super() @config = config @src = src = PandocMetadata.load_file @src subcommands = [] if .template? # There are templates in this document's metadata, try to use # those. .templates.each do |template_name| unless template_name.empty? || config.template?(template_name) raise ConfigurationError.new(:no_such_template, nil, template_name) end subcommands.push ConvertFileCommand.new(@config, @src, dst, template_name) end else # Try to match any global templates using the glob patterns global_templates = @config.determine_templates(@src) if global_templates.empty? subcommands.push ConvertFileCommand.new(@config, @src, dst) else global_templates.each do |template_name| subcommands.push ConvertFileCommand.new(@config, @src, dst, template_name) end end end # Only run a command if the src file is modified, or if the modified # setting is ignored. subcommands.each do |subcommand| if (!modified_only? || file_modified?(@src, subcommand.dst)) && !(subcommand.nil? || subcommand.skip?) push subcommand end end end |
Instance Attribute Details
#subcommands ⇒ Command[]
ConvertFileMultipleCommand
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/pandocomatic/command/convert_file_multiple_command.rb', line 36 class ConvertFileMultipleCommand < ConvertListCommand attr_reader :subcommands # rubocop:disable Metrics # Create a new ConvertFileMultipleCommand # # @param config [Configuration] Pandocomatic's configuration used to # convert the source file # @param src [String] the file to convert # @param dst [String] the output file def initialize(config, src, dst) super() @config = config @src = src = PandocMetadata.load_file @src subcommands = [] if .template? # There are templates in this document's metadata, try to use # those. .templates.each do |template_name| unless template_name.empty? || config.template?(template_name) raise ConfigurationError.new(:no_such_template, nil, template_name) end subcommands.push ConvertFileCommand.new(@config, @src, dst, template_name) end else # Try to match any global templates using the glob patterns global_templates = @config.determine_templates(@src) if global_templates.empty? subcommands.push ConvertFileCommand.new(@config, @src, dst) else global_templates.each do |template_name| subcommands.push ConvertFileCommand.new(@config, @src, dst, template_name) end end end # Only run a command if the src file is modified, or if the modified # setting is ignored. subcommands.each do |subcommand| if (!modified_only? || file_modified?(@src, subcommand.dst)) && !(subcommand.nil? || subcommand.skip?) push subcommand end end end # rubocop:enable Metrics # A string representation of this command # # @return [String] def to_s "converting #{@src} #{@subcommands.size} time#{'s' if @subcommands.size != 1}:" end # Execute this ConvertFileMultipleCommand def execute return if @subcommands.empty? CommandPrinter.new(self).print unless quiet? || (@subcommands.size == 1) run if !dry_run? && runnable? @subcommands.each(&:execute) end end |
Instance Method Details
#execute ⇒ Object
Execute this ConvertFileMultipleCommand
99 100 101 102 103 104 105 106 |
# File 'lib/pandocomatic/command/convert_file_multiple_command.rb', line 99 def execute return if @subcommands.empty? CommandPrinter.new(self).print unless quiet? || (@subcommands.size == 1) run if !dry_run? && runnable? @subcommands.each(&:execute) end |
#to_s ⇒ String
A string representation of this command
94 95 96 |
# File 'lib/pandocomatic/command/convert_file_multiple_command.rb', line 94 def to_s "converting #{@src} #{@subcommands.size} time#{'s' if @subcommands.size != 1}:" end |