class BreezyPDF::HTML2PDF

Transform an HTML slug to a PDF Access it's URL or download it locally and access it as a Tempfile

Public Class Methods

new(asset_host, html_string, metadata = {}) click to toggle source
# File lib/breezy_pdf/html_2_pdf.rb, line 7
def initialize(asset_host, html_string, metadata = {})
  @asset_host  = asset_host
  @html_string = html_string
  @metadata    = metadata
end

Public Instance Methods

to_file() click to toggle source
# File lib/breezy_pdf/html_2_pdf.rb, line 17
def to_file
  file
end
to_url() click to toggle source
# File lib/breezy_pdf/html_2_pdf.rb, line 13
def to_url
  url
end

Private Instance Methods

combined_metadata() click to toggle source
# File lib/breezy_pdf/html_2_pdf.rb, line 37
def combined_metadata
  @combined_metadata ||= BreezyPDF.default_metadata.merge(@metadata).merge(html_private_asset.metadata)
end
file() click to toggle source
# File lib/breezy_pdf/html_2_pdf.rb, line 23
def file
  @file ||= if io_object.is_a?(StringIO)
              Tempfile.new.tap do |f|
                f.write io_object.to_s
              end
            else
              io_object
            end
end
html_private_asset() click to toggle source
# File lib/breezy_pdf/html_2_pdf.rb, line 45
def html_private_asset
  @html_private_asset ||= BreezyPDF::Resources::HTML.new(@asset_host, @html_string)
end
io_object() click to toggle source
# File lib/breezy_pdf/html_2_pdf.rb, line 41
def io_object
  @io_object ||= open(url)
end
public_url() click to toggle source
# File lib/breezy_pdf/html_2_pdf.rb, line 49
def public_url
  @public_url ||= BreezyPDF::Uploads::Base.new(
    html_private_asset.filename, html_private_asset.content_type, html_private_asset.file_path
  ).public_url
end
url() click to toggle source
# File lib/breezy_pdf/html_2_pdf.rb, line 33
def url
  @url ||= BreezyPDF::RenderRequest.new(public_url, combined_metadata).submit.download_url
end