Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 107 lines (70 sloc) 4.143 kb
43fc497 @lucasmazza Licensing and readme
authored
1 # Stylus for Rails apps
2
83c9be0 @lucasmazza doc tweaks.
authored
3 A gem to compile your [Stylus](https://github.com/LearnBoost/stylus) stylesheets in your ruby apps.
43fc497 @lucasmazza Licensing and readme
authored
4
4750c38 @lucasmazza the new gem is out
authored
5 ### Rails 3.1? Sprockets and stuff?
6 Check the new [stylus](https://github.com/lucasmazza/ruby-stylus) gem.
7
43fc497 @lucasmazza Licensing and readme
authored
8 ## Installation
9
83c9be0 @lucasmazza doc tweaks.
authored
10 Just add `gem 'stylus_rails'` To your `Gemfile`. Rails will load the Stylus Railtie on your app on the development environment, and classic Sinatra applications will have an extension registered on your current application. On any other cenario you can run `Stylus.compile` inside your ruby code.
43fc497 @lucasmazza Licensing and readme
authored
11
12 ## Folders
13
83c9be0 @lucasmazza doc tweaks.
authored
14 By default, `stylus_rails` will compile all files at `public/stylesheets/stylus` to the `public/stylesheets` folder. For instance, `public/stylesheets/stylus/application.styl` would generate `public/stylesheets/application.css`.
15
16 To change this behavior, on Rails apps, you can drop some configurations in an initializer to override the default paths.
1ba81db @sebastiandeutsch Upated the readme with the compile_directory
sebastiandeutsch authored
17
18 Stylus.root = File.join(Rails.root, 'app')
19 Stylus.directory = 'stylus'
20 Stylus.compile_directory = File.join(Rails.root, 'public', 'stylesheets')
43fc497 @lucasmazza Licensing and readme
authored
21
d0f4ff7 @lucasmazza Changing the Sinatra middleware in favor of a extension and adding docs
authored
22 ## Sinatra
23
83c9be0 @lucasmazza doc tweaks.
authored
24 We all love [Sinatra](http://www.sinatrarb.com/), so we have a extension to your Sinatra applications.
25 When using classic applications, just requiring `stylus_rails` will load the extension inside the Sinatra stack. When going modular, you will need to register it yourself.
d0f4ff7 @lucasmazza Changing the Sinatra middleware in favor of a extension and adding docs
authored
26
27 require 'sinatra'
28 require 'stylus_rails'
29
30 class MyApp < Sinatra::Base
31 register Stylus::Sinatra
32
33 get '/' do
34 'oh hai'
35 end
36 end
37
38 You can also customize the `root` and `compile_directory` options using the Sinatra settings:
39
40 # storing your .styl files in ./styl ...
41 set :stylus_root, File.dirname(__FILE__)
42 # and compiling to ./public/stylesheets
43 set :stylus_directory, File.join(setting.public, 'stylesheets')
44
45
906f435 @lucasmazza Renaming the rake file and adding docs about the rake task.
authored
46 ## Rake task
47
83c9be0 @lucasmazza doc tweaks.
authored
48 `stylus_rails` bundles a rake task `stylus:compile` to recompile your `.styl` files whenever necessary. Just add the following to your Rakefile:
906f435 @lucasmazza Renaming the rake file and adding docs about the rake task.
authored
49
83c9be0 @lucasmazza doc tweaks.
authored
50 require 'stylus_rails'
906f435 @lucasmazza Renaming the rake file and adding docs about the rake task.
authored
51 load 'stylus_rails/tasks/compile.rake'
52
83c9be0 @lucasmazza doc tweaks.
authored
53 **NOTE** - *This task is included automatically on Rails apps, so you don't need to do this.*
54
55 ## Partials
56
57 `stylus_rails` will skip all files starting with `_`, so you can use this naming convention on your partial files and import them on other files.
58
59 So, let's say that you have the following `_vendor.styl`:
60
61 border-radius()
62 -webkit-border-radius arguments
63 -moz-border-radius arguments
64 border-radius arguments
65
66 And a `application.styl`
67
68 @import '_mixins'
69 .button
70 border-radius 5px
71
72 Stylus will compile your `application.styl` into a `application.css` and your `_vendor.styl` will be ignored.
a932072 @lucasmazza docs
authored
73
1866bd9 @sebastiandeutsch Added Error Handling section to README
sebastiandeutsch authored
74 ## Error Handling
75
76 If the stylus binary exits with error code 1 stylus_rails will throw an error exception. In case you don't want
77 this the behaviour can be switched to silent by setting the following variable to false:
78
79 Stylus.silent = true
80
35e7402 @lucasmazza changelog added
authored
81 ## Changelog
82 [here.](https://github.com/lucasmazza/stylus_rails/blob/master/CHANGELOG.md)
83
43fc497 @lucasmazza Licensing and readme
authored
84 ## License
85
86 (The MIT License)
87
88 Copyright (c) 2011 Lucas Mazza &lt;luc4smazza@gmail.com&gt;
89
90 Permission is hereby granted, free of charge, to any person obtaining
91 a copy of this software and associated documentation files (the
92 'Software'), to deal in the Software without restriction, including
93 without limitation the rights to use, copy, modify, merge, publish,
94 distribute, sublicense, and/or sell copies of the Software, and to
95 permit persons to whom the Software is furnished to do so, subject to
96 the following conditions:
97
98 The above copyright notice and this permission notice shall be
99 included in all copies or substantial portions of the Software.
100
101 THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
102 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
103 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
104 IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
105 CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
106 TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
107 SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Something went wrong with that request. Please try again.