10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
|
# File 'lib/embed_csv.rb', line 10
def render(context)
filedir = File.dirname(context.registers[:page]["path"])
csvpath = File.path(File.join(filedir, @url.strip))
table_tag = "<table>"
table_tag += '<caption>Data from here: <a href="'+ @url + '">' + @url + '</a></caption>'
count = 0
CSV.foreach(csvpath) do |row|
if count == 0
table_tag += "<thead>"
else
table_tag += "<tbody>"
end
table_tag += "<tr>"
for item in row
table_tag += "<td>#{item}</td>"
end
table_tag += "</tr>"
if count == 0
table_tag += "</thead>"
else
table_tag += "</tbody>"
end
count += 1
end
table_tag += "</table>"
end
|