Wicked_pdf + rail resource traffic + sass import into production

I am successfully using wicked_pdf with SASS in development. I include one file .scssthat contains several rules importfor other files .sassand .scssthrough this helper:

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

But when switching to production, the application is still looking for the imported files found arent.

I added a second manifest file, which must be precompiled in the production.rb ( config.assets.precompile += %w(pdf.css)) file , which contains one rule requireto pick up the specified file .scss. This file was compiled just fine, but it seems that the assistant does not select the necessary file during the production process and is still trying to load the imported files .sass.

Does anyone have any experience how to solve this? Creating PDF requires absolute paths, making it difficult to complete this task.

+5
source share
2 answers

I have an evil pdf working in development and production. This is the core of my wicked_pdf configuration:

I updated the WickedPdfHelper (downloaded from initializers / wicked_pdf.rb) based on the wicked_pdf pull request from github antti user

module WickedPdfHelper
  def wicked_pdf_stylesheet_link_tag(*sources)
    sources.collect { |source|
      "<style type='text/css'>#{Rails.application.assets.find_asset(source+".css")}</style>"
    }.join("\n").html_safe
  end

  def wicked_pdf_image_tag(img, options={})
    asset = Rails.application.assets.find_asset(img)
    image_tag "file://#{asset.pathname.to_s}", options
  end

  def wicked_pdf_javascript_src_tag(jsfile, options={})
    asset = Rails.application.assets.find_asset(jsfile)
    javascript_include_tag "file://#{asset.pathname.to_s}", options
  end

  def wicked_pdf_javascript_include_tag(*sources)
    sources.collect{ |source| "<script type='text/javascript'>#{Rails.application.assets.find_asset(source+".js")}</script>" }.join("\n").html_safe
  end
end

then in app / assets / stylesheets / pdf.css I need some sass style sheets:

/* ...
*= require ./_colors
*= require_directory ./pdf
*= require_self
*/

(remember that if you change the initializers or anything in config /, you need to re-run the rails application to make changes)

+8

All Articles