Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 145 lines (113 sloc) 6.138 kb
0d08239 @mattly initial commit
authored
1 # rack-coffee
2
232646b @mattly use execjs instead of the shell
authored
3 Simple rack middleware for serving up [CoffeeScript][coffee] files as compiled
4 javascript.
0d08239 @mattly initial commit
authored
5
6 ## Usage
7
905ede2 @mattly to be clear
authored
8 The options behave similarly to Rack::Static:
232646b @mattly use execjs instead of the shell
authored
9
71fd29f @mattly :static parameter to enable passthrough of misses to the app (thanks …
authored
10 require 'rack/coffee'
232646b @mattly use execjs instead of the shell
authored
11 use Rack::Coffee,
f7d190d @mattly add Brian's Cache header stuff
authored
12 :root => '/path/to/directory/above/url',
13 :urls => '/javascipts'
232646b @mattly use execjs instead of the shell
authored
14
15 For rails, presuming you've required 'rack/coffee' somehow, stick this in the
16 Rails initializer config block:
bde2cc5 @mattly * documentation for Rails (thanks, weepy)
authored
17
18 config.middleware.use Rack::Coffee, :root => "#{RAILS_ROOT}/public"
19
232646b @mattly use execjs instead of the shell
authored
20 Note however that by default this will not play nicely with
21 `javascript_include_tag`'s `:cache` option, you would need to compile your
68a27f6 @mattly add :compile_cache option
authored
22 .coffee files before deploying. Alternately, use the rails asset pipeline.
71fd29f @mattly :static parameter to enable passthrough of misses to the app (thanks …
authored
23
f7d190d @mattly add Brian's Cache header stuff
authored
24 ## Options
25
26 * `:root`: the directory above `urls`. Defaults to `Dir.pwd`.
232646b @mattly use execjs instead of the shell
authored
27 * `:urls`: the directories in which to look for coffeescripts. May specify
28 a string or an array of strings. Defaults to `/javascripts`.
68a27f6 @mattly add :compile_cache option
authored
29 * `:cache-compile`: When truthy, will create and look for tempfiles with the
30 timestamp of the desired coffee file, and use those. Meant to speed up
31 development of projects with lots of coffee files.
32 * `:cache-control`: Sets a `Cache-Control` header if present. Defaults to false.
33 Values are interpreted like so:
23bc5e8 @mattly change :cache/:ttl to :cache_control
authored
34 - `true`: max-age=86400
35 - `3600`: max-age=3600
36 - `:public` or `'public'`: max-age=86400, public
37 - `[3600, :public]` or `%w(3600 public)`: max-age=3600, public
38 - `false` or `nil`: disables cache header
232646b @mattly use execjs instead of the shell
authored
39 * `:bare`: When `true`, disables the top-level function wrapper that
40 CoffeeScript uses by default.
e080cea @mattly prep for 0.9 release
authored
41 * `:join`: Set to a string, f.e. "index" to concat all the .coffee files before
42 compiling
f7d190d @mattly add Brian's Cache header stuff
authored
43
0d08239 @mattly initial commit
authored
44 ## Bugs?
45
bde2cc5 @mattly * documentation for Rails (thanks, weepy)
authored
46 * Let me know here: [Issue Tracking][issues]
0d08239 @mattly initial commit
authored
47
48 ## Requirements
49
232646b @mattly use execjs instead of the shell
authored
50 * [CoffeeScript Gem][coffee-gem] and therefore [execjs][]
0cf98ad @mattly compatibility with coffeescript 0.5.x
authored
51 * [Rack][rack]
0d08239 @mattly initial commit
authored
52
f7d190d @mattly add Brian's Cache header stuff
authored
53 ## Thanks
54
55 * Jeremy Ashkenas, for creating CoffeeScript
56 * Brian Mitchell, for picking up the slack on handling the 0.5 update
57
0d08239 @mattly initial commit
authored
58 ## History
59
232646b @mattly use execjs instead of the shell
authored
60 * March 18, 2012:
8b92ce1 @mattly remove :static option in favor of explicit Rack::File
authored
61 This release is **NOT BACKWARDS COMPATIBLE** with 0.9.x.
68a27f6 @mattly add :compile_cache option
authored
62 * added a `:cache_compile` option. If truthy, will cache the compiled coffee
63 to a tempfile timestamped with the modification time of the original.
23bc5e8 @mattly change :cache/:ttl to :cache_control
authored
64 * **BACKWARDS INCOMPATIBILITY** chance the `:cache` and `:ttl` options into
65 `:cache_control`. See documentation above for how the arguments work.
31e1e97 @mattly some refactoring
authored
66 * A fair bit of refactoring to make the main call method easier to follow.
8b92ce1 @mattly remove :static option in favor of explicit Rack::File
authored
67 * **BACKWARDS INCOMPATIBILITY** remove `:static` option. If you want to
68 serve stock javascript files from the same directory as your coffeescript
69 files, stick a Rack::File in your middleware stack after Rack::Coffee.
232646b @mattly use execjs instead of the shell
authored
70 * **BACKWARDS INCOMPATIBILITY** remove `:nowrap` option in favor of `:bare`
71 * Use `execjs` gem instead of coffee-script command. Thanks to [jewel][] for
72 kicking this off, even if I didn't use their code.
73
ce92615 @mattly fix :join problem, release 0.9.1
authored
74 * May 5, 2011: release 0.9.1
232646b @mattly use execjs instead of the shell
authored
75 * Fix a bug in the 'join' option to reflect how command-line -p actually
76 works
ce92615 @mattly fix :join problem, release 0.9.1
authored
77
e080cea @mattly prep for 0.9 release
authored
78 * May 3, 2011: release 0.9
232646b @mattly use execjs instead of the shell
authored
79 * Make '304 NOT MODIFIED' return a correct response body on Ruby 1.9
80 [Aanand Prasad][aanand]
e080cea @mattly prep for 0.9 release
authored
81 * Added 'join' option for concating your js
9b79fe9 @mattly update readme
authored
82
a69ee36 @mattly ready for release 0.3.3
authored
83 * January 21, 2011: release 0.3.3
84 Two changes by [Jonathan Baudanza][jbaudanza]:
232646b @mattly use execjs instead of the shell
authored
85 * changed --nowrap to --bare, per a recent change to coffee-script. You may
86 use :nowrap or :bare to indicate you want this
a69ee36 @mattly ready for release 0.3.3
authored
87 * return 304 NOT MODIFIED for caching purposes
88
9d8642b @mattly release 0.3.2, :nowrap
authored
89 * March 21, 2010: release 0.3.2
232646b @mattly use execjs instead of the shell
authored
90 * added :nowrap option to config, allowing the disabling of the top-level
91 function wrapper.
9d8642b @mattly release 0.3.2, :nowrap
authored
92
f7d190d @mattly add Brian's Cache header stuff
authored
93 * March 6, 2010: release 0.3.1
232646b @mattly use execjs instead of the shell
authored
94 * options now take :cache and :ttl options for setting cache headers, should
95 you decide to actually serve up hot coffeescripts outside of your
96 development environment. Via Brian Mitchell.
f7d190d @mattly add Brian's Cache header stuff
authored
97
0cf98ad @mattly compatibility with coffeescript 0.5.x
authored
98 * March 6, 2010: release 0.3 REQUIRES COFFEE-SCRIPT 0.5 OR HIGHER
232646b @mattly use execjs instead of the shell
authored
99 * CoffeeScript is now written in coffeescript. The included compiler is now
100 based on node.js instead of being hosted in a ruby gem, so we're shelling
101 out to the command-line interpreter. Thanks to [Brian Mitchell][binary42]
102 for doing most of the dirty work, at least as far as ruby 1.9 is
103 concerned.
0cf98ad @mattly compatibility with coffeescript 0.5.x
authored
104
ce62f09 @mattly 0.2 release
authored
105 * January 27, 2010: release 0.2 BACKWARDS INCOMPATIBLE
232646b @mattly use execjs instead of the shell
authored
106 * replace :url parameter in favor of :urls, now it behaves similarly to
107 Rack::Static (Brian Mitchell)
108 * add :static parameter, which when false will disable automatic asset
109 serving of url misses via Rack::File, instead passing through to the app.
ce62f09 @mattly 0.2 release
authored
110 * improve documentation for Rails
bde2cc5 @mattly * documentation for Rails (thanks, weepy)
authored
111 * remove dependency on Pathname, oh if only it were stdlib instead of extlib
112
113 * January 26, 2010: First public release 0.1.
0d08239 @mattly initial commit
authored
114
115 ## Copyright
116
a69ee36 @mattly ready for release 0.3.3
authored
117 Copyright (C) 2010 Matthew Lyon <matthew@lyonheart.us>
0d08239 @mattly initial commit
authored
118
119 Permission is hereby granted, free of charge, to any person obtaining a copy
120 of this software and associated documentation files (the "Software"), to
121 deal in the Software without restriction, including without limitation the
122 rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
123 sell copies of the Software, and to permit persons to whom the Software is
124 furnished to do so, subject to the following conditions:
125
126 The above copyright notice and this permission notice shall be included in
127 all copies or substantial portions of the Software.
128
129 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
130 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
131 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
132 THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
133 IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
bde2cc5 @mattly * documentation for Rails (thanks, weepy)
authored
134 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
135
87198c5 @mattly fix links in readme
authored
136 [coffee]: http://jashkenas.github.com/coffee-script/
232646b @mattly use execjs instead of the shell
authored
137 [coffee-gem]: https://github.com/josh/ruby-coffee-script
138 [execjs]: https://github.com/sstephenson/execjs
bde2cc5 @mattly * documentation for Rails (thanks, weepy)
authored
139 [issues]: http://github.com/mattly/rack-coffee/issues
0cf98ad @mattly compatibility with coffeescript 0.5.x
authored
140 [rack]: http://rack.rubyforge.org/
141 [binary42]: http://github.com/binary42
a69ee36 @mattly ready for release 0.3.3
authored
142 [jbaudanza]: https://github.com/jbaudanza
9b79fe9 @mattly update readme
authored
143 [aanand]: https://github.com/aanand
232646b @mattly use execjs instead of the shell
authored
144 [jewel]: https://github.com/jewel
Something went wrong with that request. Please try again.