class Rabbit::ImageManipulable::Mermaid

Public Class Methods

match?(filename) click to toggle source
# File lib/rabbit/image/mermaid.rb, line 29
def match?(filename)
  File.extname(filename).downcase.end_with?(".mmd")
end
new(filename, props, canvas: nil) click to toggle source
Calls superclass method Rabbit::ImageManipulable::Base::new
# File lib/rabbit/image/mermaid.rb, line 36
def initialize(filename, props, canvas: nil)
  init_delegated_loader(filename, props, canvas)
  super
end

Private Instance Methods

init_delegated_loader(filename, props, canvas) click to toggle source
# File lib/rabbit/image/mermaid.rb, line 42
def init_delegated_loader(filename, props, canvas)
  background_color = props["background_color"] || "transparent"
  pdf_path = File.open(filename, "rb") do |source|
    cache_processed_data(canvas, [source, background_color], "pdf") do
      @pdf_file = Tempfile.new(["rabbit-image-loader-mermaid", ".pdf"])
      command_line = [
        "npx",
        "--yes",
        "--package=@mermaid-js/mermaid-cli",
        "mmdc",
        "--backgroundColor", background_color,
        "--input", filename,
        "--output", @pdf_file.path,
        "--pdfFit",
      ]
      unless SystemRunner.run(*command_line)
        format = _("tried mermaid command: %s")
        additional_info = format % command_line.inspect
        raise MermaidCanNotHandleError.new(command_line.join(' '),
                                           additional_info)
      end
      @pdf_file.path
    end
  end
  @delegated_loader = PDF.new(pdf_path, props)
end
load_image() click to toggle source
# File lib/rabbit/image/mermaid.rb, line 69
def load_image
  # do nothing
end