简体   繁体   English

Rails:Bower CSS 无法加载其字体

[英]Rails: Bower CSS can't load its fonts

I downloaded Metro UI and the CSS downloaded into this folder:我下载了 Metro UI 和下载到这个文件夹中的 CSS:

/vendor/assets/bower_components/metro-bootstrap/dist/css/metro-bootstrap.css

Then I included the CSS from app/assets/stylesheets/application.css.scss like so:然后我包含了来自app/assets/stylesheets/application.css.scss的 CSS,如下所示:

/*
 * require bootstrap-sass
 *= require_tree .
 *= require_self 
  require metro-bootstrap (not sure if I should include this?)
 */

@import "metro-bootstrap/dist/css/metro-bootstrap.css";

It throws an error because the CSS is trying to load fonts like this:它抛出一个错误,因为 CSS 正在尝试加载这样的字体:

@font-face {
  font-family: 'Glyphicons Halflings';
  src: url('../fonts/glyphicons-halflings-regular.eot');
  src: url('../fonts/glyphicons-halflings-regular.eot?#iefix') format('embedded-opentype'), url('../fonts/glyphicons-halflings-regular.woff') format('woff'), url('../fonts/glyphicons-halflings-regular.ttf') format('truetype'), url('../fonts/glyphicons-halflings-regular.svg#glyphicons_halflingsregular') format('svg');
}

The fonts are located in this folder:字体位于此文件夹中:

/vendor/assets/bower_components/metro-bootstrap/dist/fonts/

But this folder is not accessed by Ruby naturally, because Ruby kind of compiles all the assets in new folders, and stuff (I don't know well)但是这个文件夹不是 Ruby 自然访问的,因为 Ruby 有点编译新文件夹中的所有资产和东西(我不太清楚)

Can you help me fix this?你能帮我解决这个问题吗? I want it to link to the fonts with the right path, without having to modify the CSS, or copy the CSS to my asset folder, otherwise it'd kill the purpose of using Bower to install dependencies.我希望它以正确的路径链接到字体,而不必修改 CSS,或者将 CSS 复制到我的资产文件夹,否则它会破坏使用 Bower 安装依赖项的目的。

I was able to set up a demo application using the same metro theme (actually like the font, so thank you for sharing that).我能够使用相同的 Metro 主题设置演示应用程序(实际上就像字体一样,所以感谢您的分享)。 Let me walk you through how I set things up and see if it can work out for you or maybe you missed a step.让我向您介绍我是如何设置的,看看它是否适合您,或者您是否错过了一步。

First I created a .bowerrc file (maybe change yours to bower_components for the directory path?):首先,我创建了一个.bowerrc文件(也许将您的文件更改为 bower_components 作为目录路径?):

{
  "directory": "vendor/assets/components"
}

Then bower init to create the json file.然后bower init创建 json 文件。

Then bower install metro-bootstrap然后bower install metro-bootstrap

application.css.scss应用程序.css.scss

 *
 *= require_tree .
 *= require_self
 */

@import "metro-bootstrap/dist/css/metro-bootstrap.css";

I then started my server and the correct font rendered.然后我启动了我的服务器并呈现了正确的字体。 Here is a good resource on setting Bower in your rails application (without the gem): http://dotwell.io/taking-advantage-of-bower-in-your-rails-4-app/ .这是在 Rails 应用程序中设置 Bower 的一个很好的资源(没有 gem): http : //dotwell.io/taking-advantage-of-bower-in-your-rails-4-app/ Hopefully that gives you some ideas or helps you out.希望这能给你一些想法或帮助你。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM