Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 119 lines (66 sloc) 4.682 kb
b96b170 @metaskills Updating readme and make sure the LESS parser gets a :paths that incl…
authored
1 # The dynamic stylesheet language for the Rails asset pipeline.
2
3 This gem provides integration for Rails projects using the Less stylesheet language in the asset pipeline.
4
5
2808400 @metaskills Add generator support. Fixes #8.
authored
6
b96b170 @metaskills Updating readme and make sure the LESS parser gets a :paths that incl…
authored
7 ## Installing
8
26180e6 @metaskills Update readme.
authored
9 Just bundle up less-rails in your Gemfile. This will pull in less as a runtime dependency too.
b96b170 @metaskills Updating readme and make sure the LESS parser gets a :paths that incl…
authored
10
26180e6 @metaskills Update readme.
authored
11 gem 'less-rails'
b96b170 @metaskills Updating readme and make sure the LESS parser gets a :paths that incl…
authored
12
13
2808400 @metaskills Add generator support. Fixes #8.
authored
14
b96b170 @metaskills Updating readme and make sure the LESS parser gets a :paths that incl…
authored
15 ## Configuration
16
3a6cb74 @metaskills Better docs if you need to hook into less-rails configuration.
authored
17 This gem was made for other gems to properly hook into one place to provide paths to the Less::Parser. For example, the less-rails-bootstrap project at http://github.com/metaskills/less-rails-bootstrap and each project should do the path configuration for you. If you need to, you can configure less-rails with additional paths. These paths have higher priority than those from your applications assets load paths.
b96b170 @metaskills Updating readme and make sure the LESS parser gets a :paths that incl…
authored
18
3a6cb74 @metaskills Better docs if you need to hook into less-rails configuration.
authored
19 ```ruby
20 MyProject::Application.configure do
067da39 @metaskills All app asset stylesheet paths are added to less paths.
authored
21 config.less.paths << "#{Rails.root}/lib/less/protractor/stylesheets"
004ff4d @metaskills Changing config to use top level options vs a nested options.
authored
22 config.less.compress = true
3a6cb74 @metaskills Better docs if you need to hook into less-rails configuration.
authored
23 end
24 ```
b96b170 @metaskills Updating readme and make sure the LESS parser gets a :paths that incl…
authored
25
2808400 @metaskills Add generator support. Fixes #8.
authored
26 #### About Compression
27
2a8824e @metaskills Remove our basic CssCompressor since it can not handle real world gen…
authored
28 If `config.assets.compress` is set to true, we will set the `config.less.compress` to true as well. Less has real basic compression and it is recommended that you set the rails `config.assets.css_compressor` to something more stronger like `:yui` in your `config/environments/production.rb` file. Note, this requires the [yui-compressor](https://rubygems.org/gems/yui-compressor) gem but does an excellent job of compressing assets.
2808400 @metaskills Add generator support. Fixes #8.
authored
29
30
4bbfac5 @metaskills Extend LESS with Rails asset pipeline helpers. Fixes #1.
authored
31
883bd8b @metaskills Docs about `@import`
authored
32 ## Import Hooks
33
34 Any `@import` to a `.less` file will automatically declare that file as a sprockets dependency to the file importing it. This means that you can edit imported framework files and see changes reflected in the parent durning development. So this:
35
36 ```css
37 @import "frameworks/bootstrap/mixins";
38
39 #leftnav { .border-radius(5px); }
40 ```
41
42 Will end up acting as if you had done this below:
43
44 ```css
45 /*
46 *= depend_on "frameworks/bootstrap/mixins.less"
47 */
48
49 @import "frameworks/bootstrap/mixins";
50
51 #leftnav { .border-radius(5px); }
52 ```
53
54
55
4bbfac5 @metaskills Extend LESS with Rails asset pipeline helpers. Fixes #1.
authored
56 ## Helpers
57
58 When referencing assets use the following helpers in LESS.
59
60 ```css
61 asset-path(@relative-asset-path) /* Returns a string to the asset. */
62 asset-path("rails.png") /* Becomes: "/assets/rails.png" */
63
64 asset-url(@relative-asset-path) /* Returns url reference to the asset. */
65 asset-url("rails.png") /* Becomes: url(/assets/rails.png) */
66 ```
67
68 As a convenience, for each of the following asset classes there are corresponding `-path` and `-url` helpers image, font, video, audio, javascript and stylesheet. The following examples only show the `-url` variants since you get the idea of the `-path` ones above.
69
70 ```css
71 image-url("rails.png") /* Becomes: url(/assets/rails.png) */
72 font-url("rails.ttf") /* Becomes: url(/assets/rails.ttf) */
bef47b6 @pgib Fix the file extension in the video-url() and audio-url() examples.
pgib authored
73 video-url("rails.mp4") /* Becomes: url(/videos/rails.mp4) */
74 audio-url("rails.mp3") /* Becomes: url(/audios/rails.mp3) */
4bbfac5 @metaskills Extend LESS with Rails asset pipeline helpers. Fixes #1.
authored
75 javascript-url("rails.js") /* Becomes: url(/assets/rails.js) */
76 stylesheet-url("rails.css") /* Becomes: url(/assets/rails.css) */
77 ```
78
79 Lastly, we provide a data url method for base64 encoding assets.
80
81 ```css
82 asset-data-url("rails.png") /* Becomes: url(data:image/png;base64,iVBORw0K...) */
83 ```
84
85 Please note that these helpers are only available server-side, and something like ERB templates should be used if client-side rendering is desired.
86
87
2808400 @metaskills Add generator support. Fixes #8.
authored
88
89 ## Generators
90
91 Installation of the gem will set your applications stylesheet engine to use Less. It is possible to have many gems that set the stylesheet engine, for instance the sass-rails and/or stylus gems. In this case, you can resolve the ambiguity by setting the stylesheet engine in your `config/application.rb` file like so. Doing so would mean all generated assets will be in the a fresh `css.less` template.
92
93 ```ruby
94 config.app_generators.stylesheet_engine :less
95 ```
96
97 We have generators for both assets and scaffold in the `less` namespace. For instance the following would generate a blank `app/assets/stylesheets/posts.css.less` template.
98
99 ```
100 $ rails generate less:assets posts
101 ```
102
103 We also have a generator for rails scaffold CSS. Just like the Sass gem, we simply parse the scaffold.css in the default rails generator and save it as a scaffolds.css.less file. This is done automatically during other scaffold generator actions.
104
105
106
e7e6d64 @metaskills Make Travis CI use all ruby versions.
authored
107 ## Testing
108
5d060cb @metaskills Type in README.
authored
109 Simple! Just clone the repo, then run `bundle install` and `bundle exec rake`. The tests will begin to run. We also use Travis CI to run our tests too. Current build status is:
e7e6d64 @metaskills Make Travis CI use all ruby versions.
authored
110
111 [![Build Status](https://secure.travis-ci.org/metaskills/less-rails.png)](http://travis-ci.org/metaskills/less-rails)
112
113
114
b96b170 @metaskills Updating readme and make sure the LESS parser gets a :paths that incl…
authored
115 ## License
116
117 Less::Rails is Copyright (c) 2011 Ken Collins, <ken@metaskills.net> and is distributed under the MIT license.
118
Something went wrong with that request. Please try again.