Skip to content

Instantly share code, notes, and snippets.

@hammady
Created April 19, 2015 12:30
Show Gist options
  • Save hammady/a1d9996f09f1516a3972 to your computer and use it in GitHub Desktop.
Save hammady/a1d9996f09f1516a3972 to your computer and use it in GitHub Desktop.
Simple ERB template to convert CSV rows to HTML cards
<!--
If your input file is in Excel format, use xlsx2csv python tool available at
https://github.com/dilshod/xlsx2csv
Usage is simple, you need ruby installed (including erb)
rename the input file to input.csv, then just run:
erb csv2webcards.erb > output.html
Now open output.html in any browser to see the HTML cards
Author: Hossam Hammady ([email protected])
-->
<%
require 'csv'
csv_opts = {:headers => true, :return_headers => false}
data = CSV.read 'input.csv', csv_opts
%>
<html>
<style>
.card {
margin: 10px;
padding: 10px;
background-color: oldlace;
border: 1px solid black;
border-radius: 5px;
}
.card li {
margin-bottom: 5px;
}
</style>
<body>
<% header = [] %>
<% data.each_with_index do |row, index| %>
<h2>Row #<%= index+1 %></h2>
<div class='card'>
<ul>
<% row.each do |key, value| %>
<% unless value.nil? %><li><strong><%= key %>: </strong><br/><%= value %></li><%end%>
<% end %>
</ul>
</div>
<% end %>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment