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 +0 -3
- data/README.markdown +11 -11
- data/Rakefile +0 -2
- data/lib/rack/cappuccino.rb +31 -19
- data/spec/rack/cappuccino_spec.rb +27 -23
- data/spec/spec_helper.rb +2 -14
- metadata +3 -3
data/Gemfile.lock
CHANGED
data/README.markdown
CHANGED
@@ -1,26 +1,26 @@
|
|
1
1
|
# rack-cappuccino
|
2
2
|
|
3
|
-
Create a Rack app from your Cappuccino app.
|
3
|
+
Create a Rack app from your Cappuccino app.
|
4
4
|
|
5
5
|
## Usage
|
6
6
|
|
7
|
-
|
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
|
-
|
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
|
-
|
21
|
+
#### To run locally, from your Build/Release/APPNAME directory, run:
|
22
22
|
|
23
|
-
|
23
|
+
rackup
|
24
24
|
|
25
25
|
## Contributing to rack-cappuccino
|
26
26
|
|
data/Rakefile
CHANGED
data/lib/rack/cappuccino.rb
CHANGED
@@ -1,29 +1,41 @@
|
|
1
|
-
require "
|
2
|
-
require "rack/request"
|
1
|
+
require "sinatra"
|
3
2
|
|
4
3
|
module Rack
|
5
|
-
class Cappuccino
|
6
|
-
VERSION = "0.0.
|
4
|
+
class Cappuccino < Sinatra::Base
|
5
|
+
VERSION = "0.0.2"
|
7
6
|
|
8
|
-
|
7
|
+
# Caller from when this file is loaded. Includes +config.ru+
|
8
|
+
# which we need for +root+.
|
9
|
+
#
|
10
|
+
CALLER = caller
|
9
11
|
|
10
|
-
|
11
|
-
|
12
|
-
|
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
|
-
|
16
|
-
|
17
|
-
|
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
|
-
|
22
|
-
|
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
|
3
|
+
describe "Rack::Cappuccino" do
|
4
|
+
include Rack::Test::Methods
|
5
|
+
|
5
6
|
NOT_FOUND = 404
|
6
7
|
OK = 200
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
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
|
-
|
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
|
-
|
21
|
-
|
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
|
-
|
26
|
-
|
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
|
-
|
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
|
-
|
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
|
38
|
-
|
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
|
-
|
43
|
-
|
46
|
+
get "/"
|
47
|
+
last_response.status.should == OK
|
44
48
|
end
|
45
49
|
|
46
50
|
it "should handle css content-type" do
|
47
|
-
|
48
|
-
|
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
|
-
|
53
|
-
|
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/
|
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
|
-
-
|
9
|
-
version: 0.0.
|
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
|
+
date: 2010-11-19 00:00:00 -05:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|