Module: WickedPdfHelper

Defined in:
lib/wicked_pdf/wicked_pdf_helper.rb

Defined Under Namespace

Modules: Assets

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.add_extension(filename, extension) ⇒ Object


8
9
10
# File 'lib/wicked_pdf/wicked_pdf_helper.rb', line 8

def self.add_extension(filename, extension)
  (File.extname(filename.to_s)[1..-1] == extension) ? filename : "#{filename}.#{extension}"
end

.root_pathObject


4
5
6
# File 'lib/wicked_pdf/wicked_pdf_helper.rb', line 4

def self.root_path
  String === Rails.root ? Pathname.new(Rails.root) : Rails.root
end

Instance Method Details

#wicked_pdf_image_tag(img, options = {}) ⇒ Object


21
22
23
# File 'lib/wicked_pdf/wicked_pdf_helper.rb', line 21

def wicked_pdf_image_tag(img, options = {})
  image_tag "file:///#{WickedPdfHelper.root_path.join('public', 'images', img)}", options
end

#wicked_pdf_javascript_include_tag(*sources) ⇒ Object


31
32
33
34
# File 'lib/wicked_pdf/wicked_pdf_helper.rb', line 31

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


25
26
27
28
29
# File 'lib/wicked_pdf/wicked_pdf_helper.rb', line 25

def wicked_pdf_javascript_src_tag(jsfile, options = {})
  jsfile = WickedPdfHelper.add_extension(jsfile, 'js')
  src = "file:///#{WickedPdfHelper.root_path.join('public', 'javascripts', jsfile)}"
  ('script', '', { 'type' => Mime::JS, 'src' => path_to_javascript(src) }.merge(options))
end

12
13
14
15
16
17
18
19
# File 'lib/wicked_pdf/wicked_pdf_helper.rb', line 12

def wicked_pdf_stylesheet_link_tag(*sources)
  css_dir = WickedPdfHelper.root_path.join('public', 'stylesheets')
  css_text = sources.collect { |source|
    source = WickedPdfHelper.add_extension(source, 'css')
    "<style type='text/css'>#{File.read(css_dir.join(source))}</style>"
  }.join("\n")
  css_text.respond_to?(:html_safe) ? css_text.html_safe : css_text
end