cuba 0.0.1

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/LICENSE ADDED
@@ -0,0 +1,19 @@
1
+ Copyright (c) 2010 Michel Martens
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to deal
5
+ in the Software without restriction, including without limitation the rights
6
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ copies of the Software, and to permit persons to whom the Software is
8
+ furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in
11
+ all copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ THE SOFTWARE.
@@ -0,0 +1,86 @@
1
+ Cuba
2
+ ====
3
+
4
+ Rum based microframework for web development.
5
+
6
+ Description
7
+ -----------
8
+
9
+ Cuba is a light wrapper around [Rum](http://github.com/chneukirchen/rum), a tiny but powerful mapper for [Rack](http://github.com/chneukirchen/rack) applications.
10
+
11
+ It integrates [Haml](http://haml-lang.com/) templates via [Tilt](http://github.com/rtomayko/tilt), and testing via [Contest](http://github.com/citrusbyte/contest) and [Stories](http://github.com/citrusbyte/stories).
12
+
13
+ Usage
14
+ -----
15
+
16
+ Here's a simple application:
17
+
18
+ # cat hello_world.rb
19
+ require "cuba"
20
+
21
+ Cuba.define do
22
+ on get do
23
+ on path("hello") do
24
+ res.write "Hello world!"
25
+ end
26
+
27
+ on default do
28
+ res.redirect "/hello"
29
+ end
30
+ end
31
+ end
32
+
33
+ # cat hello_world_test.rb
34
+ require "cuba/test"
35
+
36
+ Cuba.test "My App" do
37
+ story "As a user I want to be greeted with a Hello world" do
38
+ scenario "A user visits the homepage" do
39
+ visit "/"
40
+
41
+ assert_contain "Hello world!"
42
+ end
43
+ end
44
+ end
45
+
46
+ To run it, you can create a `config.ru`:
47
+
48
+ # cat config.ru
49
+ require "hello_world"
50
+
51
+ run Cuba.app
52
+
53
+ That's it, you can now run `rackup` and enjoy what you have just created.
54
+
55
+ For more information about what you can do, check [Rum's documentation](http://github.com/chneukirchen/rum). To see how you can test it, check the documentation for [Stories](http://github.com/citrusbyte/stories).
56
+
57
+ Installation
58
+ ------------
59
+
60
+ $ sudo gem install cuba
61
+
62
+ License
63
+ -------
64
+
65
+ Copyright (c) 2010 Michel Martens
66
+
67
+ Permission is hereby granted, free of charge, to any person
68
+ obtaining a copy of this software and associated documentation
69
+ files (the "Software"), to deal in the Software without
70
+ restriction, including without limitation the rights to use,
71
+ copy, modify, merge, publish, distribute, sublicense, and/or sell
72
+ copies of the Software, and to permit persons to whom the
73
+ Software is furnished to do so, subject to the following
74
+ conditions:
75
+
76
+ The above copyright notice and this permission notice shall be
77
+ included in all copies or substantial portions of the Software.
78
+
79
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
80
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
81
+ OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
82
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
83
+ HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
84
+ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
85
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
86
+ OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,5 @@
1
+ task :test do
2
+ system "cd test && ruby cuba_test.rb"
3
+ end
4
+
5
+ task :default => :test
@@ -0,0 +1,17 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = "cuba"
3
+ s.version = "0.0.1"
4
+ s.summary = "Rum based microframework for web applications."
5
+ s.description = "Cuba is a light wrapper for Rum, a microframework for Rack applications."
6
+ s.authors = ["Michel Martens"]
7
+ s.email = ["michel@soveran.com"]
8
+ s.homepage = "http://github.com/soveran/cuba"
9
+ s.files = ["LICENSE", "README.markdown", "Rakefile", "lib/cuba/ron.rb", "lib/cuba/rum.rb", "lib/cuba/test.rb", "lib/cuba/version.rb", "lib/cuba.rb", "cuba.gemspec", "test/cuba_test.rb"]
10
+ s.add_dependency "rack", ">= 1.1.0"
11
+ s.add_dependency "haml", ">= 2.2.22"
12
+ s.add_dependency "tilt", ">= 0.9"
13
+ s.add_dependency "webrat", ">= 0.7.0"
14
+ s.add_dependency "contest", ">= 0.1.2"
15
+ s.add_dependency "stories", ">= 0.1.3"
16
+ s.add_dependency "rack-test", ">= 0.5.3"
17
+ end
@@ -0,0 +1,12 @@
1
+ require "cuba/version"
2
+ require "cuba/ron"
3
+
4
+ module Cuba
5
+ def self.define(&block)
6
+ @app = Ron.new(&block)
7
+ end
8
+
9
+ def self.app
10
+ @app
11
+ end
12
+ end
@@ -0,0 +1,11 @@
1
+ require "cuba/rum"
2
+ require "haml"
3
+ require "tilt"
4
+
5
+ module Cuba
6
+ class Ron < Rum
7
+ def haml(template, locals = {})
8
+ res.write Tilt::HamlTemplate.new("#{template}.haml").render(self, locals)
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,153 @@
1
+ # Rum, the gRand Unified Mapper
2
+ #
3
+ # Rum is a powerful mapper for your Rack applications that can be used
4
+ # as a microframework.
5
+ #
6
+ # More information at http://github.com/chneukirchen/rum
7
+ #
8
+ # == Copyright
9
+ #
10
+ # Copyright (C) 2008, 2009 Christian Neukirchen <http://purl.org/net/chneukirchen>
11
+ #
12
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
13
+ # of this software and associated documentation files (the "Software"), to
14
+ # deal in the Software without restriction, including without limitation the
15
+ # rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
16
+ # sell copies of the Software, and to permit persons to whom the Software is
17
+ # furnished to do so, subject to the following conditions:
18
+ #
19
+ # The above copyright notice and this permission notice shall be included in
20
+ # all copies or substantial portions of the Software.
21
+ #
22
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
23
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
25
+ # THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
26
+ # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
27
+ # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28
+ #
29
+ require 'rack'
30
+
31
+ class Rack::Response
32
+ # 301 Moved Permanently
33
+ # 302 Found
34
+ # 303 See Other
35
+ # 307 Temporary Redirect
36
+ def redirect(target, status=302)
37
+ self.status = status
38
+ self["Location"] = target
39
+ end
40
+ end
41
+
42
+ class Rum
43
+ attr_reader :env, :req, :res
44
+
45
+ def initialize(&blk)
46
+ @blk = blk
47
+ end
48
+
49
+ def call(env)
50
+ dup._call(env)
51
+ end
52
+
53
+ def _call(env)
54
+ @env = env
55
+ @req = Rack::Request.new(env)
56
+ @res = Rack::Response.new
57
+ @matched = false
58
+ catch(:rum_run_next_app) {
59
+ instance_eval(&@blk)
60
+ @res.status = 404 unless @matched || !@res.empty?
61
+ return @res.finish
62
+ }.call(env)
63
+ end
64
+
65
+ def on(*arg, &block)
66
+ return if @matched
67
+ s, p = env["SCRIPT_NAME"], env["PATH_INFO"]
68
+ yield *arg.map { |a| a == true || (a != false && a.call) || return }
69
+ env["SCRIPT_NAME"], env["PATH_INFO"] = s, p
70
+ @matched = true
71
+ end
72
+
73
+ def any(*args)
74
+ args.any? { |a| a == true || (a != false && a.call) }
75
+ end
76
+
77
+ def also
78
+ @matched = false
79
+ end
80
+
81
+ def path(p)
82
+ lambda {
83
+ if env["PATH_INFO"] =~ /\A\/(#{p})(\/|\z)/ #/
84
+ env["SCRIPT_NAME"] += "/#{$1}"
85
+ env["PATH_INFO"] = $2 + $'
86
+ $1
87
+ end
88
+ }
89
+ end
90
+
91
+ def number
92
+ path("\\d+")
93
+ end
94
+
95
+ def segment
96
+ path("[^\\/]+")
97
+ end
98
+
99
+ def extension(e="\\w+")
100
+ lambda { env["PATH_INFO"] =~ /\.(#{e})\z/ && $1 }
101
+ end
102
+
103
+ def param(p, default=nil)
104
+ lambda { req[p] || default }
105
+ end
106
+
107
+ def header(p, default=nil)
108
+ lambda { env[p.upcase.tr('-','_')] || default }
109
+ end
110
+
111
+ def default
112
+ true
113
+ end
114
+
115
+ def host(h)
116
+ req.host == h
117
+ end
118
+
119
+ def method(m)
120
+ req.request_method = m
121
+ end
122
+
123
+ def get; req.get?; end
124
+ def post; req.post?; end
125
+ def put; req.put?; end
126
+ def delete; req.delete?; end
127
+
128
+ def accept(mimetype)
129
+ lambda {
130
+ env['HTTP_ACCEPT'].split(',').any? { |s| s.strip == mimetype } and
131
+ res['Content-Type'] = mimetype
132
+ }
133
+ end
134
+
135
+ def check(&block)
136
+ block
137
+ end
138
+
139
+ def run(app)
140
+ throw :rum_run_next_app, app
141
+ end
142
+
143
+ def puts(*args)
144
+ args.each { |s|
145
+ res.write s
146
+ res.write "\n"
147
+ }
148
+ end
149
+
150
+ def print(*args)
151
+ args.each { |s| res.write s }
152
+ end
153
+ end
@@ -0,0 +1,25 @@
1
+ require "webrat"
2
+ require "rack/test"
3
+ require "stories"
4
+ require "stories/runner"
5
+
6
+ Webrat.configure do |config|
7
+ config.mode = :rack
8
+ end
9
+
10
+ class Test::Unit::TestCase
11
+ include Rack::Test::Methods
12
+ include Webrat::Methods
13
+ include Webrat::Matchers
14
+ include Stories::Webrat
15
+
16
+ def app
17
+ Cuba.app
18
+ end
19
+ end
20
+
21
+ module Cuba
22
+ def self.test(name, &block)
23
+ Test::Unit::TestCase.context(name, &block)
24
+ end
25
+ end
@@ -0,0 +1,3 @@
1
+ module Cuba
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,45 @@
1
+ $:.unshift(File.join("..", "lib"))
2
+
3
+ require "cuba"
4
+ require "cuba/test"
5
+
6
+ form = <<EOS
7
+ <form action="/login" method="post">
8
+ <input name="user">
9
+ <input type="submit" value="Login">
10
+ </form>
11
+ EOS
12
+
13
+ Cuba.define do
14
+ on get do
15
+ on path("login") do
16
+ res.write "Enter your username"
17
+ res.write form
18
+ end
19
+
20
+ on default do
21
+ res.redirect "/login"
22
+ end
23
+ end
24
+
25
+ on post, path("login") do
26
+ on param("user") do |user|
27
+ res.write "Got #{user}"
28
+ end
29
+ end
30
+ end
31
+
32
+ Cuba.test "Sample Site" do
33
+ story "As a user I want to be able to login" do
34
+ scenario "A user submits good info" do
35
+ visit "/"
36
+
37
+ assert_contain "Enter your username"
38
+
39
+ fill_in "user", :with => "Michel"
40
+ click_button "Login"
41
+
42
+ assert_contain "Got Michel"
43
+ end
44
+ end
45
+ end
metadata ADDED
@@ -0,0 +1,168 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cuba
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 0
8
+ - 1
9
+ version: 0.0.1
10
+ platform: ruby
11
+ authors:
12
+ - Michel Martens
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-04-25 00:00:00 -03:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: rack
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ segments:
28
+ - 1
29
+ - 1
30
+ - 0
31
+ version: 1.1.0
32
+ type: :runtime
33
+ version_requirements: *id001
34
+ - !ruby/object:Gem::Dependency
35
+ name: haml
36
+ prerelease: false
37
+ requirement: &id002 !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ segments:
42
+ - 2
43
+ - 2
44
+ - 22
45
+ version: 2.2.22
46
+ type: :runtime
47
+ version_requirements: *id002
48
+ - !ruby/object:Gem::Dependency
49
+ name: tilt
50
+ prerelease: false
51
+ requirement: &id003 !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ segments:
56
+ - 0
57
+ - 9
58
+ version: "0.9"
59
+ type: :runtime
60
+ version_requirements: *id003
61
+ - !ruby/object:Gem::Dependency
62
+ name: webrat
63
+ prerelease: false
64
+ requirement: &id004 !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ segments:
69
+ - 0
70
+ - 7
71
+ - 0
72
+ version: 0.7.0
73
+ type: :runtime
74
+ version_requirements: *id004
75
+ - !ruby/object:Gem::Dependency
76
+ name: contest
77
+ prerelease: false
78
+ requirement: &id005 !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ segments:
83
+ - 0
84
+ - 1
85
+ - 2
86
+ version: 0.1.2
87
+ type: :runtime
88
+ version_requirements: *id005
89
+ - !ruby/object:Gem::Dependency
90
+ name: stories
91
+ prerelease: false
92
+ requirement: &id006 !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ segments:
97
+ - 0
98
+ - 1
99
+ - 3
100
+ version: 0.1.3
101
+ type: :runtime
102
+ version_requirements: *id006
103
+ - !ruby/object:Gem::Dependency
104
+ name: rack-test
105
+ prerelease: false
106
+ requirement: &id007 !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ segments:
111
+ - 0
112
+ - 5
113
+ - 3
114
+ version: 0.5.3
115
+ type: :runtime
116
+ version_requirements: *id007
117
+ description: Cuba is a light wrapper for Rum, a microframework for Rack applications.
118
+ email:
119
+ - michel@soveran.com
120
+ executables: []
121
+
122
+ extensions: []
123
+
124
+ extra_rdoc_files: []
125
+
126
+ files:
127
+ - LICENSE
128
+ - README.markdown
129
+ - Rakefile
130
+ - lib/cuba/ron.rb
131
+ - lib/cuba/rum.rb
132
+ - lib/cuba/test.rb
133
+ - lib/cuba/version.rb
134
+ - lib/cuba.rb
135
+ - cuba.gemspec
136
+ - test/cuba_test.rb
137
+ has_rdoc: true
138
+ homepage: http://github.com/soveran/cuba
139
+ licenses: []
140
+
141
+ post_install_message:
142
+ rdoc_options: []
143
+
144
+ require_paths:
145
+ - lib
146
+ required_ruby_version: !ruby/object:Gem::Requirement
147
+ requirements:
148
+ - - ">="
149
+ - !ruby/object:Gem::Version
150
+ segments:
151
+ - 0
152
+ version: "0"
153
+ required_rubygems_version: !ruby/object:Gem::Requirement
154
+ requirements:
155
+ - - ">="
156
+ - !ruby/object:Gem::Version
157
+ segments:
158
+ - 0
159
+ version: "0"
160
+ requirements: []
161
+
162
+ rubyforge_project:
163
+ rubygems_version: 1.3.6
164
+ signing_key:
165
+ specification_version: 3
166
+ summary: Rum based microframework for web applications.
167
+ test_files: []
168
+