添加字体后,Heroku Rails资产管道无法预编译 [英] Heroku Rails asset pipeline fails to precompile after adding font

查看:121
本文介绍了添加字体后,Heroku Rails资产管道无法预编译的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



添加字体到:

  -app 
- 资产
- 字体

SCSS:

  @ font-face {
font-family :LigatureSymbols;

src:font-url('LigatureSymbols211.eot');
src:local('LigatureSymbols'),
font-url('LigatureSymbols211.eot?#iefix')格式('embedded-opentype'),
font-url('LigatureSymbols211。 WOFF ')格式(' WOFF '),
字体-URL(' LigatureSymbols211.ttf ')格式(' 的TrueType '),
字体-URL(' LigatureSymbols211.svg#LigatureSymbols ')格式(' SVG');

font-weight:normal;
font-style:normal;
}

production.rb

  config.assets.paths<< Rails.root.join('app','assets','fonts')
config.assets.precompile + =%w(.svg .eot .woff .ttf)

但是当我推送到我的Heroku制作服务器时,我得到了这个结果:

  ----->为Rails资产管道准备应用程序
运行:rake资产:预编译
我,[2013-05-06T06:21:07.804043#2036] INFO - :编写/ tmp / build_2snusxy9gm4d7 / public / assets / LigatureSymbols211 -c5b7db18fa0fcd910e92fee751776047.eot
I,[2013-05-06T06:21:07.809822#2036] INFO - :Writing /tmp/build_2snusxy9gm4d7/public/assets/LigatureSymbols211-09ff8be41a6bee98c834e9a278bb8b28.otf
I,[2013 -05-06T06:21:07.812685#2036] INFO - :编写/tmp/build_2snusxy9gm4d7/public/assets/LigatureSymbols211-1f682b1be252dbf6182d606a185b603f.svg
我,[2013-05-06T06:21:07.819262#2036] INFO - :写入/tmp/build_2snusxy9gm4d7/public/assets/LigatureSymbols211-9e88765b872185b22e519da056cba9f0.ttf
我,[2013-05-06T06:21:07.829518#2036] INFO - :编写/ tmp / build_2snusxy9gm4d7 / public / assets /LigatureSymbols211-a2d90ca6deff46bfcf9cade63d4902ce.woff
我,[2013-05-06T06:21:07.838351#2036] INFO - :写作的/ tmp / build_2snusxy9gm4d7 / PU blic / assets / rails-5f9b3f343d9831cbf50b9bc980faf39b.png
I,[2013-05-06T06:21:17.072501#2036] INFO - :Writing /tmp/build_2snusxy9gm4d7/public/assets/application-6af5b81b9fcc820f1d43b4135f00317e.js
耙子中止了!
未定义方法`[]'为nil:NilClass
(在/tmp/build_2snusxy9gm4d7/app/assets/stylesheets/application.css中)

我试着在我的 application.css中添加一个所需的但这也行不通。



编辑:

我可以在运行服务器时在我的开发机器上访问 localhost:5000 / assets / LigatureSymbols-2.11.eot 。不知道这是否有助于缩小出错的地方



编辑2:



代码与SCSS字体一起使用注释掉了,是否有语法错误?

编辑3:

它位于跟踪堆栈的顶部:

  ... / sprockets-2.9.2 / lib / sprockets / sass_functions.rb:63:`sprockets_context'
... / sprockets-2.9.2 / lib / sprockets / sass_functions.rb:42:in`font_url'

我的 font-url 调用有问题吗?



编辑4:

删除字体文件名中的破折号并更改了scss以反映,但仍存在相同的错误



编辑5:



在本地机器上生成CSS:

  @ font-face {
font-family:LigatureSymbols;
src:font-url(LigatureSymbols211.eot);
源:本地( LigatureSymbols),字体网址( LigatureSymbols211.eot #iefix?)格式( 嵌入式OpenType字体),字体网址( LigatureSymbols211.woff)格式( WOFF ),font-url(LigatureSymbols211.ttf)格式(truetype),font-url(LigatureSymbols211.svg#LigatureSymbols)格式(svg);
font-weight:normal;
font-style:normal; }


解决方案

我发现了!奇怪的事情......可能是SASS中的一个错误。



如果我将代码直接放在文件 home.css.scss 这是我的 application.css 中所需要的,则会发生错误。

另外,如果我将字体SCSS放在一个单独的文件( font.scss )和 @importfont它也会引发错误。 如果我在<$ c $>中需要 font.scss 文件,那么 $ b

c> application.css 将通过资产管道。



如果我使用 font-url (...) vs asset-url(...,font) vs url(资产路径(。 ..,font))在 application.css中包含 = require 字体时, / code>


I'm trying to add a font to my Rails app this is what I've done:

Added fonts to:

-app
--assets
---fonts

SCSS:

@font-face {
  font-family: LigatureSymbols;

  src: font-url('LigatureSymbols211.eot');
  src: local('LigatureSymbols'),
       font-url('LigatureSymbols211.eot?#iefix') format('embedded-opentype'),
       font-url('LigatureSymbols211.woff') format('woff'),
       font-url('LigatureSymbols211.ttf') format('truetype'),
       font-url('LigatureSymbols211.svg#LigatureSymbols') format('svg');

  font-weight: normal;
  font-style: normal;
}

production.rb:

config.assets.paths << Rails.root.join('app', 'assets', 'fonts')
config.assets.precompile += %w( .svg .eot .woff .ttf )

But when I push to my Heroku production server I get this:

-----> Preparing app for Rails asset pipeline
       Running: rake assets:precompile
       I, [2013-05-06T06:21:07.804043 #2036]  INFO -- : Writing /tmp/build_2snusxy9gm4d7/public/assets/LigatureSymbols211-c5b7db18fa0fcd910e92fee751776047.eot
       I, [2013-05-06T06:21:07.809822 #2036]  INFO -- : Writing /tmp/build_2snusxy9gm4d7/public/assets/LigatureSymbols211-09ff8be41a6bee98c834e9a278bb8b28.otf
       I, [2013-05-06T06:21:07.812685 #2036]  INFO -- : Writing /tmp/build_2snusxy9gm4d7/public/assets/LigatureSymbols211-1f682b1be252dbf6182d606a185b603f.svg
       I, [2013-05-06T06:21:07.819262 #2036]  INFO -- : Writing /tmp/build_2snusxy9gm4d7/public/assets/LigatureSymbols211-9e88765b872185b22e519da056cba9f0.ttf
       I, [2013-05-06T06:21:07.829518 #2036]  INFO -- : Writing /tmp/build_2snusxy9gm4d7/public/assets/LigatureSymbols211-a2d90ca6deff46bfcf9cade63d4902ce.woff
       I, [2013-05-06T06:21:07.838351 #2036]  INFO -- : Writing /tmp/build_2snusxy9gm4d7/public/assets/rails-5f9b3f343d9831cbf50b9bc980faf39b.png
       I, [2013-05-06T06:21:17.072501 #2036]  INFO -- : Writing /tmp/build_2snusxy9gm4d7/public/assets/application-6af5b81b9fcc820f1d43b4135f00317e.js
       rake aborted!
       undefined method `[]' for nil:NilClass
       (in /tmp/build_2snusxy9gm4d7/app/assets/stylesheets/application.css)

I tried to add a required line in my application.css but that wouldn't work either.

EDIT:

I can access localhost:5000/assets/LigatureSymbols-2.11.eot on my dev machine when running the server. Not sure if this might help narrow what's going wrong

EDIT 2:

The code works with the SCSS font commented out, is there a syntax error?

EDIT 3:

This is at the top of the trace stack:

.../sprockets-2.9.2/lib/sprockets/sass_functions.rb:63:in `sprockets_context'
.../sprockets-2.9.2/lib/sprockets/sass_functions.rb:42:in `font_url'

is there something wrong with my font-url calls?

EDIT 4:

Removed dashes from font filenames and changed scss to reflect, but same error persists

EDIT 5:

Generated CSS on local machine:

@font-face {
  font-family: LigatureSymbols;
  src: font-url("LigatureSymbols211.eot");
  src: local("LigatureSymbols"), font-url("LigatureSymbols211.eot?#iefix") format("embedded-opentype"), font-url("LigatureSymbols211.woff") format("woff"), font-url("LigatureSymbols211.ttf") format("truetype"), font-url("LigatureSymbols211.svg#LigatureSymbols") format("svg");
  font-weight: normal;
  font-style: normal; }

解决方案

I found it out! Strangest thing... might be a bug in SASS.

If I put the code directly in the file home.css.scss which was required in my application.css, the error would occur.

Additionally, if I placed the font SCSS in a seperate file (font.scss) and @import "font" it would also raise an error.

Only if I required the font.scss file in my application.css would the asset pipeline pass.

It didn't matter if I used font-url(...) vs asset-url(...,font) vs url(asset-path(...,font)) They all work when the font was included via a =require in the application.css

这篇关于添加字体后,Heroku Rails资产管道无法预编译的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆