Created
September 14, 2011 23:54
-
-
Save anlek/1218149 to your computer and use it in GitHub Desktop.
Using Wicked_PDF with Rails 3.1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#in config/initializers/wicked_pdf.rb | |
module WickedPdfHelper | |
def wicked_pdf_stylesheet_link_tag(*sources) | |
sources.collect { |source| | |
"<style type='text/css'>#{Rails.application.assets.find_asset("#{source}.css").body}</style>" | |
}.join("\n").gsub(/url\(['"](.+)['"]\)(.+)/,%[url("#{wicked_pdf_image_location("\\1")}")\\2]).html_safe | |
end | |
def wicked_pdf_image_tag(img, options={}) | |
image_tag wicked_pdf_image_location(img), options | |
end | |
def wicked_pdf_image_location(img) | |
"file://#{Rails.root.join('app', 'assets', 'images', img)}" | |
end | |
def wicked_pdf_javascript_src_tag(jsfile) | |
"<script type='text/javascript'>#{Rails.application.assets.find_asset("#{source}.js").body}</script>" | |
end | |
def wicked_pdf_javascript_include_tag(*sources) | |
sources.collect{ |source| wicked_pdf_javascript_src_tag(source, {}) }.join("\n").html_safe | |
end | |
end |
I spotted a couple of bugs. I forked the gist and amended.
https://gist.github.com/1388921
Cheers,
Graeme
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Read article on this at: http://anlek.com/2011/09/wicked_pdf-working-in-rails-3-1/