Class: Lilac::CLI::TemplateASTCache
- Inherits:
-
Object
- Object
- Lilac::CLI::TemplateASTCache
- Defined in:
- lib/lilac/cli/build/template_ast_cache.rb
Overview
Memoizes parsed component template ASTs by component name. The
same .lil shape often appears on many pages; the parse step is
not free and the parsed result is immutable, so caching once per
build keeps multi-page builds linear in components rather than
pages × components.
Shared by Builder (when emitting the :bundle delivery file) and
PageCompiler (per-page injection). Both read through fetch;
writes happen lazily on miss.
Defined Under Namespace
Classes: RenderedTemplate
Instance Method Summary collapse
-
#fetch(name, component) ⇒ Object
Returns a Hash with: :default_html — concatenated body HTML of the default templates :default_directives — Array
for top-level binding emission :default_refs_map — Hash { ref_name => line } for lint :named — Array (user-defined) :source_path — Path to the .lil(or in-memory page). -
#initialize ⇒ TemplateASTCache
constructor
A new instance of TemplateASTCache.
Constructor Details
#initialize ⇒ TemplateASTCache
Returns a new instance of TemplateASTCache.
22 23 24 |
# File 'lib/lilac/cli/build/template_ast_cache.rb', line 22 def initialize @cache = {} end |
Instance Method Details
#fetch(name, component) ⇒ Object
Returns a Hash with:
:default_html — concatenated body HTML of the default templates
:default_directives — Array<Directive> for top-level binding emission
:default_refs_map — Hash { ref_name => line } for lint
:named — Array<RenderedTemplate> (user-defined)
:source_path — Path to the `.lil` (or in-memory page)
32 33 34 |
# File 'lib/lilac/cli/build/template_ast_cache.rb', line 32 def fetch(name, component) @cache[name] ||= parse(component) end |