Module: TalkToYourApp::Renderers::HtmlTable

Defined in:
lib/talk_to_your_app/renderers/html_table.rb

Overview

Minimal HTML table renderer — no ActionView dependency. Every value is HTML-escaped via CGI.escape_html; the output is returned as a plain string for an MCP text content block and is never marked html_safe. NULL cells render as empty.

Class Method Summary collapse

Class Method Details

.esc(value) ⇒ Object



22
23
24
# File 'lib/talk_to_your_app/renderers/html_table.rb', line 22

def esc(value)
  CGI.escape_html(value.to_s)
end

.render(columns, rows) ⇒ Object



14
15
16
17
18
19
20
# File 'lib/talk_to_your_app/renderers/html_table.rb', line 14

def render(columns, rows)
  head = "<thead><tr>#{columns.map { |c| "<th>#{esc(c)}</th>" }.join}</tr></thead>"
  body = rows.map do |row|
    "<tr>#{row.map { |cell| "<td>#{cell.nil? ? "" : esc(cell)}</td>" }.join}</tr>"
  end.join
  "<table>#{head}<tbody>#{body}</tbody></table>"
end