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") (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
wkhtmltopdfexecutable 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 (content, wants_html = false) update_tag_attribute(:link, :href, content, wants_html) end
#update_a_hrefs(content) ⇒ Object
Public: Converts 'href' attributes of any tags to be compatible with the
wkhtmltopdfexecutable requirements (to absolute URLs). Capable of handling URLs to both other domains and relative URLS.content - the String of HTML content to normalize/update
Returns content un-modified if wants_html is true. Otherwise returns the content string with the modified 'href' attribute on all -tags in content.
124 125 126
# File 'app/helpers/chili_pdf_helper.rb', line 124 def update_a_hrefs(content) update_tag_attribute(:a, :href, content, false, :absolute_url) end
#update_img_src_tags_of(content, wants_html = false) ⇒ Object
Public: Converts 'src' attributes of any
tags to be compatible with the
wkhtmltopdfexecutable 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 (content, wants_html = false) update_tag_attribute(:img, :src, content, wants_html) end
#update_link_and_image_urls(content, wants_html) ⇒ Object
Public: Converts 'href' attributes of any tags and any 'src' attributes of
tags contained in 'content' to be compatible with the
wkhtmltopdfexecutable (to absolute & 'file://-based' URLs).content - the String of HTML content to normalize/update wants_html - specifies whether the 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 -tags in content.
140 141 142
# File 'app/helpers/chili_pdf_helper.rb', line 140 def update_link_and_image_urls(content, wants_html) update_a_hrefs((content, wants_html)) end