Skip to content

Commit caaeee0

Browse files
committed
Inline template
1 parent bd0b15e commit caaeee0

1 file changed

Lines changed: 19 additions & 6 deletions

File tree

frameworks/Ruby/rack/hello_world.rb

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -107,12 +107,25 @@ def fortunes
107107
fortunes << { 'id' => 0, 'message' => 'Additional fortune added at request time.' }
108108
fortunes.sort_by! { |item| item['message'] }
109109

110-
buffer = String.new
111-
buffer << TEMPLATE_PREFIX
112-
fortunes.each do |item|
113-
buffer << "<tr><td>#{item['id']}</td><td>#{ERB::Escape.html_escape(item['message'])}</td></tr>"
114-
end
115-
buffer << TEMPLATE_POSTFIX
110+
rows = fortunes.map { |fortune| "<tr><td>#{fortune['id']}</td><td>#{ERB::Escape.html_escape(fortune['message'])}</td></tr>" }.join
111+
112+
<<-HTML
113+
<!DOCTYPE html>
114+
<html>
115+
<head>
116+
<title>Fortunes</title>
117+
</head>
118+
<body>
119+
<table>
120+
<tr>
121+
<th>id</th>
122+
<th>message</th>
123+
</tr>
124+
#{rows}
125+
</table>
126+
</body>
127+
</html>
128+
HTML
116129
end
117130

118131
def update_worlds(count)

0 commit comments

Comments
 (0)