Skip to content

Commit

Permalink
middleware and executable
Browse files Browse the repository at this point in the history
  • Loading branch information
collin committed Nov 30, 2009
1 parent 11f2e03 commit 215870f
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 20 deletions.
2 changes: 2 additions & 0 deletions Rakefile.rb
Expand Up @@ -56,6 +56,8 @@
gemspec.homepage = "http://github.com/collin/jabs" gemspec.homepage = "http://github.com/collin/jabs"
gemspec.authors = ["Collin Miller"] gemspec.authors = ["Collin Miller"]


gemspec.executables << 'jabs'

gemspec.add_dependency('fold', '0.5.0') gemspec.add_dependency('fold', '0.5.0')
gemspec.add_dependency('johnson', '1.1.2') gemspec.add_dependency('johnson', '1.1.2')
gemspec.add_dependency('colored', '1.1') gemspec.add_dependency('colored', '1.1')
Expand Down
8 changes: 4 additions & 4 deletions bin/jabs
@@ -1,4 +1,4 @@
ruby -e "\ #!/usr/bin/env ruby -KU
require 'rubygems'; require 'jabs'
puts Jabs::Engine.new(STDIN.read).render require 'jabs'
" puts Jabs::Engine.new(STDIN.read).render
10 changes: 10 additions & 0 deletions examples/config.ru
@@ -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"]
}
6 changes: 3 additions & 3 deletions lib/jabs.rb
@@ -1,8 +1,8 @@
#! /usr/bin/env ruby

require 'rubygems'
require 'fold' require 'fold'
require 'rack'
require 'johnson' require 'johnson'
require 'pathname'
puts require Pathname.new(__FILE__).dirname.expand_path+'jabs/middleware'


module Johnson module Johnson
module Nodes module Nodes
Expand Down
27 changes: 27 additions & 0 deletions lib/jabs/middleware.rb
@@ -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
13 changes: 0 additions & 13 deletions lib/middleware.rb

This file was deleted.

0 comments on commit 215870f

Please sign in to comment.