class BreezyPDF::Resources::HTML

:nodoc

Public Class Methods

new(base_url, html_fragment) click to toggle source
# File lib/breezy_pdf/resources/html.rb, line 6
def initialize(base_url, html_fragment)
  @base_url      = base_url
  @html_fragment = html_fragment
  @upload_ids    = []
end

Public Instance Methods

content_type() click to toggle source
# File lib/breezy_pdf/resources/html.rb, line 12
def content_type
  "text/html"
end
file_path() click to toggle source
# File lib/breezy_pdf/resources/html.rb, line 20
def file_path
  file.path
end
filename() click to toggle source
# File lib/breezy_pdf/resources/html.rb, line 16
def filename
  @filename ||= "#{SecureRandom.hex}.html"
end
metadata() click to toggle source
# File lib/breezy_pdf/resources/html.rb, line 24
def metadata
  @metadata ||= BreezyPDF.extract_metadata ? Hash[*meta_tags] : {}
end
upload_ids() click to toggle source
# File lib/breezy_pdf/resources/html.rb, line 28
def upload_ids
  modified_html_fragment

  @upload_ids
end

Private Instance Methods

file() click to toggle source
# File lib/breezy_pdf/resources/html.rb, line 36
def file
  @file ||= Tempfile.new(filename).tap do |f|
    f.write(modified_html_fragment)
    f.rewind
  end
end
meta_tags() click to toggle source
# File lib/breezy_pdf/resources/html.rb, line 69
def meta_tags
  @meta_tags ||= parsed_document.css(%(meta[name^="breezy-pdf-"])).collect do |tag|
    [tag["name"].gsub(/^breezy\-pdf\-/, ""), tag["content"]]
  end.flatten
end
modified_html_fragment() click to toggle source
# File lib/breezy_pdf/resources/html.rb, line 43
def modified_html_fragment
  @modified_html_fragment ||= modify_html_fragment!
end
modify_html_fragment!() click to toggle source
# File lib/breezy_pdf/resources/html.rb, line 47
def modify_html_fragment!
  if BreezyPDF.filter_elements
    @html_fragment = BreezyPDF::HTML::Strip.new(
      @html_fragment
    ).stripped_fragment
  end

  if BreezyPDF.upload_assets
    publiciser = BreezyPDF::HTML::Publicize.new(
      @base_url, @html_fragment
    )
    @upload_ids    = publiciser.upload_ids
    @html_fragment = publiciser.public_fragment
  end

  @html_fragment
end
parsed_document() click to toggle source
# File lib/breezy_pdf/resources/html.rb, line 65
def parsed_document
  @parsed_document ||= Nokogiri::HTML(modified_html_fragment)
end