Report abuse

test.rb

#!/usr/bin/ruby

require 'erb'

template = File.readlines("test.erb").join

newarray = []

newarray << ["one", "two", "three"]
newarray << ["one", "two", "three"]
newarray << ["one", "two", "three"]

html = ERB.new(template, 0, "<>")

puts html.result(binding)

test.erb

<style type="text/css"> 
TABLE.data { font-family: arial,serif;  font-size: 10pt;  background-color: white;  padding: 2; }
TH.data { font-family: arial,serif;  font-size: 10pt;  background-color: white;  text-align: left;  background-color: #999797;  color: #DCE5C1; }
.serviceOK { font-family: arial,serif;  font-size: 10pt;  text-align: left;  background-color: #33FF00;  font-weight: bold; }
.serviceCRITICAL { font-family: arial,serif;  font-size: 10pt;  text-align: left;  background-color: #F83838;  font-weight: bold; }
</style>

<TABLE BORDER=0 CLASS='data'>
<TR><TH CLASS='data'>Host</TH><TH CLASS='data'>Service</TH><TH CLASS='data'>% Uptime</TH>
<% newarray.each do |line| %>
<tr><td CLASS='data'><%= line[0] %></td><td CLASS='serviceOK'><%= line[1] %></td><td CLASS='serviceCRITICAL'><%= line[2] %></td></tr>
<% end %>

output

<style type="text/css"> 
TABLE.data { font-family: arial,serif;  font-size: 10pt;  background-color: white;  padding: 2; }
TH.data { font-family: arial,serif;  font-size: 10pt;  background-color: white;  text-align: left;  background-color: #999797;  color: #DCE5C1; }
.serviceOK { font-family: arial,serif;  font-size: 10pt;  text-align: left;  background-color: #33FF00;  font-weight: bold; }
.serviceCRITICAL { font-family: arial,serif;  font-size: 10pt;  text-align: left;  background-color: #F83838;  font-weight: bold; }
</style>

<TABLE BORDER=0 CLASS='data'>
<TR><TH CLASS='data'>Host</TH><TH CLASS='data'>Service</TH><TH CLASS='data'>% Uptime</TH>
<tr><td CLASS='data'>one</td><td CLASS='serviceOK'>two</td><td CLASS='serviceCRITICAL'>three</td></tr>
<tr><td CLASS='data'>one</td><td CLASS='serviceOK'>two</td><td CLASS='serviceCRITICAL'>three</td></tr>
<tr><td CLASS='data'>one</td><td CLASS='serviceOK'>two</td><td CLASS='serviceCRITICAL'>three</td></tr>