Class: SkillBench::Services::HtmlFormatter

Inherits:
Object
  • Object
show all
Extended by:
FormattingHelpers
Defined in:
lib/skill_bench/services/html_formatter.rb

Overview

Formats evaluation results as a complete, self-contained HTML document.

The output embeds all styling inline (no external assets) and escapes every dynamic, user-derived value with CGI.escapeHTML to prevent HTML injection. Both the modern DeltaReport shape and the legacy result shape are supported.

Constant Summary collapse

STYLE =

Inline stylesheet embedded in every generated document.

<<~CSS
  body { font-family: -apple-system, Segoe UI, Roboto, sans-serif; margin: 2rem; color: #1a1a1a; background: #fafafa; }
  main { max-width: 960px; margin: 0 auto; }
  header { border-bottom: 2px solid #ddd; padding-bottom: 1rem; margin-bottom: 1.5rem; }
  h1 { margin: 0 0 0.5rem; font-size: 1.6rem; }
  dl.meta { display: grid; grid-template-columns: max-content 1fr; gap: 0.2rem 1rem; margin: 0.5rem 0; }
  dl.meta dt { font-weight: 600; color: #555; }
  dl.meta dd { margin: 0; }
  p.usage { color: #555; font-variant-numeric: tabular-nums; }
  table { border-collapse: collapse; width: 100%; margin: 1rem 0; }
  th, td { padding: 0.4rem 0.75rem; text-align: right; border-bottom: 1px solid #e2e2e2; }
  th:first-child, td:first-child { text-align: left; }
  tr.total td { font-weight: 700; border-top: 2px solid #bbb; }
  p.verdict { font-weight: 700; padding: 0.5rem 0.75rem; border-radius: 4px; display: inline-block; }
  p.verdict.pass { background: #e6f4ea; color: #1e7e34; }
  p.verdict.fail { background: #fde8e8; color: #c0392b; }
  p.error { color: #c0392b; }
  section.iterations h3 { margin-bottom: 0.25rem; }
  ol { margin: 0.25rem 0 1rem; }
  li { margin: 0.2rem 0; }
  span.tools, span.observation { color: #555; }
CSS

Class Method Summary collapse

Methods included from FormattingHelpers

delta_str, humanize, trend_icon, truncate

Class Method Details

.format(result) ⇒ String

Format an eval result as a full HTML document.

Parameters:

  • result (Hash)

    Eval result envelope (DeltaReport or legacy shape).

Returns:

  • (String)

    A complete HTML document string.



45
46
47
48
49
# File 'lib/skill_bench/services/html_formatter.rb', line 45

def self.format(result)
  report = result.dig(:response, :report)
  body = report.is_a?(SkillBench::DeltaReport) ? delta_body(result, report) : legacy_section(result)
  build_document(result, body)
end