Permalink
Browse files

middleware and executable

  • Loading branch information...
1 parent 11f2e03 commit 215870fcbf226e0980525e80fb6a8166338bce36 @collin committed Nov 30, 2009
Showing with 46 additions and 20 deletions.
  1. +2 −0 Rakefile.rb
  2. +4 −4 bin/jabs
  3. +10 −0 examples/config.ru
  4. +3 −3 lib/jabs.rb
  5. +27 −0 lib/jabs/middleware.rb
  6. +0 −13 lib/middleware.rb
View
@@ -56,6 +56,8 @@
gemspec.homepage = "http://github.com/collin/jabs"
gemspec.authors = ["Collin Miller"]
+ gemspec.executables << 'jabs'
+
gemspec.add_dependency('fold', '0.5.0')
gemspec.add_dependency('johnson', '1.1.2')
gemspec.add_dependency('colored', '1.1')
View
@@ -1,4 +1,4 @@
-ruby -e "\
-require 'rubygems'; require 'jabs'
-puts Jabs::Engine.new(STDIN.read).render
-"
+#!/usr/bin/env ruby -KU
+
+require 'jabs'
+puts Jabs::Engine.new(STDIN.read).render
View
@@ -0,0 +1,10 @@
+require 'lib/jabs'
+require 'pathname'
+
+puts Pathname.new(__FILE__).dirname.expand_path+'src'
+puts "OF"
+
+use Jabs::Rack::Static, :urls => '/src', :root => Pathname.new(__FILE__).dirname.expand_path
+run lambda { |env|
+ [200, {'Content-Type'=>'text/html'}, "JABS"]
+}
View
@@ -1,8 +1,8 @@
-#! /usr/bin/env ruby
-
-require 'rubygems'
require 'fold'
+require 'rack'
require 'johnson'
+require 'pathname'
+puts require Pathname.new(__FILE__).dirname.expand_path+'jabs/middleware'
module Johnson
module Nodes
View
@@ -0,0 +1,27 @@
+module Jabs
+
+ module Rack
+ class Static < ::Rack::Static
+ def initialize(app, options={})
+ super(app, options)
+ root = options[:root] || Dir.pwd
+ @file_server = Jabs::Rack::File.new(root)
+ end
+ end
+
+ class File < ::Rack::File
+ def serving
+ @path += ".jabs" unless @path[/\.jabs$/]
+ status, headers, body = * super
+ return [status, headers, body] unless status == 200
+
+ jabs = Jabs::Engine.new(open(body.path).read).render
+
+ headers['Content-Type'] = 'text/javascript'
+ headers['Content-Length'] = jabs.size.to_s
+
+ [status, headers, jabs]
+ end
+ end
+ end
+end
View
@@ -1,13 +0,0 @@
-require 'rack'
-
-module Jabs
- class Middleware < Rack::File
- def serving
- @path += ".jabs" unless @path[/\.jabs$/]
- status, headers, body = *super
- return [status, headers, body] unless status == 200
- headers['Content-Type'] = 'text/javascript'
- [status, headers, Jabs::Engine.new(body).render]
- end
- end
-end

0 comments on commit 215870f

Please sign in to comment.