Skip to main content

generate_compiled_template

Function generate_compiled_template 

Source
pub fn generate_compiled_template(
    tag_name: &str,
    html_content: &str,
) -> Result<String>
Expand description

Generate a compiled template as JSON-safe metadata.

The returned string is the metadata data payload. Condition closures are emitted separately by [generate_compiled_template_with_root_source].

§Flow

  1. Extract @event bindings from the <template> wrapper (→ root_events).
  2. Strip the <template shadowrootmode="…"> wrapper if present.
  3. Compile the inner body via [compile_to_metadata].
  4. Serialize into JSON metadata and component-local condition closures.

§Compilation rules

Source syntaxMetadata field(s)Client h result
{{expr}}, {{{expr}}}, mixed texttx[]dynamic text run removed
href="{{url}}", class="x {{y}}"a[] + ag[]element kept marker-free
?disabled="{{expr}}"a[] + ag[]element kept marker-free
:config="{{settings}}"a[] + ag[]element kept marker-free
<if condition="…">body</if>c[] + cl[] + b[]block removed; anchor slot stored
<for each="v in coll">body</for>r[] + rl[] + b[]block removed; anchor slot stored
first concrete key="{{v.id}}"optional fifth r[] fieldrelative repeat key path stored
<link> / <style> child nodeshpreserved in static HTML
module adopted stylesheet specifiersastored from <template> wrapper
@event="{handler(e)}"eg[]element kept marker-free
w-ref="name" / w-ref={name}(stays in HTML)(unchanged)
<outlet /> / <outlet>(stays in HTML)<outlet></outlet>

§Errors

Returns crate::ParserError::Template if the template contains an invalid @event handler, non-braced w-ref, or invalid concrete-child repeat key.