Giter Site home page Giter Site logo

stylus_rails's Introduction

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 <[email protected]>

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.

stylus_rails's People

Contributors

lucasmazza avatar sebastiandeutsch avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

stylus_rails's Issues

ExecJS instead of system call

With ExecJS and a customized compile script (instead of the stylus binary) we would have more control over the compiling process and would be able to use the nib package if available.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.