Giter Site home page Giter Site logo

cruller's Introduction

Cruller

Cruller is a gem for nicely dealing with CoffeeScript files in a Sinatra app that you might want to deploy on a production system, and thus don't want CoffeeScript compiling all the time, or your evil sysadmin might not want to install Node (no idea why!).

It deals best in the following situation:

  • In development, all requests are being handled directly by Sinatra including static files
  • In production, some requests (e.g. for /public/ files) are handled by the web server in front of Sinatra.

In this ideal situation it will nicely compile cached copies for you in development, but be bypassed in production.

Usage

Standalone

First, you'll need to configure Cruller (unless you are happy with it's defaults):

Cruller.configure {:source => "path/to/coffeescripts",
                   :destination => "path/to/javascript/output",
                   :path => "/url/for/javascripts",
                   :compile => "auto"}

Cruller takes 4 parameters:

  • source: the location where your CoffeeScript files are located.
  • destination: where you want the compiled Javascript to be written to. Any existing Javascript files will be served from here too.
  • path: The URL for your Javascripts.
  • compile: Whether you want to always compile CoffeeScript when a request is made, automatically compile it based on modified time, or never compile the CoffeeScript and only ever serve cached files.

Now, you can brew CoffeeScript! The command is simple:

Cruller.brew("name_of_js")

It doesn't matter if the name has .coffee or .js in it. Cruller will strip that away. The command returns either the string of CoffeeScript, or false if Cruller couldn't find anything to brew or return to you.

Middleware

Cruller has some middleware that you can use in your Rack app which will allow you to compile CoffeeScript to a folder normally handled directly by the Rack server (e.g. the public directory):

use Cruller::Server

to your config.ru file before your actual Rack app, and then configure Cruller before your app serves any requests (otherwise it will use default settings) using Cruller.configure.

Sinatra

In Sinatra you can use the middleware by adding the configuration + use call in your configure block. The following example would stop Cruller being used in production (reverting to the cache)

configure do |app|
  Cruller.configure( {:source => "views/coffeescripts",
                      :destination => "public/javascripts"} )

  app.use Cruller::Server if settings.environment == :development
end 

Ruby on Rails

With Rails 3 you can either put the use line in your config.ru file as above or you can add a config line in application.rb or development.rb if you just want Cruller to compile CoffeeScript in development:

config.middleware.use Cruller::Server

Then you can configure Cruller wherever you like. I add a file called cruller.rb to my initializers folder:

Cruller.configure({
  :source => "app/views/coffeescripts",
  :destination => "public/javascripts",
  :path => "/javascripts",
  :compile => "auto"
})

Contributing to Cruller

  • Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
  • Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
  • Fork the project
  • Start a feature/bugfix branch
  • Commit and push until you are happy with your contribution
  • Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
  • Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.

Copyright

Copyright (c) 2011 David Somers. See LICENSE.txt for further details.

cruller's People

Contributors

jalada avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar

cruller's Issues

Support subdirectories

You can't put coffeescript in subdirectories right now, fix that!

  • Brew stuff in subdirectories
  • Write cache out to subdirectory (creating a directory if necessary)

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.