Class: MakePDF::CommandBased::Writer
- Includes:
- Arguments
- Defined in:
- lib/make_pdf/command_based.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#command ⇒ Object
readonly
Returns the value of attribute command.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Attributes included from Arguments
Attributes inherited from PDFWriter
#logger, #output_dir, #source_url
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(command: COMMAND, **options) ⇒ Writer
constructor
A new instance of Writer.
- #output_for(file, output_base_path: ".", version: [], **options) ⇒ Object
- #write(source_url, output_filename, **options) ⇒ Object
Methods included from Arguments
Methods inherited from PDFWriter
#make_output_filename, #make_pdf_filename, #make_relative_file, #make_source_url, #process
Methods included from PathManip
Constructor Details
#initialize(command: COMMAND, **options) ⇒ Writer
Returns a new instance of Writer.
30 31 32 33 |
# File 'lib/make_pdf/command_based.rb', line 30 def initialize(command: COMMAND, **) super(**) @command = command end |
Instance Attribute Details
#command ⇒ Object (readonly)
Returns the value of attribute command.
23 24 25 |
# File 'lib/make_pdf/command_based.rb', line 23 def command @command end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
23 24 25 |
# File 'lib/make_pdf/command_based.rb', line 23 def @options end |
Class Method Details
.prefix ⇒ Object
26 27 28 |
# File 'lib/make_pdf/command_based.rb', line 26 def self.prefix '--' end |
Instance Method Details
#output_for(file, output_base_path: ".", version: [], **options) ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/make_pdf/command_based.rb', line 52 def output_for(file, output_base_path: ".", version: [], **) output_base_path = Pathname.new(output_base_path) file = Pathname.new(file) if @output_dir.nil? path = output_base_path / file.dirname else path = File.(relative_path(file, output_base_path), @output_dir) end FileUtils.mkdir_p path suffix = if version.empty? then "" else "_#{version.join("_")}" end File.(File.basename(file, ".html") + "#{suffix}.pdf", path) end |
#write(source_url, output_filename, **options) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/make_pdf/command_based.rb', line 35 def write(source_url, output_filename, **) logger.info("converting #{source_url} with #{@command}") arguments = make_arguments( command: @command, source_url:, output_filename:, ** ) logger.debug("Executing #{@command} #{arguments}") std_out = IO.popen([@command] + arguments, {:err =>[ :child, :out]}) do |pipe| pipe.read end status = $? raise RuntimeError.new("Failure executing #{command} with #{arguments}.\n\noutput:\n\n---\n#{std_out}\n---\n") if status != 0 logger.info("pdf-writer: Wrote #{output_filename}") end |