Module: ChiliPdfHelper

Defined in:
app/helpers/chili_pdf_helper.rb

Constant Summary collapse

PLUGIN_JS_DIR =

Public directory of ChiliPDF plugin JavaScript files

Rails.root.join('public','plugin_assets', 'chili_pdf', 'javascripts')
PLUGIN_CSS_DIR =

Public directory of ChiliPDF plugin stylesheets

Rails.root.join('public','plugin_assets', 'chili_pdf', 'stylesheets')
PROTOTYPE_SCRIPT_TAG =

Standard

Public: Generate JS

Public: Generates tags for all CSS files in the plugin_assets/chili_pdf/stylesheets directory, formatting the 'href' attribute value appropriately for HTML or PDF request types.

wants_html - specifies whether the 'src' attribute should be formatted for HTML or PDF requests (local vs. relative paths). Added to keep excessive boolean logic out of views.

Returns: String of link tags separated by a newline character.



22
23
24
25
26
# File 'app/helpers/chili_pdf_helper.rb', line 22

def chili_pdf_stylesheets(wants_html)
  file_type_list(:css, PLUGIN_CSS_DIR, wants_html) {|asset_path|
    "<link href='#{asset_path}' rel='stylesheet' type='text/css' />\n"
  }.join("\n")
end

#logo_img_tag(wants_html) ⇒ Object

Public: Generates an image tag with the appropriate mark-up for the ChiliPDF 'logo'.

wants_html - specifies whether the 'src' attribute should be formatted for HTML or PDF requests (local vs. relative paths). Added to keep excessive boolean logic out of views.

Returns an '' tag for your view template with a properly formatted 'src' attribute, depending on whether the user is requesting an HTML or PDF format. If no logo is defined in the plugin configuration, nothing is rendered in the view tempalate.



108
109
110
111
112
113
# File 'app/helpers/chili_pdf_helper.rb', line 108

def logo_img_tag(wants_html)
  if ChiliPDF::Config.logo_url?
    img_tag = image_tag(ChiliPDF::Config.logo_url, :id => "chili-pdf-logo")
    update_img_src_tags_of(img_tag, wants_html)
  end
end

#normalize_custom_js_src_tags_in(content, wants_html = false) ⇒ Object

Public: Converts 'src' attributes of any

Public: Converts 'href' attributes of any tags tags to be compatible with the wkhtmltopdf executable requirements, using "file://"-format for all local assets.

content - the String of HTML content to normalize/update wants_html - specifies whether the 'src' attribute should be formatted for HTML or PDF requests (local vs. relative paths). Added to keep excessive boolean logic out of views.

Returns content un-modified if wants_html is true. Otherwise returns the content string with the modified 'href' attribute on all locally-hosted -tags in content.



58
59
60
# File 'app/helpers/chili_pdf_helper.rb', line 58

def normalize_custom_link_href_tags_in(content, wants_html = false)
  update_tag_attribute(:link, :href, content, wants_html)
end

#update_img_src_tags_of(content, wants_html = false) ⇒ Object

Public: Converts 'src' attributes of any tags to be compatible with the wkhtmltopdf executable requirements, using "file://"-format for all local assets.

content - the String of HTML content to normalize/update wants_html - specifies whether the 'src' attribute should be formatted for HTML or PDF requests (local vs. relative paths). Added to keep excessive boolean logic out of views.

Returns content un-modified if wants_html is true. Otherwise returns the content string with the modified 'src' attribute on all locally-hosted -tags in content.



92
93
94
# File 'app/helpers/chili_pdf_helper.rb', line 92

def update_img_src_tags_of(content, wants_html = false)
  update_tag_attribute(:img, :src, content, wants_html)
end