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) ⇒ HtmlRenderer

Returns a new instance of HtmlRenderer.

Parameters:



107
108
109
110
# File 'lib/activerecord_callback_lens/renderer/html_renderer.rb', line 107

def initialize(graph, definitions)
  @graph = graph
  @definitions = definitions
end

Class Method Details

.render(graph, definitions:) ⇒ String

Returns a complete HTML document.

Parameters:

Returns:

  • (String)

    a complete HTML document



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

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

Instance Method Details

#renderString

Assembles the full HTML document.

Returns:

  • (String)


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

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