Class: ActiverecordCallbackLens::Renderer::HtmlRenderer

Inherits:
Object
  • Object
show all
Defined in:
lib/activerecord_callback_lens/renderer/html_renderer.rb

Overview

Renders a self-contained HTML report for a model's callbacks.

The document embeds five sections (spec section 8.3):

  1. Callback List — a table with columns Phase, Event, Filter, Conditions.
  2. Execution Flow — an ordered list sorted by ExecutionOrderAnalyzer (the :create path).
  3. Dependency Tree — a nested <ul> built from each definition's ConditionTree (via ConditionTreeHtml).
  4. Mermaid Diagram — a <pre class="mermaid"> block populated by MermaidRenderer and rendered client-side via the Mermaid CDN script.
  5. Graphviz SVG — the inline <svg> produced by GraphvizRenderer#to_svg when the dot binary is available; the section is omitted otherwise.

All user-derived text is HTML escaped with CGI.escapeHTML.

Constant Summary collapse

MERMAID_CDN =

The Mermaid.js bundle loaded from a CDN so the report stays a single, dependency-free HTML file.

"https://cdn.jsdelivr.net/npm/mermaid/dist/mermaid.min.js"

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(graph, definitions, expand: false) ⇒ HtmlRenderer

Returns a new instance of HtmlRenderer.

Parameters:

  • (defaults to: false)


109
110
111
112
113
# File 'lib/activerecord_callback_lens/renderer/html_renderer.rb', line 109

def initialize(graph, definitions, expand: false)
  @graph = graph
  @definitions = definitions
  @expand = expand
end

Class Method Details

.render(graph, definitions:, expand: false) ⇒ String

Returns a complete HTML document.

Parameters:

  • the assembled dependency graph

  • parsed definitions

  • (defaults to: false)

    expand proc filter labels to their source snippet

Returns:

  • a complete HTML document



102
103
104
# File 'lib/activerecord_callback_lens/renderer/html_renderer.rb', line 102

def self.render(graph, definitions:, expand: false)
  new(graph, definitions, expand: expand).render
end

Instance Method Details

#renderString

Assembles the full HTML document.

Returns:



118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
# File 'lib/activerecord_callback_lens/renderer/html_renderer.rb', line 118

def render
  "    <!DOCTYPE html>\n    <html>\n    <head><meta charset=\"utf-8\"><title>Callback Lens</title></head>\n    <body>\n    \#{callback_table}\n    \#{execution_flow}\n    \#{dependency_trees}\n    \#{mermaid_section}\n    \#{svg_section}\n    <script src=\"\#{MERMAID_CDN}\"></script>\n    <script>mermaid.initialize({startOnLoad:true});</script>\n    </body>\n    </html>\n  HTML\nend\n"