在 Rails 3.1 应用程序中使用 Less

发布于 2024-12-03 11:40:30 字数 203 浏览 3 评论 0原文

我刚刚将我的应用程序升级到最新版本的 Rails (3.1),我想将 Twitter 的 Bootstrap 集成到我的应用程序中应用程序,但它使用 LESS 而不是 Rails 3.1 默认使用的 SASS。

我该如何配置 Rails 以使用 Less 而不是 Sass?

I've just upgraded my application to the latest release of rails (3.1) and I'm wanting to integrate Twitter's Bootstrap into my application but it uses LESS and not SASS which is what Rails 3.1 uses by default.

How do I go about configuring Rails to use Less instead of Sass?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

§普罗旺斯的薰衣草 2024-12-10 11:40:31

正如 apneadiving 指出的,Sprockets(Rails 3.1 用于其资产管道)支持 LESS。

要将 Rails 应用配置为支持 LESS,您可以将 gem 添加到 Gemfile 的资产组中:

group :assets do
  gem 'less'
end

然后,运行 bundle install 来获取 less gem 及其依赖项(顺便说一句,其中包括 libv8 gem,并且可能需要一段时间才能安装)。

现在只需将 .css.less 扩展与 ./app/assets/stylesheets 目录中的样式表一起使用即可。请注意,如果 LESS 文件中有任何语法错误,您将不会收到任何有用的消息(这让我困惑了一秒钟)。

As apneadiving points out, Sprockets (what Rails 3.1 uses for its asset pipeline) supports LESS.

To configure your Rails app to support LESS, you can add the gem to the assets group of your Gemfile:

group :assets do
  gem 'less'
end

Then, run bundle install to get the less gem and its dependencies (which includes the libv8 gem, by the way, and can take awhile to install).

Now it's just a matter of using the .css.less extension with the stylesheets in your ./app/assets/stylesheets directory. Note that you won't get any helpful messages if you have any syntax errors in your LESS files (this tripped me up for a second).

看轻我的陪伴 2024-12-10 11:40:31

对于 Rails 3.1,我们现在有了 @metaskill 的 less-rails gem,它提供了特定于 Rails 的帮助程序等。它相当新,但似乎得到了积极维护。

您还可以使用 less-rails-bootstrap gem(由同一作者提供)来引入引导库。

gem 'less-rails'
gem 'less-rails-bootstrap'

另请参阅我的文章此处,了解如何在 Rails 上使用 Bootstrap 及其 mixin。

For Rails 3.1, we now have @metaskill's less-rails gem which provides helpers etc. specific to Rails. It is fairly new but seems to be actively maintained.

You can also use the less-rails-bootstrap gem (by the same author) to pull in the bootstrap libraries.

gem 'less-rails'
gem 'less-rails-bootstrap'

Also see my post here about using Bootstrap and its mixins on Rails.

沫离伤花 2024-12-10 11:40:31

非常直接,请参阅此处的原始文档

用更少的样式

LESS 通过动态行为扩展了 CSS,例如变量、mixin、
操作和功能。

如果 less gem 可用于您的应用程序,您可以使用 LESS 来
在 Sprockets 中编写 CSS 资源。注意LESS编译器是这么写的
在 JavaScript 中,在撰写本文时,gem 依赖的越少
在 therubyracer 上,它在 Ruby 中嵌入了 V8 JavaScript 运行时。

要使用 LESS 编写 CSS 资源,请使用扩展名 .css.less。

Pretty straight, see original doc here:

Styling with LESS

LESS extends CSS with dynamic behavior such as variables, mixins,
operations and functions.

If the less gem is available to your application, you can use LESS to
write CSS assets in Sprockets. Note that the LESS compiler is written
in JavaScript, and at the time of this writing, the less gem depends
on therubyracer which embeds the V8 JavaScript runtime in Ruby.

To write CSS assets with LESS, use the extension .css.less.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文