Class: HtmlsToPdf

Inherits:
Object
  • Object
show all
Defined in:
lib/htmls_to_pdf/htmls_to_pdf.rb

Overview

HtmlsToPdf.new takes a configuration hash and returns an object with a create_pdf() method Calling create_pdf() on the HtmlsToPdf object generates a PDF file configured according to the configuration hash settings

Usage: HtmlsToPdf.new(options_hash).create_pdf

Constant Summary collapse

TMP_HTML_PREFIX =
'tmp_html_file_'
TMP_PDF_PREFIX =
'tmp_pdf_file_'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config = {}) ⇒ HtmlsToPdf

Returns a new instance of HtmlsToPdf.



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/htmls_to_pdf/htmls_to_pdf.rb', line 22

def initialize(config = {})
  defaults = {
    remove_css_files:       true,
    remove_html_files:      true,
    remove_tmp_pdf_files:   true,
    overwrite_existing_pdf: false,
    savedir:                "~",
    savename:               'htmls_to_pdf.pdf',
    debug:                  false
  }
  config = defaults.merge!(config)

  set_instance_vars(config)
  
  set_dir(@savedir)

  exit_if_pdf_exists unless @overwrite_existing_pdf
end

Instance Attribute Details

#cssarrayObject

Returns the value of attribute cssarray.



17
18
19
# File 'lib/htmls_to_pdf/htmls_to_pdf.rb', line 17

def cssarray
  @cssarray
end

#debugObject

Returns the value of attribute debug.



17
18
19
# File 'lib/htmls_to_pdf/htmls_to_pdf.rb', line 17

def debug
  @debug
end

#htmlarrayObject

Returns the value of attribute htmlarray.



17
18
19
# File 'lib/htmls_to_pdf/htmls_to_pdf.rb', line 17

def htmlarray
  @htmlarray
end

#optionsObject

Returns the value of attribute options.



17
18
19
# File 'lib/htmls_to_pdf/htmls_to_pdf.rb', line 17

def options
  @options
end

#overwrite_existing_pdfObject

Returns the value of attribute overwrite_existing_pdf.



17
18
19
# File 'lib/htmls_to_pdf/htmls_to_pdf.rb', line 17

def overwrite_existing_pdf
  @overwrite_existing_pdf
end

#pdfarrayObject

Returns the value of attribute pdfarray.



17
18
19
# File 'lib/htmls_to_pdf/htmls_to_pdf.rb', line 17

def pdfarray
  @pdfarray
end

#remove_css_filesObject

Returns the value of attribute remove_css_files.



17
18
19
# File 'lib/htmls_to_pdf/htmls_to_pdf.rb', line 17

def remove_css_files
  @remove_css_files
end

#remove_html_filesObject

Returns the value of attribute remove_html_files.



17
18
19
# File 'lib/htmls_to_pdf/htmls_to_pdf.rb', line 17

def remove_html_files
  @remove_html_files
end

#remove_temp_filesObject

Returns the value of attribute remove_temp_files.



17
18
19
# File 'lib/htmls_to_pdf/htmls_to_pdf.rb', line 17

def remove_temp_files
  @remove_temp_files
end

#remove_tmp_pdf_filesObject

Returns the value of attribute remove_tmp_pdf_files.



17
18
19
# File 'lib/htmls_to_pdf/htmls_to_pdf.rb', line 17

def remove_tmp_pdf_files
  @remove_tmp_pdf_files
end

#savedirObject

Returns the value of attribute savedir.



17
18
19
# File 'lib/htmls_to_pdf/htmls_to_pdf.rb', line 17

def savedir
  @savedir
end

#savenameObject

Returns the value of attribute savename.



17
18
19
# File 'lib/htmls_to_pdf/htmls_to_pdf.rb', line 17

def savename
  @savename
end

#urlsObject

Returns the value of attribute urls.



17
18
19
# File 'lib/htmls_to_pdf/htmls_to_pdf.rb', line 17

def urls
  @urls
end

Instance Method Details

#create_pdfObject



41
42
43
44
45
46
47
48
# File 'lib/htmls_to_pdf/htmls_to_pdf.rb', line 41

def create_pdf
  clean_temp_files
  get_temp_files
  # update_asset_urls
  generate_pdfs
  join_pdfs
  clean_temp_files
end