ramaze 0.0.6
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/Rakefile +360 -0
- data/bin/ramaze +152 -0
- data/doc/CHANGELOG +2021 -0
- data/doc/COPYING +56 -0
- data/doc/COPYING.ja +51 -0
- data/doc/README +275 -0
- data/doc/TODO +33 -0
- data/doc/allison/LICENSE +184 -0
- data/doc/allison/README +37 -0
- data/doc/allison/allison.css +300 -0
- data/doc/allison/allison.gif +0 -0
- data/doc/allison/allison.js +307 -0
- data/doc/allison/allison.rb +287 -0
- data/doc/allison/cache/BODY +588 -0
- data/doc/allison/cache/CLASS_INDEX +4 -0
- data/doc/allison/cache/CLASS_PAGE +1 -0
- data/doc/allison/cache/FILE_INDEX +4 -0
- data/doc/allison/cache/FILE_PAGE +1 -0
- data/doc/allison/cache/FONTS +1 -0
- data/doc/allison/cache/FR_INDEX_BODY +1 -0
- data/doc/allison/cache/IMGPATH +1 -0
- data/doc/allison/cache/INDEX +1 -0
- data/doc/allison/cache/JAVASCRIPT +307 -0
- data/doc/allison/cache/METHOD_INDEX +4 -0
- data/doc/allison/cache/METHOD_LIST +1 -0
- data/doc/allison/cache/SRC_PAGE +1 -0
- data/doc/allison/cache/STYLE +322 -0
- data/doc/allison/cache/URL +1 -0
- data/examples/blog/main.rb +16 -0
- data/examples/blog/public/screen.css +106 -0
- data/examples/blog/src/controller.rb +50 -0
- data/examples/blog/src/element.rb +53 -0
- data/examples/blog/src/model.rb +29 -0
- data/examples/blog/template/edit.xhtml +6 -0
- data/examples/blog/template/index.xhtml +24 -0
- data/examples/blog/template/new.xhtml +5 -0
- data/examples/blog/template/view.xhtml +15 -0
- data/examples/blog/test/tc_entry.rb +18 -0
- data/examples/caching.rb +23 -0
- data/examples/element.rb +40 -0
- data/examples/hello.rb +23 -0
- data/examples/simple.rb +60 -0
- data/examples/templates/template/external.haml +21 -0
- data/examples/templates/template/external.liquid +28 -0
- data/examples/templates/template/external.mab +27 -0
- data/examples/templates/template/external.rhtml +29 -0
- data/examples/templates/template/external.rmze +24 -0
- data/examples/templates/template_erubis.rb +50 -0
- data/examples/templates/template_haml.rb +48 -0
- data/examples/templates/template_liquid.rb +64 -0
- data/examples/templates/template_markaby.rb +52 -0
- data/examples/templates/template_ramaze.rb +49 -0
- data/examples/whywiki/main.rb +56 -0
- data/examples/whywiki/template/edit.xhtml +14 -0
- data/examples/whywiki/template/show.xhtml +17 -0
- data/lib/proto/conf/benchmark.yaml +35 -0
- data/lib/proto/conf/debug.yaml +34 -0
- data/lib/proto/conf/live.yaml +33 -0
- data/lib/proto/conf/silent.yaml +31 -0
- data/lib/proto/conf/stage.yaml +33 -0
- data/lib/proto/main.rb +18 -0
- data/lib/proto/public/404.jpg +0 -0
- data/lib/proto/public/css/coderay.css +105 -0
- data/lib/proto/public/css/ramaze_error.css +42 -0
- data/lib/proto/public/error.xhtml +74 -0
- data/lib/proto/public/favicon.ico +0 -0
- data/lib/proto/public/js/jquery.js +1923 -0
- data/lib/proto/public/ramaze.png +0 -0
- data/lib/proto/src/controller/main.rb +7 -0
- data/lib/proto/src/element/page.rb +16 -0
- data/lib/proto/src/model.rb +5 -0
- data/lib/proto/template/index.xhtml +6 -0
- data/lib/ramaze.rb +317 -0
- data/lib/ramaze/adapter/mongrel.rb +111 -0
- data/lib/ramaze/adapter/webrick.rb +161 -0
- data/lib/ramaze/cache.rb +11 -0
- data/lib/ramaze/cache/memcached.rb +52 -0
- data/lib/ramaze/cache/memory.rb +6 -0
- data/lib/ramaze/cache/yaml_store.rb +37 -0
- data/lib/ramaze/controller.rb +10 -0
- data/lib/ramaze/dispatcher.rb +315 -0
- data/lib/ramaze/error.rb +11 -0
- data/lib/ramaze/gestalt.rb +108 -0
- data/lib/ramaze/global.rb +120 -0
- data/lib/ramaze/helper.rb +32 -0
- data/lib/ramaze/helper/aspect.rb +189 -0
- data/lib/ramaze/helper/auth.rb +120 -0
- data/lib/ramaze/helper/cache.rb +52 -0
- data/lib/ramaze/helper/feed.rb +135 -0
- data/lib/ramaze/helper/form.rb +204 -0
- data/lib/ramaze/helper/link.rb +80 -0
- data/lib/ramaze/helper/redirect.rb +48 -0
- data/lib/ramaze/helper/stack.rb +67 -0
- data/lib/ramaze/http_status.rb +66 -0
- data/lib/ramaze/inform.rb +166 -0
- data/lib/ramaze/snippets.rb +5 -0
- data/lib/ramaze/snippets/hash/keys_to_sym.rb +19 -0
- data/lib/ramaze/snippets/kernel/aquire.rb +22 -0
- data/lib/ramaze/snippets/kernel/autoreload.rb +79 -0
- data/lib/ramaze/snippets/kernel/caller_lines.rb +58 -0
- data/lib/ramaze/snippets/kernel/constant.rb +24 -0
- data/lib/ramaze/snippets/kernel/rescue_require.rb +12 -0
- data/lib/ramaze/snippets/kernel/self_method.rb +41 -0
- data/lib/ramaze/snippets/kernel/silently.rb +13 -0
- data/lib/ramaze/snippets/object/traits.rb +60 -0
- data/lib/ramaze/snippets/openstruct/temp.rb +10 -0
- data/lib/ramaze/snippets/string/DIVIDE.rb +16 -0
- data/lib/ramaze/snippets/string/camel_case.rb +14 -0
- data/lib/ramaze/snippets/string/snake_case.rb +12 -0
- data/lib/ramaze/snippets/symbol/to_proc.rb +14 -0
- data/lib/ramaze/snippets/thread/deadQUESTIONMARK.rb +11 -0
- data/lib/ramaze/store/default.rb +48 -0
- data/lib/ramaze/template.rb +102 -0
- data/lib/ramaze/template/amrita2.rb +40 -0
- data/lib/ramaze/template/erubis.rb +58 -0
- data/lib/ramaze/template/haml.rb +65 -0
- data/lib/ramaze/template/haml/actionview_stub.rb +20 -0
- data/lib/ramaze/template/liquid.rb +74 -0
- data/lib/ramaze/template/markaby.rb +68 -0
- data/lib/ramaze/template/ramaze.rb +177 -0
- data/lib/ramaze/template/ramaze/element.rb +166 -0
- data/lib/ramaze/template/ramaze/morpher.rb +156 -0
- data/lib/ramaze/tool/create.rb +70 -0
- data/lib/ramaze/tool/tidy.rb +71 -0
- data/lib/ramaze/trinity.rb +38 -0
- data/lib/ramaze/trinity/request.rb +244 -0
- data/lib/ramaze/trinity/response.rb +41 -0
- data/lib/ramaze/trinity/session.rb +129 -0
- data/lib/ramaze/version.rb +14 -0
- data/spec/spec_all.rb +73 -0
- data/spec/spec_helper.rb +215 -0
- data/spec/tc_adapter_mongrel.rb +24 -0
- data/spec/tc_adapter_webrick.rb +22 -0
- data/spec/tc_cache.rb +79 -0
- data/spec/tc_controller.rb +39 -0
- data/spec/tc_element.rb +100 -0
- data/spec/tc_error.rb +23 -0
- data/spec/tc_gestalt.rb +90 -0
- data/spec/tc_global.rb +46 -0
- data/spec/tc_helper_aspect.rb +65 -0
- data/spec/tc_helper_auth.rb +61 -0
- data/spec/tc_helper_cache.rb +81 -0
- data/spec/tc_helper_feed.rb +129 -0
- data/spec/tc_helper_form.rb +146 -0
- data/spec/tc_helper_link.rb +58 -0
- data/spec/tc_helper_redirect.rb +51 -0
- data/spec/tc_helper_stack.rb +55 -0
- data/spec/tc_morpher.rb +90 -0
- data/spec/tc_params.rb +84 -0
- data/spec/tc_request.rb +111 -0
- data/spec/tc_session.rb +56 -0
- data/spec/tc_store.rb +25 -0
- data/spec/tc_template_amrita2.rb +34 -0
- data/spec/tc_template_erubis.rb +41 -0
- data/spec/tc_template_haml.rb +44 -0
- data/spec/tc_template_liquid.rb +98 -0
- data/spec/tc_template_markaby.rb +74 -0
- data/spec/tc_template_ramaze.rb +54 -0
- data/spec/tc_tidy.rb +14 -0
- data/spec/template/amrita2/data.html +6 -0
- data/spec/template/amrita2/index.html +1 -0
- data/spec/template/amrita2/sum.html +1 -0
- data/spec/template/erubis/sum.rhtml +1 -0
- data/spec/template/haml/index.haml +5 -0
- data/spec/template/haml/with_vars.haml +4 -0
- data/spec/template/liquid/index.liquid +1 -0
- data/spec/template/liquid/products.liquid +45 -0
- data/spec/template/markaby/external.mab +8 -0
- data/spec/template/markaby/sum.mab +1 -0
- data/spec/template/ramaze/file_only.rmze +1 -0
- data/spec/template/ramaze/index.rmze +1 -0
- data/spec/template/ramaze/nested.rmze +1 -0
- data/spec/template/ramaze/sum.rmze +1 -0
- metadata +317 -0
data/spec/tc_params.rb
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
# Copyright (c) 2006 Michael Fellinger m.fellinger@gmail.com
|
|
2
|
+
# All files in this distribution are subject to the terms of the Ruby license.
|
|
3
|
+
|
|
4
|
+
require 'spec/spec_helper'
|
|
5
|
+
|
|
6
|
+
include Ramaze
|
|
7
|
+
|
|
8
|
+
class TCParamsController < Template::Ramaze
|
|
9
|
+
def index
|
|
10
|
+
"index"
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def no_params
|
|
14
|
+
"no params"
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def single_param param
|
|
18
|
+
"single param (#{param})"
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def double_param param1, param2
|
|
22
|
+
"double param (#{param1}, #{param2})"
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def all_params *params
|
|
26
|
+
"all params (#{params.join(', ')})"
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def at_least_one param, *params
|
|
30
|
+
"at least one (#{param}, #{params.join(', ')})"
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def one_default param = 'default'
|
|
34
|
+
"one_default (#{param})"
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
context "Simple Parameters" do
|
|
39
|
+
ramaze(:mapping => {'/' => TCParamsController})
|
|
40
|
+
|
|
41
|
+
specify "Should respond to no parameters given" do
|
|
42
|
+
get('/no_params').should == "no params"
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
specify "Should respond to only / with the index" do
|
|
46
|
+
get('/').should == "index"
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
specify "call /bar though index doesn't take params" do
|
|
50
|
+
lambda{ p get('/bar') }.should_raise #OpenURI::HTTPError
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
specify "action that takes a single param" do
|
|
54
|
+
get('/single_param/foo').should == "single param (foo)"
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
specify "action that takes two params" do
|
|
58
|
+
get('/double_param/foo/bar').should == "double param (foo, bar)"
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
specify "action that takes two params but we give only one" do
|
|
62
|
+
lambda{ p get('/double_param/foo') }.should_raise #OpenURI::HTTPError
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
specify "action that takes all params" do
|
|
66
|
+
get('/all_params/foo/bar/foobar').should == "all params (foo, bar, foobar)"
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
specify "action that takes all params but needs at least one" do
|
|
70
|
+
get('at_least_one/foo/bar/foobar').should == "at least one (foo, bar, foobar)"
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
specify "action that takes all params but needs at least one (not given here)" do
|
|
74
|
+
lambda{ p get('/at_least_one') }.should_raise #OpenURI::HTTPError
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
specify "one default" do
|
|
78
|
+
get('/one_default').should == "one_default (default)"
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
specify "one default" do
|
|
82
|
+
get('/one_default/my_default').should == "one_default (my_default)"
|
|
83
|
+
end
|
|
84
|
+
end
|
data/spec/tc_request.rb
ADDED
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
# Copyright (c) 2006 Michael Fellinger m.fellinger@gmail.com
|
|
2
|
+
# All files in this distribution are subject to the terms of the Ruby license.
|
|
3
|
+
|
|
4
|
+
require 'spec/spec_helper'
|
|
5
|
+
|
|
6
|
+
include Ramaze
|
|
7
|
+
|
|
8
|
+
class TCRequestController < Template::Ramaze
|
|
9
|
+
def is_post() request.post?.to_s end
|
|
10
|
+
def is_get() request.get?.to_s end
|
|
11
|
+
def is_put() request.put?.to_s end
|
|
12
|
+
def is_delete() request.delete?.to_s end
|
|
13
|
+
|
|
14
|
+
def request_inspect
|
|
15
|
+
request.params.inspect
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def post_inspect
|
|
19
|
+
request.params.inspect
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def put_inspect(file)
|
|
23
|
+
request.body.read.inspect
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def get_inspect
|
|
27
|
+
request.params.inspect
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def test_get
|
|
31
|
+
request['foo']
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def test_get_set(arg)
|
|
35
|
+
request['foo'] = arg
|
|
36
|
+
request['foo']
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def test_headers
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def my_ip
|
|
43
|
+
request.remote_addr
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
context "Request" do
|
|
48
|
+
context "POST" do
|
|
49
|
+
ramaze( :adapter => :mongrel, :mapping => {'/' => TCRequestController} )
|
|
50
|
+
|
|
51
|
+
specify "give me the result of request.post?" do
|
|
52
|
+
post("is_post").should == 'true'
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
specify "give me the result of request.get?" do
|
|
56
|
+
post("is_get").should == 'false'
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
# this here has shown some odd errors... keep an eye on it.
|
|
60
|
+
specify "give me back what i gave" do
|
|
61
|
+
post("post_inspect", 'this' => 'post').should == {"this" => "post"}.inspect
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
context "PUT" do
|
|
66
|
+
specify "put a ressource" do
|
|
67
|
+
address = "http://localhost:7007/put_inspect/#{CGI.escape(__FILE__)}"
|
|
68
|
+
response = `curl -S -s -T #{__FILE__} #{address}`
|
|
69
|
+
file = File.read(__FILE__)
|
|
70
|
+
|
|
71
|
+
response[1..-2].should == file
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
context "DELETE" do
|
|
76
|
+
specify "delete a ressource" do
|
|
77
|
+
# find a way to test this one, even curl doesn't support it
|
|
78
|
+
end
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
context "GET" do
|
|
82
|
+
specify "give me the result of request.post?" do
|
|
83
|
+
get("/is_post").should == 'false'
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
specify "give me the result of request.get?" do
|
|
87
|
+
get("/is_get").should == 'true'
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
specify "give me back what i gave" do
|
|
91
|
+
get("/get_inspect?one=two&three=four").should == {'one' => 'two', 'three' => 'four'}.inspect
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
specify "my ip" do
|
|
95
|
+
get("/my_ip").should == '127.0.0.1'
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
specify "request[key]" do
|
|
99
|
+
get('test_get?foo=bar').should == 'bar'
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
specify "request[key] = value" do
|
|
103
|
+
get('test_get_set/bar').should == 'bar'
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
specify "header" do
|
|
107
|
+
raw_get('/test_headers').status.should == %w[200 OK]
|
|
108
|
+
raw_get('/test_headers').content_type.should == "text/html"
|
|
109
|
+
end
|
|
110
|
+
end
|
|
111
|
+
end
|
data/spec/tc_session.rb
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
# Copyright (c) 2006 Michael Fellinger m.fellinger@gmail.com
|
|
2
|
+
# All files in this distribution are subject to the terms of the Ruby license.
|
|
3
|
+
|
|
4
|
+
require 'spec/spec_helper'
|
|
5
|
+
|
|
6
|
+
include Ramaze
|
|
7
|
+
|
|
8
|
+
class TCSessionController < Template::Ramaze
|
|
9
|
+
def index
|
|
10
|
+
session.inspect
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def set_session key, val
|
|
14
|
+
session[key] = val
|
|
15
|
+
index
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def post_set_session
|
|
19
|
+
session.merge! request.params
|
|
20
|
+
index
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
context "usual Session" do
|
|
25
|
+
ramaze(:mapping => {'/' => TCSessionController})
|
|
26
|
+
|
|
27
|
+
ctx = Context.new
|
|
28
|
+
|
|
29
|
+
specify "Should give me an empty session" do
|
|
30
|
+
ctx.eget.should == {}
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
specify "set some session-parameters" do
|
|
34
|
+
ctx.eget('/set_session/foo/bar').should == {'foo' => 'bar'}
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
specify "inspect session again" do
|
|
38
|
+
ctx.eget('/').should == {'foo' => 'bar'}
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
specify "change the session" do
|
|
42
|
+
ctx.eget('/set_session/foo/foobar').should == {'foo' => 'foobar'}
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
specify "inspect the changed session" do
|
|
46
|
+
ctx.eget('/').should == {'foo' => 'foobar'}
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
specify "now a little bit with POST" do
|
|
50
|
+
ctx.epost('/post_set_session', :x => :y)['x'].should == 'y'
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
specify "snooping a bit around" do
|
|
54
|
+
ctx.cookie.split('=').size.should == 2
|
|
55
|
+
end
|
|
56
|
+
end
|
data/spec/tc_store.rb
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# Copyright (c) 2006 Michael Fellinger m.fellinger@gmail.com
|
|
2
|
+
# All files in this distribution are subject to the terms of the Ruby license.
|
|
3
|
+
|
|
4
|
+
require 'spec/spec_helper'
|
|
5
|
+
require 'ramaze/store/default'
|
|
6
|
+
|
|
7
|
+
include Ramaze
|
|
8
|
+
|
|
9
|
+
context "initialize an Store" do
|
|
10
|
+
db = 'db.yaml'
|
|
11
|
+
|
|
12
|
+
specify "Store::Default.new" do
|
|
13
|
+
Db = Store::Default.new(db)
|
|
14
|
+
Db.db.should.is_a?(YAML::Store)
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
specify "store and retrieve something" do
|
|
18
|
+
(Db[:foo] = :bar).should == :bar
|
|
19
|
+
Db[:foo].should == :bar
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
teardown do
|
|
23
|
+
FileUtils.rm db
|
|
24
|
+
end
|
|
25
|
+
end
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# Copyright (c) 2006 Michael Fellinger m.fellinger@gmail.com
|
|
2
|
+
# All files in this distribution are subject to the terms of the Ruby license.
|
|
3
|
+
|
|
4
|
+
require 'spec/spec_helper'
|
|
5
|
+
|
|
6
|
+
testcase_requires 'amrita2'
|
|
7
|
+
|
|
8
|
+
include Ramaze
|
|
9
|
+
|
|
10
|
+
class TCTemplateAmritaController < Template::Amrita2
|
|
11
|
+
trait :template_root => 'spec/template/amrita2/'
|
|
12
|
+
|
|
13
|
+
def title
|
|
14
|
+
"hello world"
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def body
|
|
18
|
+
"Amrita2 is an HTML template library for Ruby"
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
context "Simply calling" do
|
|
23
|
+
ramaze(:mapping => {'/' => TCTemplateAmritaController})
|
|
24
|
+
|
|
25
|
+
specify "should respond to /data" do
|
|
26
|
+
get('/data').should ==
|
|
27
|
+
%{<html>
|
|
28
|
+
<body>
|
|
29
|
+
<h1>hello world</h1>
|
|
30
|
+
<p>Amrita2 is an HTML template library for Ruby</p>
|
|
31
|
+
</body>
|
|
32
|
+
</html>}
|
|
33
|
+
end
|
|
34
|
+
end
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
# Copyright (c) 2006 Michael Fellinger m.fellinger@gmail.com
|
|
2
|
+
# All files in this distribution are subject to the terms of the Ruby license.
|
|
3
|
+
|
|
4
|
+
require 'spec/spec_helper'
|
|
5
|
+
|
|
6
|
+
testcase_requires 'erubis'
|
|
7
|
+
|
|
8
|
+
include Ramaze
|
|
9
|
+
|
|
10
|
+
class TCTemplateErubisController < Template::Erubis
|
|
11
|
+
trait :template_root => 'spec/template/erubis/'
|
|
12
|
+
|
|
13
|
+
def index
|
|
14
|
+
'Erubis Index'
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def sum num1, num2
|
|
18
|
+
@num1, @num2 = num1.to_i, num2.to_i
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def inline *args
|
|
22
|
+
@args = args
|
|
23
|
+
"<%= @args.inspect %>"
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
context "Erubis" do
|
|
28
|
+
ramaze(:mapping => {'/' => TCTemplateErubisController})
|
|
29
|
+
|
|
30
|
+
specify "index" do
|
|
31
|
+
get('/').should == 'Erubis Index'
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
specify "sum" do
|
|
35
|
+
get('/sum/1/2').should == '3'
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
specify "inline" do
|
|
39
|
+
get('/inline/foo/bar').should == %w[foo bar].inspect
|
|
40
|
+
end
|
|
41
|
+
end
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
# Copyright (c) 2006 Michael Fellinger m.fellinger@gmail.com
|
|
2
|
+
# All files in this distribution are subject to the terms of the Ruby license.
|
|
3
|
+
|
|
4
|
+
require 'spec/spec_helper'
|
|
5
|
+
|
|
6
|
+
testcase_requires 'ramaze/template/haml'
|
|
7
|
+
|
|
8
|
+
include Ramaze
|
|
9
|
+
|
|
10
|
+
class TCTemplateHamlController < Template::Haml
|
|
11
|
+
trait :template_root => 'spec/template/haml/'
|
|
12
|
+
|
|
13
|
+
def index
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def with_vars
|
|
17
|
+
@title = "Teen Wolf"
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
context "Simply calling" do
|
|
22
|
+
ramaze(:mapping => {'/' => TCTemplateHamlController})
|
|
23
|
+
|
|
24
|
+
specify "index" do
|
|
25
|
+
get('/').should ==
|
|
26
|
+
"<div id='contact'>
|
|
27
|
+
<h1>Eugene Mumbai</h1>
|
|
28
|
+
<ul class='info'>
|
|
29
|
+
<li class='login'>eugene</li>
|
|
30
|
+
<li class='email'>eugene@example.com</li>
|
|
31
|
+
</ul>
|
|
32
|
+
</div>"
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
specify "variables in controller" do
|
|
36
|
+
get('/with_vars').should ==
|
|
37
|
+
%{<div id='content'>
|
|
38
|
+
<div class='title'>
|
|
39
|
+
<h1>Teen Wolf</h1>
|
|
40
|
+
<a href="Home">Home</a>
|
|
41
|
+
</div>
|
|
42
|
+
</div>}
|
|
43
|
+
end
|
|
44
|
+
end
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
# Copyright (c) 2006 Michael Fellinger m.fellinger@gmail.com
|
|
2
|
+
# All files in this distribution are subject to the terms of the Ruby license.
|
|
3
|
+
|
|
4
|
+
require 'spec/spec_helper'
|
|
5
|
+
|
|
6
|
+
testcase_requires 'liquid'
|
|
7
|
+
|
|
8
|
+
include Ramaze
|
|
9
|
+
|
|
10
|
+
module ProductsFilter
|
|
11
|
+
def price(integer)
|
|
12
|
+
sprintf("$%.2d USD", integer / 100.0)
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def prettyprint(text)
|
|
16
|
+
text.gsub( /\*(.*)\*/, '<b>\1</b>' )
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def count(array)
|
|
20
|
+
array.size
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def paragraph(p)
|
|
24
|
+
"<p>#{p}</p>"
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
class TCTemplateLiquidController < Template::Liquid
|
|
30
|
+
trait :template_root => 'spec/template/liquid/'
|
|
31
|
+
trait :liquid_options => { :filters => ProductsFilter }
|
|
32
|
+
|
|
33
|
+
def index
|
|
34
|
+
@hash = {'name' => 'tobi'}
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def products
|
|
38
|
+
@hash = {'products' => products_list, 'section' => 'Gems', 'cool_products' => true}
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
private
|
|
42
|
+
|
|
43
|
+
def products_list
|
|
44
|
+
[
|
|
45
|
+
{'name' => 'Ruby', 'price' => 1000, 'description' => 'precious gem'},
|
|
46
|
+
{'name' => 'Diamond', 'price' => 2000, 'description' => 'even more precious gem'},
|
|
47
|
+
]
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
context "Liquid" do
|
|
52
|
+
ramaze(:mapping => {'/' => TCTemplateLiquidController})
|
|
53
|
+
|
|
54
|
+
specify "index" do
|
|
55
|
+
get('/').should == "hi tobi"
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
specify "products" do
|
|
59
|
+
o = get('/products')
|
|
60
|
+
o = o.split("\n").map{|l| l.strip!; l.empty? ? nil : l}.compact.join("\n")
|
|
61
|
+
o.should == %{
|
|
62
|
+
<?xml version="1.0" encoding="utf-8"?>
|
|
63
|
+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
|
|
64
|
+
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
|
65
|
+
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
|
66
|
+
<head>
|
|
67
|
+
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
|
|
68
|
+
<meta http-equiv="Content-Language" content="en-us" />
|
|
69
|
+
<title>products</title>
|
|
70
|
+
<meta name="ROBOTS" content="ALL" />
|
|
71
|
+
<meta http-equiv="imagetoolbar" content="no" />
|
|
72
|
+
<meta name="MSSmartTagsPreventParsing" content="true" />
|
|
73
|
+
<meta name="Copyright" content="(c) 2005 Copyright content: Copyright design: Tobias Luetke" />
|
|
74
|
+
<!-- (c) Copyright 2005 by Tobias Luetke All Rights Reserved. -->
|
|
75
|
+
</head>
|
|
76
|
+
<body>
|
|
77
|
+
<h1>There are currently 2 products in the Gems catalog</h1>
|
|
78
|
+
Cool products :)
|
|
79
|
+
<ul id="products">
|
|
80
|
+
<li>
|
|
81
|
+
<h2>Ruby</h2>
|
|
82
|
+
Only $10 USD
|
|
83
|
+
<p>precious gem</p>
|
|
84
|
+
<p>it rocks!</p>
|
|
85
|
+
</li>
|
|
86
|
+
<li>
|
|
87
|
+
<h2>Diamond</h2>
|
|
88
|
+
Only $20 USD
|
|
89
|
+
<p>even more precious gem</p>
|
|
90
|
+
<p>it rocks!</p>
|
|
91
|
+
</li>
|
|
92
|
+
</ul>
|
|
93
|
+
</body>
|
|
94
|
+
</html>
|
|
95
|
+
}.split("\n").map{|l| l.strip!; l.empty? ? nil : l}.compact.join("\n")
|
|
96
|
+
end
|
|
97
|
+
end
|
|
98
|
+
|