Rails 应用程序:使用 gem 与包含 Twitter Bootstrap 的源 [英] Rails app: using a gem vs. including source with Twitter Bootstrap

查看:16
本文介绍了Rails 应用程序:使用 gem 与包含 Twitter Bootstrap 的源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我浏览了我的应用程序,当我通过 gem 包含 Twitter Bootstrap 源时,我无法找到它的确切位置.例如,如果我想查看 Bootstrap .css,我该如何找到它?

I've gone through my app and am having trouble finding where exactly the Twitter Bootstrap source goes when I include it through a gem. If I wanted to view the Bootstrap .css for example, how do I find it?

据我了解,将其作为 gem 包含的替代方法是直接下载并包含源代码,对吗?一种方法比另一种更好吗?

The alternative, as I understand, to including it as a gem would be do download and include the source directly, correct? Is one approach better than the other.

最后,如果我想修改 Bootstrap css,最好的方法是什么?如果我的应用程序中有源代码,我想我可以进去修改一些东西.如果我将它作为宝石包含在内呢?

Finally, if I wanted to modify the Bootstrap css what is the best way to do it? If I had the source in my app I imagine I could just go in there and modify things. How about if I'm including it as a gem?

非常感谢您对它的工作原理进行一些澄清.将源代码放在我的应用程序目录中的某个地方是有道理的,我可以相对于 .html 文件指向它...但是使用 Gemfile 我觉得事情在一个小黑盒子里...

Some clarification on how this works would be greatly appreciated. Having the source sitting in my app's directory somewhere makes sense, and I could point to it relative to the .html files...but with the Gemfile I feel like things are in a little black box...

推荐答案

我完全同意让 Bootstrap 文件位于您的应用程序之外是令人印象深刻的.

I absolutely agree it's underwhelming to have the Bootstrap files sit outside your application.

在这种情况下,我推荐以下工作流程:

I recommend the following workflow in this case:

  1. 从 Github 克隆 repo bootstrap-sass 或下载 zipball.它是 Bootstrap 到 Sass 的官方端口,并且由同一团队不断更新.

  1. Clone the repo bootstrap-sass from Github or download the zipball. It's the official port of Bootstrap into Sass and it's kept updated by the same team.

复制 Sass 部分(文件名以下划线开头的部分)到 app/vendor/assets/stylesheets.Javascript 和图像进入 app/vendor/assets 下各自的目录.这将提醒您远离编辑这些文件,同时保持应用程序的资产目录清洁.每当您想仔细观察它们时,它们就近在咫尺.

Copy only the Sass partials (the ones whose filename begins with an underscore) to app/vendor/assets/stylesheets. Javascript and images go into their respective directories under app/vendor/assets. That will remind you to stay away from editing those files while at the same time keeping your app's asset directories clean. And whenever you feel like taking a closer look at them, they will be right at hand.

bootstrap.scss 复制到 app/assets/stylesheets 并随意修改.确保关闭所有不使用的功能,因为随身携带这些东西意味着 CSS 文件比你需要的要大.

Copy bootstrap.scss to app/assets/stylesheets and tinker with those as much as you want. Be sure to turn off all the features you're not using, because carrying that stuff around will mean having a larger CSS file than you need.

自定义您的 Boostrap 变量和类,并在清单中的 Bootstrap 文件之后加载它们,就像使用 gem 一样.例如,假设您将自己的变量放入 _overrides.scss.您的 application.css.scss 看起来像这样:

Customize your Boostrap variables and classes and load them after the Bootstrap files in your manifest, just like you would with a gem. For instance, let's say you put your own variables into _overrides.scss. Your application.css.scss would look like this:

@import "bootstrap";
@import "overrides";

就是这样.这就是 app/vendor/assets 的用途!

That's it. That's what app/vendor/assets was made for!

这篇关于Rails 应用程序:使用 gem 与包含 Twitter Bootstrap 的源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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