module Panda
module CMS
module EditorJs
module Blocks
class Table < Base
def render
content = data["content"]
with_headings = data["withHeadings"]
html_safe(<<~HTML)
#{render_rows(content, with_headings)}
HTML
end
private
def render_rows(content, with_headings)
rows = []
index = 0
while index < content.length
rows << if index == 0 && with_headings
render_header_row(content[index])
else
render_data_row(content[index])
end
index += 1
end
rows.join("\n")
end
def render_header_row(row)
cells = row.map { |cell| "#{sanitize(cell)} | " }
"#{cells.join}
"
end
def render_data_row(row)
cells = row.map { |cell| "#{sanitize(cell)} | " }
"#{cells.join}
"
end
end
end
end
end
end