Skip to content

Commit

Permalink
rename and rework exports
Browse files Browse the repository at this point in the history
  • Loading branch information
nicoburniske committed Mar 7, 2024
1 parent 60276b6 commit 784ff54
Show file tree
Hide file tree
Showing 13 changed files with 34 additions and 29 deletions.
2 changes: 1 addition & 1 deletion fuse/benches/merge.rs
@@ -1,5 +1,5 @@
use divan::Bencher;
use tailwind_fuse::{tw_merge, tw_merge_slice};
use tailwind_fuse::merge::{tw_merge, tw_merge_slice};

fn main() {
divan::main();
Expand Down
File renamed without changes.
Expand Up @@ -751,7 +751,7 @@ pub fn get_collision_id(classes: &[&str], arbitrary: &str) -> Result<&'static st
// https://tailwindcss.com/docs/forced-color-adjust
["forced", "color", "adjust", "auto" | "none"] => Ok("forced-color-adjust"),

_ => Err("Invalid tailwind class"),
_ => Err("Invalid Tailwind class"),
}
}

Expand Down
File renamed without changes.
Expand Up @@ -3,15 +3,15 @@ use std::collections::HashSet;
use crate::ast::AstStyle;

use super::{CollisionIdFn, GetCollisionsFn, MergeOptions};
use crate::fuse::merge::get_collisions::get_collisions;
use crate::core::merge::get_collisions::get_collisions;

/// Merges all the tailwind classes, resolving conflicts.
/// Merges all the Tailwind classes, resolving conflicts.
/// Can supply custom options, collision_id_fn and collisions_fn.
pub fn tw_merge_with_override(
class: &[&str],
options: MergeOptions,
collision_id_fn: impl CollisionIdFn,
collisions_fn: impl GetCollisionsFn,
class: &[&str],
) -> String {
let styles: Vec<Result<AstStyle, &str>> = crate::ast::parse_tailwind(class, options.into());

Expand Down
24 changes: 13 additions & 11 deletions fuse/src/fuse/merge/mod.rs → fuse/src/core/merge/mod.rs
Expand Up @@ -3,7 +3,9 @@ pub(crate) mod get_collisions;
pub(crate) mod merge_impl;
mod validators;

/// Merges all the tailwind classes, resolving conflicts.
pub use merge_impl::tw_merge_with_override;

/// Merges all the Tailwind classes, resolving conflicts.
///
/// Items can be of type &[`str`], [`String`], [`Option<&str>`] or [`Option<String>`].
///
Expand All @@ -14,21 +16,21 @@ mod validators;
macro_rules! tw_merge {
($($item:expr),+ $(,)?) => {{
let joined = $crate::tw_join!($($item),+);
$crate::tw_merge(joined.as_str())
$crate::merge::tw_merge(joined.as_str())
}};
}

/// Merges all the tailwind classes, resolving conflicts.
/// Merges all the Tailwind classes, resolving conflicts.
pub fn tw_merge(class: impl AsRef<str>) -> String {
tw_merge_slice(&[class.as_ref()])
}

/// Merges all the tailwind classes, resolving conflicts, with the provided options.
/// Merges all the Tailwind classes, resolving conflicts, with the provided options.
///
/// ## Example: With Tailwind Prefix
///
/// ```
/// # use tailwind_fuse::*;
/// # use tailwind_fuse::merge::*;
/// const OPTIONS: MergeOptions = MergeOptions {
/// prefix: "tw-",
/// separator: ":",
Expand All @@ -40,20 +42,20 @@ pub fn tw_merge(class: impl AsRef<str>) -> String {
/// ```
pub fn tw_merge_with_options(class: impl AsRef<str>, options: MergeOptions) -> String {
merge_impl::tw_merge_with_override(
&[class.as_ref()],
options,
noop_collision_id_fn,
noop_collision_fn,
&[class.as_ref()],
)
}

/// Merges all the tailwind classes, resolving conflicts.
/// Merges all the Tailwind classes, resolving conflicts.
pub fn tw_merge_slice(class: &[&str]) -> String {
merge_impl::tw_merge_with_override(
class,
Default::default(),
noop_collision_id_fn,
noop_collision_fn,
class,
)
}

Expand All @@ -65,7 +67,7 @@ fn noop_collision_fn(_: &str) -> Option<Vec<&'static str>> {
None
}

/// Configuration for merging tailwind classes.
/// Configuration for merging Tailwind classes.
#[derive(Clone, Copy, Debug)]
pub struct MergeOptions {
/// Custom prefix for modifiers in Tailwind classes
Expand Down Expand Up @@ -104,11 +106,11 @@ impl From<MergeOptions> for crate::ast::AstParseOptions<'static> {

/// Return a ConflictId for a given Tailwind Class.
pub trait CollisionIdFn {
/// elements: parts of the tailwind class separated by `-`.
/// elements: parts of the Tailwind class separated by `-`.
///
/// (e.g. `bg-red-500` would be `["bg", "red", "500"]`)
///
/// arbitrary: the arbitrary value at the end of the tailwind class
/// arbitrary: the arbitrary value at the end of the Tailwind class
///
/// <https://tailwindcss.com/docs/adding-custom-styles#using-arbitrary-values>
fn apply(&self, elements: &[&str], arbitrary: Option<&str>) -> Option<&'static str>;
Expand Down
File renamed without changes.
3 changes: 2 additions & 1 deletion fuse/src/fuse/mod.rs → fuse/src/core/mod.rs
@@ -1,6 +1,7 @@
pub(crate) mod join;

pub(crate) mod merge;
/// Merges all the Tailwind classes, resolving conflicts.
pub mod merge;

/// Used to extract a &str from a type
///
Expand Down
14 changes: 7 additions & 7 deletions fuse/src/lib.rs
Expand Up @@ -294,35 +294,35 @@ pub use tailwind_fuse_macro::TwClass;
#[cfg(feature = "variant")]
pub use tailwind_fuse_macro::TwVariant;

pub use crate::fuse::merge::merge_impl::*;
pub use crate::fuse::merge::*;
pub use crate::fuse::*;
pub use crate::core::merge;
pub use crate::core::*;

mod ast;
mod fuse;
mod core;

/// Used to Fuse Tailwind Classes together.
pub trait TailwindFuse {
/// Strings are not guaranteed to be single class nor free of whitespace.
fn fuse_classes(&self, class: &[&str]) -> String;
}

/// Will merge tailwind classes and handle conflicts using [`tw_merge()`]
/// Will merge Tailwind classes and handle conflicts using [`tw_merge()`]
pub struct TailwindMerge;

impl TailwindFuse for TailwindMerge {
fn fuse_classes(&self, class: &[&str]) -> String {
crate::fuse::merge::tw_merge_slice(class)
crate::core::merge::tw_merge_slice(class)
}
}

/// Will simply join tailwind classes together without handling conflicts
/// Will simply join Tailwind classes together without handling conflicts
pub struct TaiwindJoin;

impl TailwindFuse for TaiwindJoin {
fn fuse_classes(&self, class: &[&str]) -> String {
class
.iter()
.flat_map(|s| s.split_whitespace())
.map(|s| s.trim())
.filter(|s| !s.is_empty())
.fold(String::new(), |mut acc, s| {
Expand Down
3 changes: 2 additions & 1 deletion fuse/tests/group-conflicts.rs
@@ -1,4 +1,5 @@
use tailwind_fuse::*;
use tailwind_fuse::merge::tw_merge;
use tailwind_fuse::tw_merge;

#[test]
fn test_tw_merge_mixed_blend() {
Expand Down
3 changes: 2 additions & 1 deletion fuse/tests/merge.rs
@@ -1,4 +1,5 @@
use tailwind_fuse::*;
use tailwind_fuse::merge::tw_merge;
use tailwind_fuse::tw_merge;

#[test]
fn test_tw_merge() {
Expand Down
4 changes: 2 additions & 2 deletions fuse/tests/override.rs
@@ -1,13 +1,13 @@
use tailwind_fuse::{tw_merge_with_options, tw_merge_with_override, MergeOptions};
use tailwind_fuse::merge::{tw_merge_with_options, tw_merge_with_override, MergeOptions};

#[test]
fn test_collisions() {
pub fn tw_merge(class: &str) -> String {
tw_merge_with_override(
&[class],
Default::default(),
collision_id_fn,
get_collisions,
&[class],
)
}

Expand Down
2 changes: 1 addition & 1 deletion variant-macro/src/model.rs
Expand Up @@ -9,7 +9,7 @@ use darling::{
pub struct TwVariantContainer {
pub ident: syn::Ident,
pub data: ast::Data<TwVariantOption, ()>,
/// The base tailwind class for the variant.
/// The base Tailwind class for the variant.
pub class: Option<String>,
}

Expand Down

0 comments on commit 784ff54

Please sign in to comment.