Module: WickedPdfHelper::Assets
- Defined in:
- lib/wicked_pdf/wicked_pdf_helper.rb
Constant Summary collapse
- ASSET_URL_REGEX =
/url\(['"]?([^'"]+?)['"]?\)/
Instance Method Summary collapse
- #wicked_pdf_asset_path(asset) ⇒ Object
- #wicked_pdf_image_tag(img, options = {}) ⇒ Object
- #wicked_pdf_javascript_include_tag(*sources) ⇒ Object
- #wicked_pdf_javascript_src_tag(jsfile, options = {}) ⇒ Object
- #wicked_pdf_stylesheet_link_tag(*sources) ⇒ Object
Instance Method Details
#wicked_pdf_asset_path(asset) ⇒ Object
70 71 72 73 74 75 76 |
# File 'lib/wicked_pdf/wicked_pdf_helper.rb', line 70 def wicked_pdf_asset_path(asset) if (pathname = asset_pathname(asset).to_s) =~ URI_REGEXP pathname else "file:///#{pathname}" end end |
#wicked_pdf_image_tag(img, options = {}) ⇒ Object
54 55 56 |
# File 'lib/wicked_pdf/wicked_pdf_helper.rb', line 54 def wicked_pdf_image_tag(img, = {}) image_tag wicked_pdf_asset_path(img), end |
#wicked_pdf_javascript_include_tag(*sources) ⇒ Object
63 64 65 66 67 68 |
# File 'lib/wicked_pdf/wicked_pdf_helper.rb', line 63 def wicked_pdf_javascript_include_tag(*sources) sources.collect { |source| source = WickedPdfHelper.add_extension(source, 'js') "<script type='text/javascript'>#{read_asset(source)}</script>" }.join("\n").html_safe end |
#wicked_pdf_javascript_src_tag(jsfile, options = {}) ⇒ Object
58 59 60 61 |
# File 'lib/wicked_pdf/wicked_pdf_helper.rb', line 58 def wicked_pdf_javascript_src_tag(jsfile, = {}) jsfile = WickedPdfHelper.add_extension(jsfile, 'js') javascript_include_tag wicked_pdf_asset_path(jsfile), end |
#wicked_pdf_stylesheet_link_tag(*sources) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/wicked_pdf/wicked_pdf_helper.rb', line 39 def wicked_pdf_stylesheet_link_tag(*sources) stylesheet_contents = sources.collect do |source| source = WickedPdfHelper.add_extension(source, 'css') "<style type='text/css'>#{read_asset(source)}</style>" end.join("\n") stylesheet_contents.gsub(ASSET_URL_REGEX) do if Regexp.last_match[1].starts_with?('data:') "url(#{Regexp.last_match[1]})" else "url(#{wicked_pdf_asset_path(Regexp.last_match[1])})" end end.html_safe end |