Class: Ucode::Audit::Browser::Template

Inherits:
Object
  • Object
show all
Defined in:
lib/ucode/audit/browser/template.rb

Overview

Minimal ERB wrapper for the browser templates.

Reads an .erb template plus its sibling .css and .js assets from TEMPLATE_DIR, renders them with the supplied binding, and returns a complete HTML document.

Templates are plain ERB — no partials, no layouts, no helpers beyond what the binding provides. The CSS/JS assets are inlined into the rendered HTML so the page is fully self-contained (no external requests).

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ Template

Returns a new instance of Template.

Parameters:

  • name (String, Symbol)

    template name without extension (e.g. :face, :library)



24
25
26
# File 'lib/ucode/audit/browser/template.rb', line 24

def initialize(name)
  @name = name
end

Instance Method Details

#render(locals = {}) ⇒ String

Returns rendered HTML.

Parameters:

  • locals (Hash{Symbol=>Object}) (defaults to: {})

    variables exposed in the template binding

Returns:

  • (String)

    rendered HTML



31
32
33
34
35
36
37
# File 'lib/ucode/audit/browser/template.rb', line 31

def render(locals = {})
  erb = ERB.new(read("#{@name}.html.erb"), trim_mode: "-")
  erb.result_with_hash(locals.merge(
                         _css: read("#{@name}.css"),
                         _js: read("#{@name}.js"),
                       ))
end