Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

serve up coffeescript from rack middleware

branch: master

Fetching latest commit…

Octocat-spinner-32-eaf2f5

Cannot retrieve the latest commit at this time

Octocat-spinner-32 lib
Octocat-spinner-32 test
Octocat-spinner-32 .gitignore
Octocat-spinner-32 Rakefile
Octocat-spinner-32 Readme.mkdn
Octocat-spinner-32 rack-coffee.gemspec
Readme.mkdn

rack-coffee

Simple rack middleware for serving up CoffeeScript files as compiled javascript.

Usage

The options behave similarly to Rack::Static:

require 'rack/coffee'
use Rack::Coffee, {
    :root => '/path/to/directory/above/url',
    :urls => '/javascipts'
}

For rails, presuming you've required 'rack/coffee' somehow, stick this in the Rails initializer config block:

config.middleware.use Rack::Coffee, :root => "#{RAILS_ROOT}/public"

Note however that by default this will not play nicely with javascript_include_tag's :cache option, you would need to compile your .coffee files before deploying. Alternately, check out the BistroCar rails plugin that plays nicely with rails asset handling.

Options

  • :root: the directory above urls. Defaults to Dir.pwd.
  • :urls: the directories in which to look for coffeescripts. May specify a string or an array of strings. Defaults to /javascripts.
  • :static: Whether to serve any static assets found in your urls (via Rack::File). Defaults to true; Specify false to pass through to your app.
  • :cache: Sets a Cache-Control header if truthy, public if set to :public
  • :ttl: The default max-age value for the Cache-Control header. Defaults to 86400.
  • :nowrap: When true, disables the top-level function wrapper that CoffeeScript uses by default.

Bugs?

Requirements

Thanks

  • Jeremy Ashkenas, for creating CoffeeScript
  • Brian Mitchell, for picking up the slack on handling the 0.5 update

History

  • January 21, 2011: release 0.3.3 Two changes by Jonathan Baudanza:

    • changed --nowrap to --bare, per a recent change to coffee-script. You may use :nowrap or :bare to indicate you want this
    • return 304 NOT MODIFIED for caching purposes
  • March 21, 2010: release 0.3.2

    • added :nowrap option to config, allowing the disabling of the top-level function wrapper.
  • March 6, 2010: release 0.3.1

    • options now take :cache and :ttl options for setting cache headers, should you decide to actually serve up hot coffeescripts outside of your development environment. Via Brian Mitchell.
  • March 6, 2010: release 0.3 REQUIRES COFFEE-SCRIPT 0.5 OR HIGHER

    • CoffeeScript is now written in coffeescript. The included compiler is now based on node.js instead of being hosted in a ruby gem, so we're shelling out to the command-line interpreter. Thanks to Brian Mitchell for doing most of the dirty work, at least as far as ruby 1.9 is concerned.
  • January 27, 2010: release 0.2 BACKWARDS INCOMPATIBLE

    • replace :url parameter in favor of :urls, now it behaves similarly to Rack::Static (Brian Mitchell)
    • add :static parameter, which when false will disable automatic asset serving of url misses via Rack::File, instead passing through to the app.
    • improve documentation for Rails
    • remove dependency on Pathname, oh if only it were stdlib instead of extlib
  • January 26, 2010: First public release 0.1.

Copyright

Copyright (C) 2010 Matthew Lyon matthew@lyonheart.us

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 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.

Something went wrong with that request. Please try again.