Sha256: 997592a19188a9648869f9fce7605f6dd30a1002adae76a1ab9688bc9b5b0ce6

Contents?: true

Size: 1.47 KB

Versions: 16

Compression:

Stored size: 1.47 KB

Contents

class WickedPdf
  module WickedPdfHelper
    def self.root_path
      String === Rails.root ? Pathname.new(Rails.root) : Rails.root
    end

    def self.add_extension(filename, extension)
      filename.to_s.split('.').include?(extension) ? filename : "#{filename}.#{extension}"
    end

    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

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

    def wicked_pdf_javascript_src_tag(jsfile, options = {})
      jsfile = WickedPdfHelper.add_extension(jsfile, 'js')
      type = ::Mime.respond_to?(:[]) ? ::Mime[:js] : ::Mime::JS # ::Mime[:js] cannot be used in Rails 2.3.
      src = "file:///#{WickedPdfHelper.root_path.join('public', 'javascripts', jsfile)}"
      content_tag('script', '', { 'type' => type, 'src' => path_to_javascript(src) }.merge(options))
    end

    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
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
wicked_pdf-2.8.2 lib/wicked_pdf/wicked_pdf_helper.rb
wicked_pdf-2.8.1 lib/wicked_pdf/wicked_pdf_helper.rb
wicked_pdf-2.8.0 lib/wicked_pdf/wicked_pdf_helper.rb
wicked_pdf-2.7.0 lib/wicked_pdf/wicked_pdf_helper.rb
wicked_pdf-2.6.3 lib/wicked_pdf/wicked_pdf_helper.rb
wicked_pdf-2.6.2 lib/wicked_pdf/wicked_pdf_helper.rb
wicked_pdf-2.6.0 lib/wicked_pdf/wicked_pdf_helper.rb
wicked_pdf-2.1.0 lib/wicked_pdf/wicked_pdf_helper.rb
wicked_pdf-2.0.2 lib/wicked_pdf/wicked_pdf_helper.rb
wicked_pdf-2.0.1 lib/wicked_pdf/wicked_pdf_helper.rb
wicked_pdf-2.0.0 lib/wicked_pdf/wicked_pdf_helper.rb
wicked_pdf-1.4.0 lib/wicked_pdf/wicked_pdf_helper.rb
wicked_pdf-1.3.0 lib/wicked_pdf/wicked_pdf_helper.rb
wicked_pdf-1.2.2 lib/wicked_pdf/wicked_pdf_helper.rb
wicked_pdf-1.2.1 lib/wicked_pdf/wicked_pdf_helper.rb
wicked_pdf-1.2.0 lib/wicked_pdf/wicked_pdf_helper.rb