Skip to content

Instantly share code, notes, and snippets.

@havenwood
Last active January 2, 2019 03:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save havenwood/4469e3975ce0b597e00a3cf205dea4bb to your computer and use it in GitHub Desktop.
Save havenwood/4469e3975ce0b597e00a3cf205dea4bb to your computer and use it in GitHub Desktop.
An example ERB template
require 'erb'
data = [%w[hi ho], %w[hi hum]]
template = ERB.new <<~END, trim_mode: '-'
<!DOCTYPE html>
<html lang="en">
<head>
<title>Table</title>
<meta charset="UTF-8">
</head>
<body>
<table>
<%- data.each do |row| -%>
<tr>
<%- row.each do |column| -%>
<td><%= column %></td>
<%- end -%>
</tr>
<%- end -%>
</table>
</body>
</html>
END
puts template.result binding
# <!DOCTYPE html>
# <html lang="en">
# <head>
# <title>Table</title>
# <meta charset="UTF-8">
# </head>
# <body>
# <table>
# <tr>
# <td>hi</td>
# <td>ho</td>
# </tr>
# <tr>
# <td>hi</td>
# <td>hum</td>
# </tr>
# </table>
# </body>
# </html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment