module CSVEmbedder
require 'csv'
class CSVTag < Liquid::Tag
def initialize(tag_name, url, tokens)
super
@url = url
end
def render(context)
# current directory
filedir = File.dirname(context.registers[:page]["path"])
csvpath = File.path(File.join(filedir, @url.strip))
table_tag = "
"
table_tag += 'Data from here: ' + @url + ''
count = 0
CSV.foreach(csvpath) do |row|
if count == 0
table_tag += ""
else
table_tag += ""
end
table_tag += ""
for item in row
table_tag += "#{item} | "
end
table_tag += "
"
if count == 0
table_tag += ""
else
table_tag += ""
end
count += 1
end
table_tag += "
"
end
end
end
Liquid::Template.register_tag('embedcsv', CSVEmbedder::CSVTag)