Skip to content

Instantly share code, notes, and snippets.

@rickbacci
Created January 16, 2015 00:50
Show Gist options
  • Save rickbacci/c27fcb4a31b0cbca0831 to your computer and use it in GitHub Desktop.
Save rickbacci/c27fcb4a31b0cbca0831 to your computer and use it in GitHub Desktop.
require 'erb'
include ERB::Util
@items = ['foo', 'bar', 'baz']
weekday = Time.now.strftime('%A')
template = %Q{
<DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>Shopping List for <%= weekday %></title>
</head>
<body>
<h1>Shopping List for <%= weekday %></h1>
<p>You need to buy:</p>
<ul>
<% for @item in @items %>
<li><%= @item %></li>
<% end %>
</ul>
</body>
</html>
}
renderer = ERB.new(template)
puts output = renderer.result()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment