开发者

Using Less in a Rails 3.1 App

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开发者_如何学JAVA 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?


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).


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜