Class: Ucode::Audit::Browser::FacePage

Inherits:
Object
  • Object
show all
Includes:
Repo::AtomicWrites
Defined in:
lib/ucode/audit/browser/face_page.rb

Overview

Renders one face's index.html — a fully self-contained browser page for one audited font.

The page inlines the same JSON shape that Emitter::IndexEmitter writes to index.json, plus inlined CSS and JS. Opening the file via file:// renders the overview immediately; lazy fetches of the per-block chunks (blocks/<NAME>.json, codepoints/<NAME>.json, glyphs/U+XXXX.svg) work when the directory is served over HTTP.

Self-contained: no external CSS, no external JS, no CDN. Portable: the entire <label>/ directory can be moved/served whole and the page still works.

Two construction modes — pass exactly one of:

- `report:` — a live {Models::Audit::AuditReport}. The JSON
shape is derived via {Emitter::IndexEmitter#build_index}.
Used by {Emitter::FaceDirectory} when emitting alongside
the audit.
- `overview_json:` — a pre-built JSON string of the overview
shape. Used by {Commands::AuditBrowserCommand} when
regenerating HTML from an existing `index.json`.

Instance Method Summary collapse

Methods included from Repo::AtomicWrites

#same_content?, #to_pretty_json, #write_atomic

Constructor Details

#initialize(report: nil, overview_json: nil, verbose: false, with_glyphs: false, universal_set_root: nil, face_dir: nil) ⇒ FacePage

Returns a new instance of FacePage.

Parameters:

  • report (Models::Audit::AuditReport, nil) (defaults to: nil)
  • overview_json (String, nil) (defaults to: nil)

    pre-built overview JSON

  • verbose (Boolean) (defaults to: false)

    when true, the rendered page advertises per-block codepoint detail chunks

  • with_glyphs (Boolean) (defaults to: false)

    when true, the rendered page advertises that glyphs/U+XXXX.svg chunks exist

  • universal_set_root (String, Pathname, nil) (defaults to: nil)

    when both this and face_dir: are present and the root exists, the inlined overview JSON carries a universal_set section with relative paths. The face browser JS uses these to fetch universal-set glyphs for missing-codepoint chips.

  • face_dir (String, Pathname, nil) (defaults to: nil)

    destination face directory. Required when universal_set_root: is set and the caller wants relative paths resolved; otherwise optional. write(face_dir) overrides this.

Raises:

  • (ArgumentError)


55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/ucode/audit/browser/face_page.rb', line 55

def initialize(report: nil, overview_json: nil, verbose: false,
               with_glyphs: false, universal_set_root: nil, face_dir: nil)
  raise ArgumentError, "pass exactly one of report: / overview_json:" \
    unless report.nil? ^ overview_json.nil?

  @report = report
  @overview_json = overview_json
  @verbose = verbose
  @with_glyphs = with_glyphs
  @universal_set_root = universal_set_root
  @face_dir = face_dir
end

Instance Method Details

#renderString

Render the page as a string. Useful in tests.

Returns:

  • (String)


78
79
80
81
82
83
84
85
86
# File 'lib/ucode/audit/browser/face_page.rb', line 78

def render
  Template.new(:face).render(
    overview_json: overview_json,
    page_title: page_title,
    verbose: @verbose,
    with_glyphs: @with_glyphs,
    universal_set: universal_set_section,
  )
end

#write(face_dir) ⇒ Boolean

Write the rendered page to <face_dir>/index.html.

Parameters:

  • face_dir (String, Pathname)

Returns:

  • (Boolean)

    true if written, false if skipped



71
72
73
74
# File 'lib/ucode/audit/browser/face_page.rb', line 71

def write(face_dir)
  @face_dir = Pathname.new(face_dir)
  write_atomic(@face_dir.join("index.html"), render)
end