Module: WickedPdfHelper
- Defined in:
- lib/wicked_pdf/wicked_pdf_helper.rb,
lib/wicked_pdf/wicked_pdf_helper/assets.rb
Defined Under Namespace
Modules: Assets
Class Method Summary collapse
Instance Method Summary collapse
- #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
Class Method Details
.add_extension(filename, extension) ⇒ Object
6 7 8 |
# File 'lib/wicked_pdf/wicked_pdf_helper.rb', line 6 def self.add_extension(filename, extension) filename.to_s.split('.').include?(extension) ? filename : "#{filename}.#{extension}" end |
.root_path ⇒ Object
2 3 4 |
# File 'lib/wicked_pdf/wicked_pdf_helper.rb', line 2 def self.root_path String === Rails.root ? Pathname.new(Rails.root) : Rails.root end |
Instance Method Details
#wicked_pdf_image_tag(img, options = {}) ⇒ Object
19 20 21 |
# File 'lib/wicked_pdf/wicked_pdf_helper.rb', line 19 def wicked_pdf_image_tag(img, = {}) image_tag "file:///#{WickedPdfHelper.root_path.join('public', 'images', img)}", end |
#wicked_pdf_javascript_include_tag(*sources) ⇒ Object
29 30 31 32 |
# File 'lib/wicked_pdf/wicked_pdf_helper.rb', line 29 def wicked_pdf_javascript_include_tag(*sources) js_text = sources.collect { |source| wicked_pdf_javascript_src_tag(source, {}) }.join("\n") js_text.respond_to?(:html_safe) ? js_text.html_safe : js_text end |
#wicked_pdf_javascript_src_tag(jsfile, options = {}) ⇒ Object
23 24 25 26 27 |
# File 'lib/wicked_pdf/wicked_pdf_helper.rb', line 23 def wicked_pdf_javascript_src_tag(jsfile, = {}) jsfile = WickedPdfHelper.add_extension(jsfile, 'js') src = "file:///#{WickedPdfHelper.root_path.join('public', 'javascripts', jsfile)}" content_tag('script', '', { 'type' => Mime::JS, 'src' => path_to_javascript(src) }.merge()) end |
#wicked_pdf_stylesheet_link_tag(*sources) ⇒ Object
10 11 12 13 14 15 16 17 |
# File 'lib/wicked_pdf/wicked_pdf_helper.rb', line 10 def wicked_pdf_stylesheet_link_tag(*sources) css_dir = WickedPdfHelper.root_path.join('public', 'stylesheets') css_text = sources.collect do |source| source = WickedPdfHelper.add_extension(source, 'css') "<style type='text/css'>#{File.read(css_dir.join(source))}</style>" end.join("\n") css_text.respond_to?(:html_safe) ? css_text.html_safe : css_text end |