wicked_pdf +导轨'资产管道 +生产中的 sass 导入
我在开发中成功地将 wicked_pdf 与 SASS 结合使用。我包含一个 .scss
文件,其中包含其他 .sass
和 .scss
的多个 import
规则文件,通过此帮助程序:
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
但切换到生产应用程序仍然会查找未找到的导入文件。
然后,我添加了第二个清单文件,要在 production.rb 中预编译 (config.assets.precompile += %w(pdf.css)
),其中包含单个 require< /code> 规则来获取提到的
.scss
文件。该文件编译得很好,但似乎帮助程序没有在生产中选择正确的文件,并且仍然会加载导入的 .sass 文件。
有谁有经验如何解决这个问题? PDF 创建需要绝对路径,这使得这项任务变得更加困难。
I'm successfully using wicked_pdf with SASS in development. I'm including a single .scss
file, which contains several import
rules for other .sass
and .scss
files, via 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 switching to production the app still looks for the imported files which aren’t found.
I've added then a second manifest file to be pre–compiled in production.rb (config.assets.precompile += %w(pdf.css)
) which contains a single require
rule to pick up the mentioned .scss
file. This file is compiled just fine but it seems that the helper doesn't pick up the right file in production and still looks to load the imported .sass
files.
Has anyone experience how to solve this? The PDF creation requires absolute paths, which makes this task a bit more difficult.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我有一份邪恶的pdf文件正在开发和制作中。这是我的 wicked_pdf 配置的核心:
我已经根据 wicked_pdf pull request 来自 github 用户 antti
然后在 app/assets/stylesheets/pdf.css 中我需要一些 sass 样式表:
(请记住,如果您要修改初始化程序或 config/ 中的任何内容,则需要重新启动 Rails 应用程序才能引入更改)
I have wicked pdf working in development and production. This is the core of my wicked_pdf config:
I've updated WickedPdfHelper (loaded from initializers/wicked_pdf.rb) based on a wicked_pdf pull request from github user antti
then in app/assets/stylesheets/pdf.css I require a few sass stylesheets:
(remember that if you're modifying initializers or anything in config/, you'll need to re-start your rails app to pull in the changes)
我在以下位置写了一篇文章:http://anlek。 com/2011/09/wicked_pdf-working-in-rails-3-1/
它与 Philip 的解决方案非常相似,但做了一些修改。
I wrote a article on this at: http://anlek.com/2011/09/wicked_pdf-working-in-rails-3-1/
It's very similar to Philip's solution with a few modifications.