Class: Ucode::Audit::Browser::GlyphPanel

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

Overview

Service that builds per-codepoint glyph panel data for the missing-glyph reporter (TODO 26).

Two consumers:

- {MissingGlyphPage} — standalone per-block gallery; calls
{#to_hash} once per missing codepoint to inline SVG markup.
- The face browser JS — via the `universal_set` section that
{Emitter::IndexEmitter} embeds in `index.json`. The JS
fetches `<glyphs_dir>/U+XXXX.svg` at runtime using those
paths; this class doesn't need to be loaded client-side.

Reads the universal-set manifest once and builds a codepoint → Models::UniversalSetEntry index so per-codepoint lookups are O(1). SVG markup is read on demand from <universal_set_root>/glyphs/U+XXXX.svg.

When the universal-set root is nil or unreachable on disk, #available? returns false and #to_hash returns a minimal stub with available: false, svg: nil. Consumers render a text-only fallback in that case — the surrounding page still works.

Instance Method Summary collapse

Constructor Details

#initialize(universal_set_root:) ⇒ GlyphPanel

Returns a new instance of GlyphPanel.

Parameters:

  • universal_set_root (String, Pathname, nil)

    root of the universal-set build (e.g. "output/universal_glyph_set"). nil when no set is co-located.



41
42
43
44
45
# File 'lib/ucode/audit/browser/glyph_panel.rb', line 41

def initialize(universal_set_root:)
  @root = universal_set_root.nil? ? nil : Pathname.new(universal_set_root)
  @available = set_available?
  @entries_by_cp = @available ? build_entries_index : {}
end

Instance Method Details

#available?Boolean

Returns true when the universal-set root, manifest, and glyphs directory are all reachable on disk.

Returns:

  • (Boolean)

    true when the universal-set root, manifest, and glyphs directory are all reachable on disk



49
50
51
# File 'lib/ucode/audit/browser/glyph_panel.rb', line 49

def available?
  @available
end

#to_hash(codepoint) ⇒ Hash

Returns panel payload:

  • "codepoint" => Integer
  • "id" => "U+XXXX"
  • "available" => Boolean (per-codepoint glyph file exists)
  • "svg" => String markup, or nil when the SVG file is missing or the universal set is unavailable
  • "tier" => String (e.g. "tier-1"), or nil
  • "source" => String (e.g. "noto-sans"), or nil.

Parameters:

  • codepoint (Integer)

Returns:

  • (Hash)

    panel payload:

    • "codepoint" => Integer
    • "id" => "U+XXXX"
    • "available" => Boolean (per-codepoint glyph file exists)
    • "svg" => String markup, or nil when the SVG file is missing or the universal set is unavailable
    • "tier" => String (e.g. "tier-1"), or nil
    • "source" => String (e.g. "noto-sans"), or nil


62
63
64
65
66
67
68
69
70
71
# File 'lib/ucode/audit/browser/glyph_panel.rb', line 62

def to_hash(codepoint)
  {
    "codepoint" => codepoint,
    "id" => cp_id(codepoint),
    "available" => glyph_available?(codepoint),
    "svg" => read_svg(codepoint),
    "tier" => entry_for(codepoint)&.tier,
    "source" => entry_for(codepoint)&.source,
  }
end