rack-cappuccino 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/Gemfile.lock CHANGED
@@ -22,6 +22,3 @@ DEPENDENCIES
22
22
  rake
23
23
  rcov
24
24
  rspec (>= 2.0.0)
25
-
26
- METADATA
27
- version: 1.0.6
data/README.markdown CHANGED
@@ -1,26 +1,26 @@
1
1
  # rack-cappuccino
2
2
 
3
- Create a Rack app from your Cappuccino app. Makes it easy to quickly get a Cappuccino app online using Heroku.
3
+ Create a Rack app from your Cappuccino app.
4
4
 
5
5
  ## Usage
6
6
 
7
- Add a Gemfile in the root of your app with the following:
7
+ #### Build your Release target
8
+
9
+ jake release
10
+
11
+ #### Create a Gemfile in your Build/Release/APPNAME directory, with the following:
8
12
 
9
13
  source :rubygems
10
14
  gem "rack-cappuccino"
11
-
12
- Create a config.ru with the following:
13
15
 
14
- require "bundler/setup"
16
+ #### Create a config.ru in the same directory, with the following:
17
+
15
18
  require "rack/cappuccino"
16
-
17
- run Rack::Cappuccino.new(:appname => APPNAME)
18
-
19
- Replace APPNAME with the name of your app as it appears in the Build/Release directory.
19
+ run Rack::Cappuccino
20
20
 
21
- ## Build before you deploy
21
+ #### To run locally, from your Build/Release/APPNAME directory, run:
22
22
 
23
- Make sure you build your Release target before you deploy your app. Rack::Cappuccino uses it as the root directory for the Rack app.
23
+ rackup
24
24
 
25
25
  ## Contributing to rack-cappuccino
26
26
 
data/Rakefile CHANGED
@@ -1,5 +1,3 @@
1
- require 'bundler'
2
- Bundler.setup(:default, :development)
3
1
  require 'rspec/core/rake_task'
4
2
 
5
3
  RSpec::Core::RakeTask.new(:spec)
@@ -1,29 +1,41 @@
1
- require "pathname"
2
- require "rack/request"
1
+ require "sinatra"
3
2
 
4
3
  module Rack
5
- class Cappuccino
6
- VERSION = "0.0.1"
4
+ class Cappuccino < Sinatra::Base
5
+ VERSION = "0.0.2"
7
6
 
8
- attr_accessor :root
7
+ # Caller from when this file is loaded. Includes +config.ru+
8
+ # which we need for +root+.
9
+ #
10
+ CALLER = caller
9
11
 
10
- def initialize(*args)
11
- appname = args.last.delete(:appname)
12
- @root = "Build/Release/#{appname}"
12
+ # Little big of magic to find the directory of the +config.ru+
13
+ # file, ie: the root directory for our application.
14
+ #
15
+ # It looks through +CALLER+ for a call originating from +config.ru+,
16
+ # extracts it's relative path out and join it with +Dir.getwd+.
17
+ # This gives us the full path to +config.ru+ and subsequently
18
+ # the root of our app.
19
+ #
20
+ # If +config.ru+ was not used, it raises an error.
21
+ #
22
+ def self.root
23
+ config = CALLER.select { |c| c =~ /(config.ru)/ }.first
24
+ config = config.scan(/(^.*?config\.ru)/).flatten.first
25
+ ::File.dirname(::File.join(Dir.getwd, config))
26
+ rescue NoMethodError => e
27
+ raise "Rack::Cappuccino apps must be loaded from a config.ru file."
13
28
  end
14
29
 
15
- def call(env)
16
- info = Request.new(env).path_info
17
- info = "/index.html" if info == "/"
18
- path = Pathname.new(::File.join(@root, info))
19
- mime = Mime.mime_type(path.extname)
30
+ mime_type :plist, "application/octet-stream"
31
+ mime_type :sj, "application/octet-stream"
32
+ mime_type :cib, "application/octet-stream"
20
33
 
21
- if path.exist? && !path.directory? && path.to_s !~ /\.\./
22
- [200, { "Content-Type" => mime, "Content-Length" => path.size.to_s }, [path.read]]
23
- else
24
- [404, {"Content-Type" => "text/plain"}, [""]]
25
- end
26
- end
34
+ set :static, true
35
+ set :public, lambda { self.root }
27
36
 
37
+ get "/" do
38
+ send_file ::File.join(self.class.public, "index.html")
39
+ end
28
40
  end
29
41
  end
@@ -1,55 +1,59 @@
1
1
  require File.dirname(__FILE__) + '/../spec_helper'
2
2
 
3
- describe Rack::Cappuccino do
4
- include SpecHelper
3
+ describe "Rack::Cappuccino" do
4
+ include Rack::Test::Methods
5
+
5
6
  NOT_FOUND = 404
6
7
  OK = 200
7
-
8
- let(:resp) { get("/index.html") }
9
-
10
- it "should construct the root path based on 'appname'" do
11
- app = Rack::Cappuccino.new(:appname => "Hasslehoff")
12
- app.root.should == "Build/Release/Hasslehoff"
8
+
9
+ def app
10
+ support_root = File.expand_path("../../support", __FILE__)
11
+ Rack::Cappuccino.stub(:root).and_return(support_root)
12
+ Rack::Cappuccino
13
13
  end
14
14
 
15
15
  it "should send a 200" do
16
- resp.status.should == OK
16
+ get "/index.html"
17
+ last_response.status.should == OK
17
18
  end
18
19
 
19
20
  it "should return a 404 for non-existent resources" do
20
- resp = get("/doesnt_exist.html")
21
- resp.status.should == NOT_FOUND
21
+ get "/doesnt_exist.html"
22
+ last_response.status.should == NOT_FOUND
22
23
  end
23
24
 
24
25
  it "should not allow .. in the path" do
25
- resp = get("/../spec_helper.rb")
26
- resp.status.should == NOT_FOUND
26
+ get "/../spec_helper.rb"
27
+ last_response.status.should == NOT_FOUND
27
28
  end
28
29
 
29
30
  it "should have a content-length of 20" do
30
- resp.headers["Content-Length"].to_i.should == 20
31
+ get "/index.html"
32
+ last_response.headers["Content-Length"].to_i.should == 20
31
33
  end
32
34
 
33
35
  it "should handle html content-type" do
34
- resp.content_type.should == "text/html"
36
+ get "/index.html"
37
+ last_response.content_type.should =~ %r{text/html}
35
38
  end
36
39
 
37
- it "should have the file contents as the response body" do
38
- resp.body.should == "<h1>Hello World</h1>"
40
+ it "should have the file contents as the last_responseonse body" do
41
+ get "/index.html"
42
+ last_response.body.should == "<h1>Hello World</h1>"
39
43
  end
40
44
 
41
45
  it "should return the body on index.html if an empty path is given" do
42
- resp = get("/")
43
- resp.body.should == "<h1>Hello World</h1>"
46
+ get "/"
47
+ last_response.status.should == OK
44
48
  end
45
49
 
46
50
  it "should handle css content-type" do
47
- resp = get("/style.css")
48
- resp.content_type.should == "text/css"
51
+ get "/style.css"
52
+ last_response.content_type.should =~ %r{text/css}
49
53
  end
50
54
 
51
55
  it "should handle javascript content-type" do
52
- resp = get("/script.js")
53
- resp.content_type.should == "application/javascript"
56
+ get "/script.js"
57
+ last_response.content_type.should =~ %r{application/javascript}
54
58
  end
55
59
  end
data/spec/spec_helper.rb CHANGED
@@ -1,16 +1,4 @@
1
1
  require "rspec"
2
- require "rack/mock"
2
+ require "rack/test"
3
3
  $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
4
- require "rack/cappuccino"
5
-
6
- module SpecHelper
7
- def initialize
8
- @app = Rack::Cappuccino.new(:appname => "Foobar")
9
- @app.root = File.join(File.dirname(__FILE__), "support")
10
- end
11
-
12
- def get(path)
13
- request = Rack::MockRequest.new(@app)
14
- request.get(path)
15
- end
16
- end
4
+ require "rack/cappuccino"
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 0
8
- - 1
9
- version: 0.0.1
8
+ - 2
9
+ version: 0.0.2
10
10
  platform: ruby
11
11
  authors:
12
12
  - Matte Noble
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-11-17 00:00:00 -05:00
17
+ date: 2010-11-19 00:00:00 -05:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency