pub struct Component {
pub name: String,
pub props: Vec<String>,
pub defaults: HashMap<String, String>,
pub template: String,
}Expand description
A custom component definition
Fields§
§name: StringComponent name (e.g., “what-card”, “what-modal”)
props: Vec<String>Expected props
defaults: HashMap<String, String>Default values for props
template: StringTemplate content
Implementations§
Source§impl Component
impl Component
Sourcepub fn from_file(path: impl AsRef<Path>) -> Result<Self>
pub fn from_file(path: impl AsRef<Path>) -> Result<Self>
Load a component from an HTML template file (legacy format with wrapper tag)
Sourcepub fn from_file_with_name(path: impl AsRef<Path>) -> Result<Self>
pub fn from_file_with_name(path: impl AsRef<Path>) -> Result<Self>
Load a component from a file, deriving the name from the filename
This is the new recommended format where:
- Filename becomes the component name:
nav.html→nav - Props and defaults are defined in a
<what>block - Template content is everything outside the
<what>block
Sourcepub fn parse_with_name(content: &str, name: String) -> Result<Self>
pub fn parse_with_name(content: &str, name: String) -> Result<Self>
Parse component content with a provided name (filename-based)
Supports both new <what> block format and legacy wrapper tag format.
Sourcepub fn parse(content: &str) -> Result<Self>
pub fn parse(content: &str) -> Result<Self>
Parse a component definition from HTML template content (legacy format)
Expected format:
<component name="card" props="title, slug">
<article class="card">
<h3>#title#</h3>
<slot/>
</article>
</component>Sourcepub fn render(
&self,
props: &HashMap<String, String>,
children: Option<&str>,
context: &HashMap<String, Value>,
) -> String
pub fn render( &self, props: &HashMap<String, String>, children: Option<&str>, context: &HashMap<String, Value>, ) -> String
Render the component with given props and children
Priority order (highest to lowest):
- Passed props (from usage)
- Defaults (from component definition)
- Empty string (for undeclared props)
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Component
impl RefUnwindSafe for Component
impl Send for Component
impl Sync for Component
impl Unpin for Component
impl UnsafeUnpin for Component
impl UnwindSafe for Component
Blanket Implementations§
Source§impl<T> ArchivePointee for T
impl<T> ArchivePointee for T
Source§type ArchivedMetadata = ()
type ArchivedMetadata = ()
The archived version of the pointer metadata for this type.
Source§fn pointer_metadata(
_: &<T as ArchivePointee>::ArchivedMetadata,
) -> <T as Pointee>::Metadata
fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata, ) -> <T as Pointee>::Metadata
Converts some archived metadata to the pointer metadata for itself.
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<F, W, T, D> Deserialize<With<T, W>, D> for F
impl<F, W, T, D> Deserialize<With<T, W>, D> for F
impl<A, B, T> HttpServerConnExec<A, B> for Twhere
B: Body,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more