Class: Markdownplus::Csv2HtmlHandler

Inherits:
Handler
  • Object
show all
Defined in:
lib/markdownplus/handler.rb

Instance Method Summary collapse

Instance Method Details

#execute(input, parameters, variables, warnings, errors) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/markdownplus/handler.rb', line 35

def execute(input, parameters, variables, warnings, errors)
  output = "<table class='table table-striped'>"
  row_num = 0
  CSV.parse(input) do |row|
    if row_num == 0
      output += "<thead><tr>#{row.collect { |c| "<th>#{c}</th>"}.join}</tr></thead>\n<tbody>\n"
    else
      output += "<tr>#{row.collect { |c| "<td>#{c}</td>"}.join}</tr>\n"
    end
    row_num += 1
  end
  output += "</tbody></table>"
  output
end