-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_erb_html.rb
executable file
·106 lines (81 loc) · 2.57 KB
/
test_erb_html.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
# Play with more advanced parts of the ERB class - including use with HTML.
# Following information from:
# http://ruby-doc.org/stdlib-1.9.3/libdoc/erb/rdoc/ERB.html
# Note: no cats are actually being sold.
require 'erb'
class Fluffy_Kitten
def initialize ( name, gender, color, fluffyness )
@name = name
@gender = gender
@color = color
@fluffyness = fluffyness
@points_of_interest = []
end
def this_cats_name
@name
end
def this_cats_gender
@gender
end
def this_cats_color
@color
end
def this_cats_fluffyness
@fluffyness
end
def traits
@points_of_interest
end
def add_point_of_interest( point )
@points_of_interest << point
end
end
class All_Deez_Fluffy_Kittens
def initialize
@kittens = []
end
def add_this_kitten( kitten )
@kittens << kitten
end
def kittens
@kittens
end
# Support templating of member data.
def get_binding
binding
end
end
fluffywillykitty = Fluffy_Kitten.new("Willamette", "female", "grey", "omgwtfbbqfluffykitty")
fluffywillykitty.add_point_of_interest("Fluffy. Extremely fluffy.")
fluffywillykitty.add_point_of_interest("Has been known to ambush people and attack feet during dark hours.")
kitty_prince = Fluffy_Kitten.new("Prince", "male", "black and white", "standard, close-lying coat of fur")
kitty_prince.add_point_of_interest("Affectionate attention-seeker.")
kitty_prince.add_point_of_interest("Loves to cuddle, but will lie on your lap for hours and not want to move.")
kitty_mindy = Fluffy_Kitten.new("Mindy", "female", "orange", "standard, close-lying coat of fur - soft")
kitty_mindy.add_point_of_interest("Extremely shy, easy to frighten - is a giant sweetheart once she warms up to you.")
@all_the_kittens = All_Deez_Fluffy_Kittens.new
@all_the_kittens.add_this_kitten(fluffywillykitty)
@all_the_kittens.add_this_kitten(kitty_prince)
@all_the_kittens.add_this_kitten(kitty_mindy)
# Creating a template
template = %{
<html>
<head><title>Fluffy's Fluffy Kitty Emporium!</title></head>
<body>
<h1>Fluffy Kittens for sale:</h1>
<ul>
<% kittens.each do |kitty_cat| %>
<li><%= kitty_cat.this_cats_name %> is a <%= kitty_cat.this_cats_color %> <%= kitty_cat.this_cats_gender %> kitty.<br>
<%= kitty_cat.this_cats_name %>'s level of fluffinisity is: <%= kitty_cat.this_cats_fluffyness %>.<br>
Points of interest regarding <%= kitty_cat.this_cats_name %>:<br>
<% kitty_cat.traits.each do |point| %>
<li><%= point %></li>
<% end %>
</li>
<% end %>
</ul>
</body>
</html>
}.gsub(/^ /, '')
rhtml = ERB.new(template)
rhtml.run(@all_the_kittens.get_binding)