• Watch
    Notification status
    • Watch
    • Unwatch
    • Stop ignoring
  • Unstar Star
  • Fork

public / stylus_rails

Stylus love inside your ruby code. Read more

Read-Only access

README.md

Stylus for Rails apps

A gem to compile your Stylus stylesheets in your ruby apps.

Rails 3.1? Sprockets and stuff?

Check the new stylus gem.

Installation

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.

Folders

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.

To change this behavior, on Rails apps, you can drop some configurations in an initializer to override the default paths.

Stylus.root = File.join(Rails.root, 'app')
Stylus.directory = 'stylus'
Stylus.compile_directory = File.join(Rails.root, 'public', 'stylesheets')

Sinatra

We all love Sinatra, so we have a extension to your Sinatra applications. 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.

require 'sinatra'
require 'stylus_rails'

class MyApp < Sinatra::Base
  register Stylus::Sinatra

  get '/' do
    'oh hai'
  end
end

You can also customize the root and compile_directory options using the Sinatra settings:

# storing your .styl files in ./styl ...
set :stylus_root, File.dirname(__FILE__)
# and compiling to ./public/stylesheets
set :stylus_directory, File.join(setting.public, 'stylesheets')

Rake task

stylus_rails bundles a rake task stylus:compile to recompile your .styl files whenever necessary. Just add the following to your Rakefile:

require 'stylus_rails'
load 'stylus_rails/tasks/compile.rake'

NOTE - This task is included automatically on Rails apps, so you don't need to do this.

Partials

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.

So, let's say that you have the following _vendor.styl:

border-radius()
  -webkit-border-radius arguments
  -moz-border-radius arguments
  border-radius arguments

And a application.styl

@import '_mixins'
.button
  border-radius 5px

Stylus will compile your application.styl into a application.css and your _vendor.styl will be ignored.

Error Handling

If the stylus binary exits with error code 1 stylus_rails will throw an error exception. In case you don't want this the behaviour can be switched to silent by setting the following variable to false:

Stylus.silent = true

Changelog

here.

License

(The MIT License)

Copyright (c) 2011 Lucas Mazza <luc4smazza@gmail.com>

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.



Markdown Cheat Sheet

Format Text

Headers

# This is an <h1> tag
## This is an <h2> tag
###### This is an <h6> tag

Text styles

*This text will be italic*
_This will also be italic_
**This text will be bold**
__This will also be bold__

*You **can** combine them*

Lists

Unordered

* Item 1
* Item 2
  * Item 2a
  * Item 2b

Ordered

1. Item 1
2. Item 2
3. Item 3
   * Item 3a
   * Item 3b

Miscellaneous

Images

![GitHub Logo](/images/logo.png)
Format: ![Alt Text](url)

Links

http://github.com - automatic!
[GitHub](http://github.com)

Blockquotes

As Kanye West said:

> We're living the future so
> the present is our past.

Code Examples in Markdown

Syntax highlighting with GFM

```javascript
function fancyAlert(arg) {
  if(arg) {
    $.facebox({div:'#foo'})
  }
}
```

Or, indent your code 4 spaces

Here is a Python code example
without syntax highlighting:

    def foo:
      if not bar:
        return true

Inline code for comments

I think you should use an
`<addr>` element here instead.
Something went wrong with that request. Please try again.

Looking for the GitHub logo?