Skip to content

Commit

Permalink
compatibility with coffeescript 0.5.x
Browse files Browse the repository at this point in the history
  • Loading branch information
Matt Lyon committed Mar 7, 2010
2 parents ce62f09 + a2c0735 commit 0cf98ad
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 20 deletions.
7 changes: 3 additions & 4 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -20,26 +20,25 @@ else
task "rack-coffee.gemspec" do
spec = Gem::Specification.new do |s|
s.name = "rack-coffee"
s.version = "0.2.0"
s.version = "0.3.0"
s.platform = Gem::Platform::RUBY
s.summary = "serve up coffeescript from rack middleware"

s.description = <<-EOF
Rack Middlware for compiling and serving .coffee files using coffee-script; "/javascripts/app.js" compiles and serves "/javascipts/app.coffee". If there is no .coffee file, passes to Rack::File in case there's a .js file (or other asset) with the requested url.
Rack Middlware for compiling and serving .coffee files using coffee-script; "/javascripts/app.js" compiles and serves "/javascipts/app.coffee". If there is no .coffee file, can either pass to Rack::File in case there's a .js file (or other asset) with the requested url, or pass entirely.
EOF

s.files = `git ls-files`.split("\n")
s.require_path = 'lib'
s.has_rdoc = false
s.test_files = Dir['test/*_test.rb']

s.author = 'Matthew Lyon'
s.authors = ['Matthew Lyon', 'Brian Mitchell']
s.email = 'matt@flowerpowered.com'
s.homepage = 'http://github.com/mattly/rack-coffee'
s.rubyforge_project = 'rack-coffee'

s.add_dependency 'rack'
s.add_dependency 'coffee-script'
end

File.open("rack-coffee.gemspec", "w") { |f| f << spec.to_ruby }
Expand Down
12 changes: 9 additions & 3 deletions Readme.mkdn
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# rack-coffee

Simple rack middleware for serving up [CoffeeScript][coffeescript] files as compiled javascript.
Simple rack middleware for serving up [CoffeeScript][coffee] files as compiled javascript.

## Usage

Expand All @@ -26,11 +26,14 @@ Note however that by default this will not play nicely with `javascript_include_

## Requirements

* coffee-script
* rack
* [CoffeeScript][coffee] and [node.js][node] which coffee-script now depends on.
* [Rack][rack]

## History

* 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][binary42] 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.
Expand Down Expand Up @@ -63,3 +66,6 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
[coffeescript]: http://jashkenas.github.com/coffee-script/
[bistrocar]: http://github.com/jnicklas/bistro_car
[issues]: http://github.com/mattly/rack-coffee/issues
[node]: http://nodejs.org/
[rack]: http://rack.rubyforge.org/
[binary42]: http://github.com/binary42
7 changes: 5 additions & 2 deletions lib/rack/coffee.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
require 'time'
require 'coffee-script'
require 'rack/file'
require 'rack/utils'

Expand All @@ -18,14 +17,18 @@ def initialize(app, opts={})
@server = opts[:static] ? Rack::File.new(root) : app
end

def brew(coffee)
IO.popen(['coffee', '-p', coffee].join(' '))
end

def call(env)
path = Utils.unescape(env["PATH_INFO"])
return [403, {"Content-Type" => "text/plain"}, ["Forbidden\n"]] if path.include?('..')
return @app.call(env) unless urls.any?{|url| path.index(url) == 0} and (path =~ /\.js$/)
coffee = F.join(root, path.sub(/\.js$/,'.coffee'))
if F.file?(coffee)
headers = {"Content-Type" => "application/javascript", "Last-Modified" => F.mtime(coffee).httpdate}
[200, headers, [CoffeeScript.compile(F.read(coffee))]]
[200, headers, brew(coffee)]
else
@server.call(env)
end
Expand Down
13 changes: 5 additions & 8 deletions rack-coffee.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@

Gem::Specification.new do |s|
s.name = %q{rack-coffee}
s.version = "0.2.0"
s.version = "0.3.0"

s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.authors = ["Matthew Lyon"]
s.date = %q{2010-01-28}
s.description = %q{Rack Middlware for compiling and serving .coffee files using coffee-script; "/javascripts/app.js" compiles and serves "/javascipts/app.coffee". If there is no .coffee file, passes to Rack::File in case there's a .js file (or other asset) with the requested url.
s.authors = ["Matthew Lyon", "Brian Mitchell"]
s.date = %q{2010-03-06}
s.description = %q{Rack Middlware for compiling and serving .coffee files using coffee-script; "/javascripts/app.js" compiles and serves "/javascipts/app.coffee". If there is no .coffee file, can either pass to Rack::File in case there's a .js file (or other asset) with the requested url, or pass entirely.
}
s.email = %q{matt@flowerpowered.com}
s.files = ["Rakefile", "Readme.mkdn", "lib/rack/coffee.rb", "rack-coffee.gemspec", "test/javascripts/static.js", "test/javascripts/test.coffee", "test/other_javascripts/test.coffee", "test/rack_coffee_test.rb"]
s.files = [".gitignore", "Rakefile", "Readme.mkdn", "lib/rack/coffee.rb", "rack-coffee.gemspec", "test/javascripts/static.js", "test/javascripts/test.coffee", "test/other_javascripts/test.coffee", "test/rack_coffee_test.rb"]
s.homepage = %q{http://github.com/mattly/rack-coffee}
s.require_paths = ["lib"]
s.rubyforge_project = %q{rack-coffee}
Expand All @@ -24,13 +24,10 @@ Gem::Specification.new do |s|

if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
s.add_runtime_dependency(%q<rack>, [">= 0"])
s.add_runtime_dependency(%q<coffee-script>, [">= 0"])
else
s.add_dependency(%q<rack>, [">= 0"])
s.add_dependency(%q<coffee-script>, [">= 0"])
end
else
s.add_dependency(%q<rack>, [">= 0"])
s.add_dependency(%q<coffee-script>, [">= 0"])
end
end
10 changes: 7 additions & 3 deletions test/rack_coffee_test.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
require 'test/unit'
require 'rack/mock'
require 'rack/lint'
require 'ruby-debug'
begin
require 'rack/mock'
require 'rack/lint'
rescue LoadError
require 'rubygems'
retry
end

require File.dirname(__FILE__) + "/../lib/rack/coffee"

Expand Down

0 comments on commit 0cf98ad

Please sign in to comment.