/
haml.rb
114 lines (97 loc) · 2.25 KB
/
haml.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
# Copyright (c) 2009 Michael Fellinger m.fellinger@gmail.com
# All files in this distribution are subject to the terms of the Ruby license.
require File.expand_path('../../../../spec/helper', __FILE__)
spec_require 'haml'
Ramaze::App.options.views = 'haml'
class SpecHaml < Ramaze::Controller
map '/'
engine :Haml
def index
'%h1 Haml Index'
end
def links
'
%ul
%li
%a{:href => r(:index)} Index page
%li
%a{:href => r(:internal)} Internal template
%li
%a{:href => r(:external)} External template
'.ui
end
def sum(num1, num2)
@num1, @num2 = num1.to_i, num2.to_i
end
end
class SpecHamlLayout < Ramaze::Controller
map '/with_layout'
engine :Haml
layout :wrapper
RUNS = [1,2,3]
def index
RUNS.shift.to_s
end
def wrapper
'= @content'
end
end
describe Ramaze::View::Haml do
behaves_like :rack_test
should 'render' do
got = get('/')
got.status.should == 200
got['Content-Type'].should == 'text/html'
got.body.strip.should == "<h1>Haml Index</h1>"
end
should 'use other helper methods' do
got = get('/links')
got.status.should == 200
got['Content-Type'].should == 'text/html'
got.body.strip.should ==
"<ul>
<li>
<a href='/index'>Index page</a>
</li>
<li>
<a href='/internal'>Internal template</a>
</li>
<li>
<a href='/external'>External template</a>
</li>
</ul>"
end
should 'render external template' do
got = get('/external')
got.status.should == 200
got['Content-Type'].should == 'text/html'
got.body.strip.should ==
"<html>
<head>
<title>Haml Test</title>
</head>
<body>
<h1>Haml Template</h1>
</body>
</html>"
end
should 'render external template with instance variables' do
got = get('/sum/1/2')
got.status.should == 200
got['Content-Type'].should == 'text/html'
got.body.strip.should ==
"<div>
3
</div>"
end
should 'render the wrapped view twice even with caching' do
got = get('/with_layout')
got.status.should == 200
got['Content-Type'].should == 'text/html'
got.body.strip.should == "1"
got = get('/with_layout')
got.status.should == 200
got['Content-Type'].should == 'text/html'
got.body.strip.should == "2"
end
end