Expand description
hemplate: facade crate for the hemplate template language.
hemplate-runtime is always available. The default host feature exposes
AST/build APIs, while the independent derive feature exposes
#[derive(Hemplate)]. Constrained targets can disable defaults and enable
only derive, keeping parser and Tree-sitter dependencies host-only.
Dynamic native HTML Boolean attributes require a bool: false omits the
attribute, true emits its name. Strings such as "false" are not accepted.
Global HTML Booleans also apply to custom and unknown HTML elements.
HTML +hidden is different: it binds an enumerated attribute using
HiddenAttribute. Boolean false omits it, true emits its name, and string
states (including "until-found" and "false") remain escaped values.
References forward these semantics. Generic templates must require
HiddenAttribute, not just Display. Foreign content keeps ordinary escaped
value interpolation; ambiguous namespaces reject Boolean and +hidden
bindings. Use ordinary hidden="{+ value +}" for purely textual values there.
Escaping protects text, not attributes the browser reads as code. A plain
value interpolated into on*, style, srcdoc, a script or stylesheet URL,
or as the whole value of a URL attribute does not compile; use
Url::parse, a type implementing the context’s trait (UrlValue,
ScriptValue, …), or an explicit Trusted value. Fixed text that
settles a URL’s destination (href="/users/{+ id +}") takes plain values.
See the repository README, “Untrusted values and attribute contexts”.
use hemplate::Hemplate;
// templates/boolean_attrs.heml includes <input +checked="self.enabled">.
#[derive(Hemplate)]
struct BooleanAttrs {
enabled: &'static str,
value: &'static str,
hidden: bool,
}
impl BooleanAttrs {
fn next_hidden(&self) -> &bool { &self.hidden }
}A generic Display bound cannot silently stringify a Boolean hidden value:
use hemplate::{HiddenAttribute, HiddenValue};
fn hidden_state<T: core::fmt::Display>(value: &T) -> HiddenValue<'_> {
HiddenAttribute::hidden_value(value)
}Modules§
- ast
- AST types and parsing functions.
- context
- Attribute contexts and the typed values that may enter them. Attribute contexts and the typed values that may enter them.
- error
- Error types. Error type for rendering already-generated templates.
- escape
- HTML escape utility. HTML escaping utility.
- hidden
- Typed values for HTML’s enumerated
hiddenattribute. Typed values for HTML’s enumeratedhiddenattribute. - render
- Codegen dispatch helpers for interpolation.
Codegen dispatch helpers for
{+ expr +}and{+= expr =+}.
Structs§
- Extraction
Error - An error that occurs during AST node extraction.
- Html
Escape - Wrapper that HTML-escapes the Display output of the inner value.
- Parse
Error - An error that occurs during template parsing.
- Srcset
- A
srcsetwhose candidates are all checkedUrls. - Trusted
- A value someone vouches for in context
C, without any check. - Url
- A URL that is relative or has an allowed scheme:
http,https,mailtoortel.
Enums§
- Animation
Context - SVG animation value context marker.
- Build
Error - Top-level error type for host-side template processing.
- Descriptor
- How large a
srcsetcandidate renders. - Document
Context srcdoccontext marker.- Hidden
Value - The output state of an HTML
+hiddenbinding. - Html
Context - Raw HTML (
{+= =+}) context marker. - Navigation
Context <base href>and<meta http-equiv>context marker.- Render
Error - A failure while rendering an already-generated template.
- Resource
Context - Script, style and plug-in loading URL context marker.
- Script
Context - Script (
on*) context marker. - Srcset
Context srcsetcontext marker.- Style
Context stylecontext marker.- UrlContext
- URL context marker.
- UrlError
- Why a value is not accepted as a
UrlorSrcsetpart.
Traits§
- Animation
Value - A value that may be placed in
to,from,byorvaluesof an SVG animation. - Boolean
Attribute - A value for a dynamic HTML Boolean attribute such as
+disabled. - Context
- Marker for a context that
Trustedvalues can be created for. - Document
Value - A document that may be placed in
srcdoc. - Hemplate
- Trait for types that can render themselves as an HTML string.
- Hidden
Attribute - A value supported by HTML
+hiddenbindings. - Html
Value - Markup that raw interpolation
{+= value =+}may insert unescaped. - Navigation
Value - A value that may be placed in
<base href>or<meta http-equiv>. - Resource
Value - A URL that may load script, styles or plug-ins.
- Script
Value - JavaScript that may be placed in an
on*attribute. - Srcset
Value - A value that may be the whole value of a
srcsetattribute. - Style
Value - CSS that may be placed in a
styleattribute. - UrlValue
- A value that may be the whole value of a URL attribute.
Type Aliases§
- Trusted
Animation - An SVG animation value vouched for without a check.
- Trusted
Document - A document vouched for without a check.
- Trusted
Html - HTML markup vouched for without a check, for raw interpolation
{+= =+}. - Trusted
Navigation - A navigation value vouched for without a check.
- Trusted
Resource - A script, style or plug-in URL vouched for without a check.
- Trusted
Script - JavaScript vouched for without a check.
- Trusted
Srcset - A
srcsetvouched for without a check. - Trusted
Style - CSS vouched for without a check.
- Trusted
Url - A URL vouched for without a check, for example a
data:orsms:URL.