Module: WickedPdfHelper::Assets

Defined in:
lib/wicked_pdf/wicked_pdf_helper.rb

Constant Summary collapse

ASSET_URL_REGEX =
/url\(['"](.+)['"]\)(.+)/

Instance Method Summary collapse

Instance Method Details

#wicked_pdf_asset_path(asset) ⇒ Object


66
67
68
69
70
71
72
# File 'lib/wicked_pdf/wicked_pdf_helper.rb', line 66

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


50
51
52
# File 'lib/wicked_pdf/wicked_pdf_helper.rb', line 50

def wicked_pdf_image_tag(img, options = {})
  image_tag wicked_pdf_asset_path(img), options
end

#wicked_pdf_javascript_include_tag(*sources) ⇒ Object


59
60
61
62
63
64
# File 'lib/wicked_pdf/wicked_pdf_helper.rb', line 59

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


54
55
56
57
# File 'lib/wicked_pdf/wicked_pdf_helper.rb', line 54

def wicked_pdf_javascript_src_tag(jsfile, options = {})
  jsfile = WickedPdfHelper.add_extension(jsfile, 'js')
  javascript_include_tag wicked_pdf_asset_path(jsfile), options
end

39
40
41
42
43
44
45
46
47
48
# 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
    "url(#{wicked_pdf_asset_path($1)})#{$2}"
  end.html_safe
end