pub struct AttributeBag { /* private fields */ }Expand description
An ordered collection of attributes supplied to a component or slot.
Implementations§
Source§impl AttributeBag
impl AttributeBag
Sourcepub fn new(attributes: Attributes) -> Self
pub fn new(attributes: Attributes) -> Self
Create a bag from raw attributes. Each value retains its current escaping.
Sourcepub fn all(&self) -> &Attributes
pub fn all(&self) -> &Attributes
The raw attributes, including null values and omitted Boolean attributes.
Sourcepub fn all_for(&self, keys: &[&str]) -> Attributes
pub fn all_for(&self, keys: &[&str]) -> Attributes
Return the raw attributes for the requested keys in their original order.
Sourcepub fn first(&self) -> Option<&AttributeValue>
pub fn first(&self) -> Option<&AttributeValue>
The first value, if the first entry exists and is non-null.
Sourcepub fn get(&self, key: &str) -> Option<&AttributeValue>
pub fn get(&self, key: &str) -> Option<&AttributeValue>
Look up an exact key. Null values take the default path, as in Laravel.
Sourcepub fn get_or_else(
&self,
key: &str,
default: impl FnOnce() -> AttributeValue,
) -> AttributeValue
pub fn get_or_else( &self, key: &str, default: impl FnOnce() -> AttributeValue, ) -> AttributeValue
Find a value or lazily compute a fallback.
Sourcepub fn first_or_else(
&self,
default: impl FnOnce() -> AttributeValue,
) -> AttributeValue
pub fn first_or_else( &self, default: impl FnOnce() -> AttributeValue, ) -> AttributeValue
Retrieve the first value or lazily compute a fallback.
Sourcepub fn except(&self, keys: &[&str]) -> Self
pub fn except(&self, keys: &[&str]) -> Self
Exclude the requested keys. Dotted names can also remove nested array entries.
Sourcepub fn filter(
&self,
predicate: impl FnMut(&AttributeValue, &str) -> bool,
) -> Self
pub fn filter( &self, predicate: impl FnMut(&AttributeValue, &str) -> bool, ) -> Self
Retain entries whose value and key pass the callback.
Sourcepub fn where_starts_with(&self, prefixes: &[&str]) -> Self
pub fn where_starts_with(&self, prefixes: &[&str]) -> Self
Retain keys that begin with any nonempty prefix.
Sourcepub fn where_doesnt_start_with(&self, prefixes: &[&str]) -> Self
pub fn where_doesnt_start_with(&self, prefixes: &[&str]) -> Self
Retain keys that begin with none of the nonempty prefixes.
Sourcepub fn that_start_with(&self, prefixes: &[&str]) -> Self
pub fn that_start_with(&self, prefixes: &[&str]) -> Self
Alias for where_starts_with.
Sourcepub fn extract_prop_names(names: &[&str]) -> Vec<String>
pub fn extract_prop_names(names: &[&str]) -> Vec<String>
Expand template-facing prop names to include the name and Laravel’s kebab-case spelling.
Sourcepub fn only_props(&self, names: &[&str]) -> Self
pub fn only_props(&self, names: &[&str]) -> Self
Retain prop attributes by their declared or kebab-case name.
Sourcepub fn except_props(&self, names: &[&str]) -> Self
pub fn except_props(&self, names: &[&str]) -> Self
Exclude prop attributes by their declared or kebab-case name.
Sourcepub fn has(&self, keys: &[&str]) -> bool
pub fn has(&self, keys: &[&str]) -> bool
Whether all keys exist, including keys with null values and nested array paths.
Sourcepub fn has_any(&self, keys: &[&str]) -> bool
pub fn has_any(&self, keys: &[&str]) -> bool
Whether any key exists, including keys with null values and nested array paths.
Sourcepub fn missing(&self, keys: &[&str]) -> bool
pub fn missing(&self, keys: &[&str]) -> bool
Whether at least one of the requested keys is missing.
Sourcepub fn when<T: From<Self>>(
&self,
condition: bool,
callback: impl FnOnce(&Self, bool) -> Option<T>,
) -> T
pub fn when<T: From<Self>>( &self, condition: bool, callback: impl FnOnce(&Self, bool) -> Option<T>, ) -> T
Apply a transformation when the Boolean condition holds.
The result can be a bag or a caller’s runtime value that can also hold the fallback bag.
Sourcepub fn unless<T: From<Self>>(
&self,
condition: bool,
callback: impl FnOnce(&Self, bool) -> Option<T>,
) -> T
pub fn unless<T: From<Self>>( &self, condition: bool, callback: impl FnOnce(&Self, bool) -> Option<T>, ) -> T
Apply a transformation when the Boolean condition is false.
Sourcepub fn when_else<T: From<Self>>(
&self,
condition: bool,
callback: impl FnOnce(&Self, bool) -> Option<T>,
default: impl FnOnce(&Self, bool) -> Option<T>,
) -> T
pub fn when_else<T: From<Self>>( &self, condition: bool, callback: impl FnOnce(&Self, bool) -> Option<T>, default: impl FnOnce(&Self, bool) -> Option<T>, ) -> T
Apply either branch, falling back to the original bag if the selected callback returns null.
Sourcepub fn unless_else<T: From<Self>>(
&self,
condition: bool,
callback: impl FnOnce(&Self, bool) -> Option<T>,
default: impl FnOnce(&Self, bool) -> Option<T>,
) -> T
pub fn unless_else<T: From<Self>>( &self, condition: bool, callback: impl FnOnce(&Self, bool) -> Option<T>, default: impl FnOnce(&Self, bool) -> Option<T>, ) -> T
Apply either branch, running the main callback when the condition is false.
Sourcepub fn prepends(&self, value: impl Into<AttributeValue>) -> AttributeValue
pub fn prepends(&self, value: impl Into<AttributeValue>) -> AttributeValue
Construct a default value which appends the provided attribute after the default.
Sourcepub fn class(&self, entries: &[CssEntry<'_>]) -> Result<Self, AttributeError>
pub fn class(&self, entries: &[CssEntry<'_>]) -> Result<Self, AttributeError>
Merge a class list through the same escaped-default path as merge.
Sourcepub fn style(&self, entries: &[CssEntry<'_>]) -> Result<Self, AttributeError>
pub fn style(&self, entries: &[CssEntry<'_>]) -> Result<Self, AttributeError>
Merge a style list, finishing each style with a semicolon.
Sourcepub fn merge(
&self,
defaults: &Attributes,
escape: bool,
) -> Result<Self, AttributeError>
pub fn merge( &self, defaults: &Attributes, escape: bool, ) -> Result<Self, AttributeError>
Add defaults in their supplied order, optionally escaping them. Class, style and prepended defaults are joined with supplied values rather than being replaced.
Sourcepub fn insert_literal(
&mut self,
name: impl Into<String>,
value: impl Into<String>,
)
pub fn insert_literal( &mut self, name: impl Into<String>, value: impl Into<String>, )
Insert a compiler literal. An interpolated literal must already contain escaped echoes. The literal fragments and the rendered echoes retain their exact bytes here.
Sourcepub fn insert_bound(
&mut self,
name: impl Into<String>,
value: impl Into<AttributeValue>,
)
pub fn insert_bound( &mut self, name: impl Into<String>, value: impl Into<AttributeValue>, )
Insert a bound attribute, applying Laravel’s sanitizeComponentAttribute rules.
Sourcepub fn forward(&self, parent: &Self) -> Result<Self, AttributeError>
pub fn forward(&self, parent: &Self) -> Result<Self, AttributeError>
Forward a parent bag. Local attributes act as its unescaped defaults.
Sourcepub fn get_attributes(&self) -> &Attributes
pub fn get_attributes(&self) -> &Attributes
Read the underlying attributes, including omitted values.
Sourcepub fn set_attributes(&mut self, attributes: Attributes)
pub fn set_attributes(&mut self, attributes: Attributes)
Replace the raw attributes without escaping them.
Sourcepub fn offset_exists(&self, key: &str) -> bool
pub fn offset_exists(&self, key: &str) -> bool
Whether an offset is set and non-null, following PHP’s isset.
Sourcepub fn offset_get(&self, key: &str) -> Option<&AttributeValue>
pub fn offset_get(&self, key: &str) -> Option<&AttributeValue>
Access a non-null value by its exact key.
Sourcepub fn offset_set(
&mut self,
key: impl Into<String>,
value: impl Into<AttributeValue>,
)
pub fn offset_set( &mut self, key: impl Into<String>, value: impl Into<AttributeValue>, )
Set an offset without sanitizing the value.
Sourcepub fn offset_unset(&mut self, key: &str)
pub fn offset_unset(&mut self, key: &str)
Remove an offset, preserving the order of the remaining entries.
Sourcepub fn get_iterator(&self) -> Iter<'_, String, AttributeValue> ⓘ
pub fn get_iterator(&self) -> Iter<'_, String, AttributeValue> ⓘ
Iterate over the raw values in insertion order.
Sourcepub fn json_serialize(&self) -> &Attributes
pub fn json_serialize(&self) -> &Attributes
Return the raw map as a serialization input.
Sourcepub fn to_array(&self) -> Attributes
pub fn to_array(&self) -> Attributes
Return the raw attributes as an ordered map.
Sourcepub fn invoke(&self, defaults: &Attributes) -> Result<String, AttributeError>
pub fn invoke(&self, defaults: &Attributes) -> Result<String, AttributeError>
Merge escaped defaults and render the result, as when a Blade bag is called.
Sourcepub fn is_empty(&self) -> Result<bool, AttributeError>
pub fn is_empty(&self) -> Result<bool, AttributeError>
Whether the bag renders to an empty string.
Sourcepub fn is_not_empty(&self) -> Result<bool, AttributeError>
pub fn is_not_empty(&self) -> Result<bool, AttributeError>
Whether the bag renders any HTML attributes.
Sourcepub fn to_html(&self) -> Result<String, AttributeError>
pub fn to_html(&self) -> Result<String, AttributeError>
Render the attributes using HTML encoding, preserving existing entities.