class Pandocomatic::ConvertFileMultipleCommand

Create a command to convert one file multiple times

@!attribute subcommands

@return [Command[]] the subcommands to execute when running this
ConvertFileMultipleCommand

Attributes

subcommands[R]

Public Class Methods

new(config, src, dst) click to toggle source

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

Calls superclass method
# File lib/pandocomatic/command/convert_file_multiple_command.rb, line 47
def initialize(config, src, dst)
  super()
  @config = config
  @src = src

  metadata = @config.get_metadata @src

  subcommands = []

  if metadata&.template?
    # There are templates in this document's metadata, try to use
    # those.
    metadata.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

Public Instance Methods

execute() click to toggle source

Execute this ConvertFileMultipleCommand

# File lib/pandocomatic/command/convert_file_multiple_command.rb, line 99
def execute
  return if @subcommands.empty?

  description = CommandPrinter.new(self)
  Pandocomatic::LOG.info description
  description.print unless quiet? || (@subcommands.size == 1)
  run if !dry_run? && runnable?

  @subcommands.each(&:execute)
end
to_s() click to toggle source

A string representation of this command

@return [String]

# 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