Skip to main content

Crate larust_view

Crate larust_view 

Source
Expand description

Blade-inspired template parsing for *.blade.xr files.

This crate is pure text parsing plus a small runtime (View, escape) - no syn/proc-macro2 dependency. Turning the parsed Node tree into actual Rust code lives in larust-macros’ view! macro, since that’s the part that needs the proc-macro toolchain and file-tracking plumbing that’s local to a specific crate compilation.

Modules§

push_registry
A small request-scoped runtime registry that lets @push content cross a boundary @stack/@push’s normal compile-time resolution can’t see across - specifically a <wire:...> mount point, which is a genuinely separate view!(...) call with no shared AST (see docs/GOTCHAS.md’s @push/@stack entry for the full picture).

Structs§

GlobalEntry
A parsed .blade.xr template, before layout resolution.
ParseError
A template parsing/resolution error. Deliberately just a message - larust-macros is the one place that can turn this into a proper spanned syn::Error, and the file/template context is usually already in the message by the time it gets there.
View
A rendered template. What view!(...) (in larust-macros) produces.

Enums§

Node

Functions§

escape
HTML-escapes a string for safe interpolation ({{ }}, not {!! !!}).
js
@js($expr)’s JS-safe (not HTML-escaped) serialization - drops a Serialize value into inline JavaScript as a JSON.parse('...') call, mirroring Laravel’s Illuminate\Support\Js::from() two-layer mechanism faithfully:
parse
resolve
Resolves @extends/@section/@yield/@push/@stack composition into a single, flat node list ready for codegen.
resolve_with_context
Same as resolve, but also returns the whole-tree @push/@globals collections it gathered along the way - needed by larust-macros, which loads and codegens each <resource:...> tag’s own named template separately from this call (see Node::Resource’s own doc comment in ast.rs), and must apply substitute_stacks/substitute_globals to that freshly-loaded content itself using these same maps - otherwise a @push/@stack pair split across a resource-tag boundary (the single most common shape in practice: a shared components.layouts.app providing @stack('head'), included via <resource:...> from every page, with pages pushing their own per-page <link>/<meta> tags into it) would never connect - @stack('head') sitting inside that separately-loaded layout file is invisible to this call’s own substitute_stacks, which only ever walks the nodes passed in as nodes here.
substitute_globals
Mirrors substitute_stacks below, but for @global: walks the fully resolved tree, replacing Node::Global { name, fallback } with a real Node::Interpolate sourced from whichever @globals block (anywhere in the chain) provided that name, falling back to fallback if none did, or nothing if there’s no fallback either - same “unset becomes empty” convention as an unset @stack. A persist-flagged entry substitutes to Node::PersistGlobal instead - its value isn’t known until request time, so it can’t collapse to a literal Interpolate the way every other entry does; see that node’s own doc comment.
substitute_stacks
Mirrors substitute_yields below, but for @stack - kept as a separate pass (run once, after the entire @extends chain is already section/yield-resolved) rather than folded into substitute_yields itself, since pushes needs contributions from every level of the chain before any @stack can be substituted correctly (see resolve_inner’s doc comment on collect_pushes).