Emojis
Embeds ~200 commonly-used emoji as SVG assets from Twemoji (https://github.com/jdecked/twemoji), with an opt-in on-disk cache for the rest of the catalogue.
All curated SVGs are read and inlined at compile time (via the
read_file macro), so consumers don't need to ship the
data/ directory alongside their compiled binaries.
Lookup chain :
- The 208 curated emojis are baked into the binary and served from RAM.
- Anything else is looked up in the on-disk cache (cf.
Emojis::Cache). The cache is empty by default — populate it viaEmojis::Cache.pull(API) oremojis pull(CLI). - If still not found, returns
niland the caller decides (typically substitutes with?or text fallback).
Why two layers : the curated set covers the 90 % case of technical documentation (status, colours, dev tools…) at near-zero cost (~840 KB embedded). The cache covers the long tail without inflating every dependent binary by 18 MB.
Constants
Compile-time hash of codepoint_key => svg_content for the
curated set. Codepoint keys are lowercase hex, multi-codepoint
sequences joined with - (Twemoji file naming convention).
Built from data/svg/MANIFEST.txt.
Version of Twemoji whose curated assets are embedded.
Version of this Crystal shard.
Lue au compile-time depuis shard.yml via le macro read_file.
Cf. note mémoire feedback_shard_version_macro.md (mémoire ALOLI).
Class methods
Iterates over every (key, svg) pair in the embedded curated
set only — the cache is intentionally NOT walked, since it can
grow to thousands of entries and most callers using each want
to enumerate the small fast set, not the disk one.
Returns true when either the curated set or the cache
has an SVG for the given codepoint. Cheaper than svg(...) for
the curated branch (no string copy), but the cache branch still
has to stat the file.
Returns true when either the curated set or the cache
has an SVG for the given codepoint. Cheaper than svg(...) for
the curated branch (no string copy), but the cache branch still
has to stat the file.
Returns every embedded codepoint key (sorted alphabetically).
Useful for --list-emojis style commands or for documentation.
Returns the number of emojis in the embedded curated set
(does NOT count cached SVGs ; see Cache.size for that).
Returns the raw SVG content for a single-codepoint emoji.
Pass a Char (most natural) or an Int32 codepoint.
Looks up first in the embedded curated set, then in the
on-disk cache. Returns nil when neither has the emoji —
callers should fall back to text.
Emojis.svg('✅') # => "<svg ...>" (curated)
Emojis.svg('🦄') # => "<svg ...>" if cache populated, else nil
Emojis.svg('é') # => nil (not an emoji)
Returns the raw SVG content for a single-codepoint emoji.
Pass a Char (most natural) or an Int32 codepoint.
Looks up first in the embedded curated set, then in the
on-disk cache. Returns nil when neither has the emoji —
callers should fall back to text.
Emojis.svg('✅') # => "<svg ...>" (curated)
Emojis.svg('🦄') # => "<svg ...>" if cache populated, else nil
Emojis.svg('é') # => nil (not an emoji)
Returns the SVG for a multi-codepoint emoji sequence (e.g. an emoji modified by a skin-tone or zero-width-joiner). Pass an array of codepoints in source order.
The curated set focuses on single-codepoint emojis ; sequences are typically only available once the cache has been populated.
# 👨💻 = MAN (1F468) + ZWJ (200D) + LAPTOP (1F4BB)
Emojis.svg([0x1F468, 0x200D, 0x1F4BB])