Skip to main content

ExtraSlash

Struct ExtraSlash 

Source
pub struct ExtraSlash<Str, MapStr> {
    pub values: MapStr,
    pub default: Str,
}
Expand description

Add support for an extra slash (/) followed by a value for the utility classes handled by this plugin.

In practice, you give it a map with the accepted values after the slash as keys and the values you need to insert into the CSS value as values, as well as a default value in case no slash is found. Then, you add the placeholder {/} to your CSS values (or templates) and it will be replaced with the specified value.

§Example

use encre_css::{Config, generate};
use encre_css::prelude::build_plugin::*;

pub(crate) const PLUGIN: StaticPlugin = Plugin::ListValues(ListValues {
    prop: SingleProp("background-image"),
    values: map! {
        "custom-bg-img" => "linear-gradient(to top in {/}, #00aaff, #00ffaa)",
    },
    extra_slash: Some(ExtraSlash {
        values: map! {
            "increasing" => "oklch increasing hue",
            "oklab" => "oklab",
        },
        default: "oklab",
    }),
    ..ListValues::default()
});

let mut config = Config::default();
config.register_plugin(&PLUGIN);

let generated = generate(["custom-bg-img", "custom-bg-img/increasing"], &config);

assert!(generated.ends_with(".custom-bg-img {
  background-image: linear-gradient(to top in oklab, #00aaff, #00ffaa);
}

.custom-bg-img\\/increasing {
  background-image: linear-gradient(to top in oklch increasing hue, #00aaff, #00ffaa);
}"));

§Example in TOML

[[custom_plugins]]

[custom_plugins.ListValues]
prop = "background-image"

[custom_plugins.ListValues.values]
custom-bg-img = "linear-gradient(to top in {/}, #00aaff, #00ffaa)"

[custom_plugins.ListValues.extra_slash]
default = "oklab"

[custom_plugins.ListValues.extra_slash.values]
increasing = "oklch increasing hue"
oklab = "oklab"

Fields§

§values: MapStr

The mapping between the string parsed after the slash (/) and the actual values generated in the CSS value.

§default: Str

The key in ExtraSlash::values which is chosen by default when no slash is present in the utility class.

Trait Implementations§

Source§

impl<Str: Clone, MapStr: Clone> Clone for ExtraSlash<Str, MapStr>

Source§

fn clone(&self) -> ExtraSlash<Str, MapStr>

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<Str: Copy, MapStr: Copy> Copy for ExtraSlash<Str, MapStr>

Source§

impl<Str: Debug, MapStr: Debug> Debug for ExtraSlash<Str, MapStr>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de, Str, MapStr> Deserialize<'de> for ExtraSlash<Str, MapStr>
where Str: Deserialize<'de>, MapStr: Deserialize<'de>,

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl<Str: PartialEq, MapStr: PartialEq> PartialEq for ExtraSlash<Str, MapStr>

Source§

fn eq(&self, other: &ExtraSlash<Str, MapStr>) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl<Str, MapStr> Serialize for ExtraSlash<Str, MapStr>
where Str: Serialize, MapStr: Serialize,

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl<Str: PartialEq, MapStr: PartialEq> StructuralPartialEq for ExtraSlash<Str, MapStr>

Auto Trait Implementations§

§

impl<Str, MapStr> Freeze for ExtraSlash<Str, MapStr>
where MapStr: Freeze, Str: Freeze,

§

impl<Str, MapStr> RefUnwindSafe for ExtraSlash<Str, MapStr>
where MapStr: RefUnwindSafe, Str: RefUnwindSafe,

§

impl<Str, MapStr> Send for ExtraSlash<Str, MapStr>
where MapStr: Send, Str: Send,

§

impl<Str, MapStr> Sync for ExtraSlash<Str, MapStr>
where MapStr: Sync, Str: Sync,

§

impl<Str, MapStr> Unpin for ExtraSlash<Str, MapStr>
where MapStr: Unpin, Str: Unpin,

§

impl<Str, MapStr> UnsafeUnpin for ExtraSlash<Str, MapStr>
where MapStr: UnsafeUnpin, Str: UnsafeUnpin,

§

impl<Str, MapStr> UnwindSafe for ExtraSlash<Str, MapStr>
where MapStr: UnwindSafe, Str: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.