renee 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +8 -0
- data/examples/blog/blog.rb +48 -0
- data/examples/blog/config.ru +40 -0
- data/examples/blog/views/edit.erb +1 -0
- data/examples/blog/views/index.erb +18 -0
- data/examples/blog/views/show.erb +5 -0
- data/lib/renee.rb +33 -0
- data/lib/renee/version.rb +3 -0
- data/renee.gemspec +31 -0
- data/test/blog_test.rb +78 -0
- data/test/test_helper.rb +57 -0
- metadata +204 -0
data/Rakefile
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
class Blog
|
2
|
+
attr_reader :posts
|
3
|
+
|
4
|
+
def initialize
|
5
|
+
@posts = []
|
6
|
+
@post_id = 0
|
7
|
+
end
|
8
|
+
|
9
|
+
def new_post(title, contents)
|
10
|
+
@posts << Post.new(self, @post_id += 1, title, contents)
|
11
|
+
end
|
12
|
+
|
13
|
+
def find_post(id)
|
14
|
+
@posts.find{|p| p.id == id}
|
15
|
+
end
|
16
|
+
|
17
|
+
def delete_post(post)
|
18
|
+
@posts.delete(post)
|
19
|
+
end
|
20
|
+
|
21
|
+
class Post
|
22
|
+
attr_reader :id, :created_at, :updated_at
|
23
|
+
attr_accessor :title, :contents
|
24
|
+
|
25
|
+
def initialize(blog, id, title, contents)
|
26
|
+
@blog, @id, @title, @contents, @created_at = blog, id, title, contents, Time.new
|
27
|
+
@updated_at = @created_at
|
28
|
+
end
|
29
|
+
|
30
|
+
def touch!
|
31
|
+
@updated_at = Time.new
|
32
|
+
end
|
33
|
+
|
34
|
+
def title=(title)
|
35
|
+
touch!
|
36
|
+
@title = title
|
37
|
+
end
|
38
|
+
|
39
|
+
def contents=(contents)
|
40
|
+
touch!
|
41
|
+
@contents = contents
|
42
|
+
end
|
43
|
+
|
44
|
+
def delete!
|
45
|
+
@blog.delete_post(self)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
$: << File.expand_path("../../lib", File.dirname(__FILE__))
|
2
|
+
$: << File.dirname(__FILE__)
|
3
|
+
require 'renee'
|
4
|
+
require 'blog'
|
5
|
+
require 'json'
|
6
|
+
|
7
|
+
blog = Blog.new
|
8
|
+
|
9
|
+
run Renee {
|
10
|
+
@blog = blog
|
11
|
+
|
12
|
+
# find blog post and do things to it.
|
13
|
+
var Integer do |id|
|
14
|
+
@post = @blog.find_post(id)
|
15
|
+
halt 404 unless @post
|
16
|
+
path('edit') { render! 'edit' }
|
17
|
+
|
18
|
+
get { render! 'show' }
|
19
|
+
delete { @post.delete!; halt :ok }
|
20
|
+
put {
|
21
|
+
@post.title = request['title'] if request['title']
|
22
|
+
@post.contents = request['contents'] if request['contents']
|
23
|
+
halt :ok
|
24
|
+
}
|
25
|
+
end
|
26
|
+
|
27
|
+
post {
|
28
|
+
if request['title'] && request['contents']
|
29
|
+
@blog.new_post(request['title'], request['contents'])
|
30
|
+
halt :created
|
31
|
+
else
|
32
|
+
halt :bad_request
|
33
|
+
end
|
34
|
+
}
|
35
|
+
|
36
|
+
extension('json') { get { halt @blog.posts.map{ |p| {:contents => p.contents} }.to_json } }
|
37
|
+
no_extension { get { render! 'index' } }
|
38
|
+
}.setup {
|
39
|
+
views_path File.expand_path(File.dirname(__FILE__) + "/views")
|
40
|
+
}
|
@@ -0,0 +1 @@
|
|
1
|
+
Editing <%= @post.title %>
|
@@ -0,0 +1,18 @@
|
|
1
|
+
<% @blog.posts.each do |p| %>
|
2
|
+
<p>
|
3
|
+
Title:
|
4
|
+
<a href='/<%= p.id %>'><%= p.title %></a>
|
5
|
+
<br />
|
6
|
+
<%= p.contents %>
|
7
|
+
</p>
|
8
|
+
<% end%>
|
9
|
+
|
10
|
+
<% if @blog.posts.empty? %><p>No posts</p><% end %>
|
11
|
+
|
12
|
+
<br/>
|
13
|
+
<form action=/ method=post>
|
14
|
+
Title
|
15
|
+
<input name=title><br/>
|
16
|
+
<textarea name=contents></textarea><br/>
|
17
|
+
<input type=submit>
|
18
|
+
</form>
|
data/lib/renee.rb
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'renee-core'
|
2
|
+
require 'renee-render'
|
3
|
+
|
4
|
+
require 'renee/version'
|
5
|
+
|
6
|
+
class Renee
|
7
|
+
class RichCore < Renee::Core
|
8
|
+
def initialize(&blk)
|
9
|
+
super
|
10
|
+
end
|
11
|
+
|
12
|
+
def call(env)
|
13
|
+
application_class.new(settings, &application_block).call(env)
|
14
|
+
end
|
15
|
+
alias_method :[], :call
|
16
|
+
|
17
|
+
def application_class
|
18
|
+
@application_class ||= begin
|
19
|
+
app_cls = Class.new(Application)
|
20
|
+
settings.includes.each { |inc| app_cls.send(:include, inc) }
|
21
|
+
app_cls
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
class Application < Renee::Core::Application
|
26
|
+
include Renee::Render
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def Renee(&blk)
|
32
|
+
Renee::RichCore.new(&blk)
|
33
|
+
end
|
data/renee.gemspec
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "renee/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "renee"
|
7
|
+
s.version = Renee::VERSION
|
8
|
+
s.authors = ["Josh Hull", "Nathan Esquenazi", "Arthur Chiu"]
|
9
|
+
s.email = ["joshbuddy@gmail.com", "nesquena@gmail.com", "mr.arthur.chiu@gmail.com"]
|
10
|
+
s.homepage = ""
|
11
|
+
s.summary = %q{The super-friendly web framework}
|
12
|
+
s.description = %q{The super-friendly web framework.}
|
13
|
+
|
14
|
+
s.rubyforge_project = "renee"
|
15
|
+
|
16
|
+
s.files = `git ls-files`.split("\n")
|
17
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
18
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
19
|
+
s.require_paths = ["lib"]
|
20
|
+
|
21
|
+
# TODO fix these deps
|
22
|
+
%w[core render].each do |name|
|
23
|
+
s.add_runtime_dependency "renee-#{name}", "= #{Renee::VERSION}"
|
24
|
+
end
|
25
|
+
s.add_development_dependency 'minitest', "~> 2.6.1"
|
26
|
+
s.add_development_dependency 'rake'
|
27
|
+
s.add_development_dependency 'bundler', "~> 1.0.10"
|
28
|
+
s.add_development_dependency "rack-test", ">= 0.5.0"
|
29
|
+
s.add_development_dependency "haml", ">= 2.2.0"
|
30
|
+
s.add_development_dependency "json"
|
31
|
+
end
|
data/test/blog_test.rb
ADDED
@@ -0,0 +1,78 @@
|
|
1
|
+
require File.expand_path('../test_helper', __FILE__)
|
2
|
+
|
3
|
+
describe "Blog example" do
|
4
|
+
before { @app = blog_app }
|
5
|
+
|
6
|
+
it "should respond to GET /" do
|
7
|
+
get('/')
|
8
|
+
assert_equal 200, response.status
|
9
|
+
assert_equal "
|
10
|
+
<p>No posts</p>
|
11
|
+
<br/>
|
12
|
+
<form action=/ method=post>
|
13
|
+
Title
|
14
|
+
<input name=title><br/>
|
15
|
+
<textarea name=contents></textarea><br/>
|
16
|
+
<input type=submit>
|
17
|
+
</form>", response.body
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should allow a POST to /" do
|
21
|
+
post('/', :title => 'my title', :contents => 'hey hey hey')
|
22
|
+
assert_equal 201, response.status
|
23
|
+
get('/')
|
24
|
+
assert_equal 200, response.status
|
25
|
+
assert_equal " <p>
|
26
|
+
Title:
|
27
|
+
<a href='/1'>my title</a>
|
28
|
+
<br />
|
29
|
+
hey hey hey
|
30
|
+
</p>
|
31
|
+
|
32
|
+
|
33
|
+
<br/>
|
34
|
+
<form action=/ method=post>
|
35
|
+
Title
|
36
|
+
<input name=title><br/>
|
37
|
+
<textarea name=contents></textarea><br/>
|
38
|
+
<input type=submit>
|
39
|
+
</form>", response.body
|
40
|
+
end
|
41
|
+
|
42
|
+
it "should allow a PUT to /" do
|
43
|
+
post('/', :title => 'my title', :contents => 'hey hey hey')
|
44
|
+
put('/1', :title => 'my real title', :contents => 'hey hey hey')
|
45
|
+
assert_equal 200, response.status
|
46
|
+
get('/')
|
47
|
+
assert_equal 200, response.status
|
48
|
+
assert_equal " <p>
|
49
|
+
Title:
|
50
|
+
<a href='/1'>my real title</a>
|
51
|
+
<br />
|
52
|
+
hey hey hey
|
53
|
+
</p>
|
54
|
+
|
55
|
+
|
56
|
+
<br/>
|
57
|
+
<form action=/ method=post>
|
58
|
+
Title
|
59
|
+
<input name=title><br/>
|
60
|
+
<textarea name=contents></textarea><br/>
|
61
|
+
<input type=submit>
|
62
|
+
</form>", response.body
|
63
|
+
end
|
64
|
+
|
65
|
+
it "should allow a DELETE to /" do
|
66
|
+
post('/', :title => 'my title', :contents => 'hey hey hey')
|
67
|
+
assert_equal 201, response.status
|
68
|
+
get('/.json')
|
69
|
+
assert_equal 200, response.status
|
70
|
+
assert_equal "[{\"contents\":\"hey hey hey\"}]", response.body
|
71
|
+
delete('/1')
|
72
|
+
assert_equal 200, response.status
|
73
|
+
get('/.json')
|
74
|
+
assert_equal 200, response.status
|
75
|
+
assert_equal "[]", response.body
|
76
|
+
end
|
77
|
+
|
78
|
+
end
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
gem 'minitest'
|
3
|
+
require 'minitest/autorun'
|
4
|
+
gem 'rack-test'
|
5
|
+
require 'rack/test'
|
6
|
+
$: << File.expand_path('../../../renee-core/lib', __FILE__)
|
7
|
+
$: << File.expand_path('../../../renee-render/lib', __FILE__)
|
8
|
+
$: << File.expand_path('../../lib', __FILE__)
|
9
|
+
require 'renee'
|
10
|
+
|
11
|
+
class ColoredIO
|
12
|
+
ESC = "\e["
|
13
|
+
NND = "#{ESC}0m"
|
14
|
+
|
15
|
+
def initialize(io)
|
16
|
+
@io = io
|
17
|
+
end
|
18
|
+
|
19
|
+
def print(o)
|
20
|
+
case o
|
21
|
+
when "."
|
22
|
+
@io.send(:print, "#{ESC}32m#{o}#{NND}")
|
23
|
+
when "E"
|
24
|
+
@io.send(:print, "#{ESC}33m#{o}#{NND}")
|
25
|
+
when "F"
|
26
|
+
@io.send(:print, "#{ESC}31m#{o}#{NND}")
|
27
|
+
else
|
28
|
+
@io.send(:print, o)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def puts(*o)
|
33
|
+
super
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
MiniTest::Unit.output = ColoredIO.new(MiniTest::Unit.output)
|
38
|
+
|
39
|
+
## TEST HELPERS
|
40
|
+
class MiniTest::Spec
|
41
|
+
include Rack::Test::Methods
|
42
|
+
|
43
|
+
def default_views_path
|
44
|
+
File.dirname(__FILE__) + "/views"
|
45
|
+
end
|
46
|
+
|
47
|
+
def blog_app
|
48
|
+
file = File.join(File.dirname(__FILE__), '..', 'examples', 'blog', 'config.ru')
|
49
|
+
Rack::Lint.new(Rack::Builder.parse_file(file)[0])
|
50
|
+
end
|
51
|
+
|
52
|
+
def app
|
53
|
+
@app
|
54
|
+
end
|
55
|
+
|
56
|
+
alias :response :last_response
|
57
|
+
end
|
metadata
ADDED
@@ -0,0 +1,204 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: renee
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 29
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 1
|
10
|
+
version: 0.0.1
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Josh Hull
|
14
|
+
- Nathan Esquenazi
|
15
|
+
- Arthur Chiu
|
16
|
+
autorequire:
|
17
|
+
bindir: bin
|
18
|
+
cert_chain: []
|
19
|
+
|
20
|
+
date: 2011-10-15 00:00:00 Z
|
21
|
+
dependencies:
|
22
|
+
- !ruby/object:Gem::Dependency
|
23
|
+
version_requirements: &id001 !ruby/object:Gem::Requirement
|
24
|
+
none: false
|
25
|
+
requirements:
|
26
|
+
- - "="
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
hash: 29
|
29
|
+
segments:
|
30
|
+
- 0
|
31
|
+
- 0
|
32
|
+
- 1
|
33
|
+
version: 0.0.1
|
34
|
+
requirement: *id001
|
35
|
+
type: :runtime
|
36
|
+
prerelease: false
|
37
|
+
name: renee-core
|
38
|
+
- !ruby/object:Gem::Dependency
|
39
|
+
version_requirements: &id002 !ruby/object:Gem::Requirement
|
40
|
+
none: false
|
41
|
+
requirements:
|
42
|
+
- - "="
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
hash: 29
|
45
|
+
segments:
|
46
|
+
- 0
|
47
|
+
- 0
|
48
|
+
- 1
|
49
|
+
version: 0.0.1
|
50
|
+
requirement: *id002
|
51
|
+
type: :runtime
|
52
|
+
prerelease: false
|
53
|
+
name: renee-render
|
54
|
+
- !ruby/object:Gem::Dependency
|
55
|
+
version_requirements: &id003 !ruby/object:Gem::Requirement
|
56
|
+
none: false
|
57
|
+
requirements:
|
58
|
+
- - ~>
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
hash: 21
|
61
|
+
segments:
|
62
|
+
- 2
|
63
|
+
- 6
|
64
|
+
- 1
|
65
|
+
version: 2.6.1
|
66
|
+
requirement: *id003
|
67
|
+
type: :development
|
68
|
+
prerelease: false
|
69
|
+
name: minitest
|
70
|
+
- !ruby/object:Gem::Dependency
|
71
|
+
version_requirements: &id004 !ruby/object:Gem::Requirement
|
72
|
+
none: false
|
73
|
+
requirements:
|
74
|
+
- - ">="
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
hash: 3
|
77
|
+
segments:
|
78
|
+
- 0
|
79
|
+
version: "0"
|
80
|
+
requirement: *id004
|
81
|
+
type: :development
|
82
|
+
prerelease: false
|
83
|
+
name: rake
|
84
|
+
- !ruby/object:Gem::Dependency
|
85
|
+
version_requirements: &id005 !ruby/object:Gem::Requirement
|
86
|
+
none: false
|
87
|
+
requirements:
|
88
|
+
- - ~>
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
hash: 3
|
91
|
+
segments:
|
92
|
+
- 1
|
93
|
+
- 0
|
94
|
+
- 10
|
95
|
+
version: 1.0.10
|
96
|
+
requirement: *id005
|
97
|
+
type: :development
|
98
|
+
prerelease: false
|
99
|
+
name: bundler
|
100
|
+
- !ruby/object:Gem::Dependency
|
101
|
+
version_requirements: &id006 !ruby/object:Gem::Requirement
|
102
|
+
none: false
|
103
|
+
requirements:
|
104
|
+
- - ">="
|
105
|
+
- !ruby/object:Gem::Version
|
106
|
+
hash: 11
|
107
|
+
segments:
|
108
|
+
- 0
|
109
|
+
- 5
|
110
|
+
- 0
|
111
|
+
version: 0.5.0
|
112
|
+
requirement: *id006
|
113
|
+
type: :development
|
114
|
+
prerelease: false
|
115
|
+
name: rack-test
|
116
|
+
- !ruby/object:Gem::Dependency
|
117
|
+
version_requirements: &id007 !ruby/object:Gem::Requirement
|
118
|
+
none: false
|
119
|
+
requirements:
|
120
|
+
- - ">="
|
121
|
+
- !ruby/object:Gem::Version
|
122
|
+
hash: 7
|
123
|
+
segments:
|
124
|
+
- 2
|
125
|
+
- 2
|
126
|
+
- 0
|
127
|
+
version: 2.2.0
|
128
|
+
requirement: *id007
|
129
|
+
type: :development
|
130
|
+
prerelease: false
|
131
|
+
name: haml
|
132
|
+
- !ruby/object:Gem::Dependency
|
133
|
+
version_requirements: &id008 !ruby/object:Gem::Requirement
|
134
|
+
none: false
|
135
|
+
requirements:
|
136
|
+
- - ">="
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
hash: 3
|
139
|
+
segments:
|
140
|
+
- 0
|
141
|
+
version: "0"
|
142
|
+
requirement: *id008
|
143
|
+
type: :development
|
144
|
+
prerelease: false
|
145
|
+
name: json
|
146
|
+
description: The super-friendly web framework.
|
147
|
+
email:
|
148
|
+
- joshbuddy@gmail.com
|
149
|
+
- nesquena@gmail.com
|
150
|
+
- mr.arthur.chiu@gmail.com
|
151
|
+
executables: []
|
152
|
+
|
153
|
+
extensions: []
|
154
|
+
|
155
|
+
extra_rdoc_files: []
|
156
|
+
|
157
|
+
files:
|
158
|
+
- Rakefile
|
159
|
+
- examples/blog/blog.rb
|
160
|
+
- examples/blog/config.ru
|
161
|
+
- examples/blog/views/edit.erb
|
162
|
+
- examples/blog/views/index.erb
|
163
|
+
- examples/blog/views/show.erb
|
164
|
+
- lib/renee.rb
|
165
|
+
- lib/renee/version.rb
|
166
|
+
- renee.gemspec
|
167
|
+
- test/blog_test.rb
|
168
|
+
- test/test_helper.rb
|
169
|
+
homepage: ""
|
170
|
+
licenses: []
|
171
|
+
|
172
|
+
post_install_message:
|
173
|
+
rdoc_options: []
|
174
|
+
|
175
|
+
require_paths:
|
176
|
+
- lib
|
177
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
178
|
+
none: false
|
179
|
+
requirements:
|
180
|
+
- - ">="
|
181
|
+
- !ruby/object:Gem::Version
|
182
|
+
hash: 3
|
183
|
+
segments:
|
184
|
+
- 0
|
185
|
+
version: "0"
|
186
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
187
|
+
none: false
|
188
|
+
requirements:
|
189
|
+
- - ">="
|
190
|
+
- !ruby/object:Gem::Version
|
191
|
+
hash: 3
|
192
|
+
segments:
|
193
|
+
- 0
|
194
|
+
version: "0"
|
195
|
+
requirements: []
|
196
|
+
|
197
|
+
rubyforge_project: renee
|
198
|
+
rubygems_version: 1.8.10
|
199
|
+
signing_key:
|
200
|
+
specification_version: 3
|
201
|
+
summary: The super-friendly web framework
|
202
|
+
test_files:
|
203
|
+
- test/blog_test.rb
|
204
|
+
- test/test_helper.rb
|