Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

13 valid tailwind syntax but twust returns compile error #15

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 18 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,27 @@ members = ["twust-macro", "tailwind"]

[workspace.package]
name = "twust"
version = "1.0.4"
version = "1.0.5"
edition = "2021"
authors = ["Oyelowo Oyedayo"]
description = "One codebase to rule them all"
documentation = "https://codebreather.com/oyelowo"
email = ["[email protected]"]
readme = "README.md"
documentation = "https://docs.rs/nom"
# documentation = "https://codebreather.com/oyelowo"
description = "Zero-config Static type-checker for Tailwind CSS"
license = "MIT/Apache-2.0"
categories = ["UI", "css", "tailwindcss", "web-programming"]
keywords = [
"tailwind",
"css",
"tailwindcss",
"frontend",
"ui",
"rust",
"web",
"twust",
]


# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

Expand Down
10 changes: 5 additions & 5 deletions examples/leptos-demo/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ edition = "2021"
[workspace]

[dependencies]
leptos = { version = "0.5.0-beta2", features = ["csr", "nightly"] }
leptos_meta = { version = "0.5.0-beta2", features = ["csr", "nightly"] }
leptos_router = { version = "0.5.0-beta2", features = ["csr", "nightly"] }
log = "0.4.2"
gloo-net = { version = "0.4.0", features = ["http"] }
leptos = { version = "0.7.4", features = ["csr"] }
leptos_meta = { version = "0.7.4" }
leptos_router = { version = "0.7.4" }
log = "0.4.25"
gloo-net = { version = "0.6.0", features = ["http"] }
twust = { version = "*", features = ["daisyui"] }
# twust = { git = "https://github.com/oyelowo/twust", features = ["daisyui"] }

Expand Down
2 changes: 2 additions & 0 deletions examples/leptos-demo/Makefile.toml
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
extend = [{ path = "../cargo-make/main.toml" }]


23 changes: 3 additions & 20 deletions examples/leptos-demo/src/app.rs
Original file line number Diff line number Diff line change
@@ -1,28 +1,11 @@
use leptos::*;
use leptos_meta::*;
use leptos_router::*;
use leptos::prelude::*;
use twust::tw;

#[component]
pub fn App() -> impl IntoView {
provide_meta_context();

view! {
<Stylesheet id="leptos" href="/pkg/tailwind.css"/>
<Link rel="shortcut icon" type_="image/ico" href="/favicon.ico"/>
<Router>
<Routes>
<Route path="" view= move || view! { <Home/> }/>
</Routes>
</Router>
}
}

#[component]
fn Home() -> impl IntoView {
pub fn Home() -> impl IntoView {
// Try to break mistype any of the class name and see what happens.
// Daisyui classes are also ssupported via a feature flag
let x = tw!("my-5 mx-auto max-w-3xl text-center");
let _x = tw!("my-5 mx-auto max-w-3xl text-center");
view! {
<div class=tw!("my-5 mx-auto max-w-3xl text-center")>
<h2 class=tw!("p-6 text-4xl")>"Twust"</h2>
Expand Down
16 changes: 9 additions & 7 deletions examples/leptos-demo/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@ mod app;
use app::*;
use leptos::*;

use leptos_router::components::Router;

pub fn main() {
_ = console_log::init_with_level(log::Level::Debug);
console_error_panic_hook::set_once();

// logging::log!("csr mode - mounting to body");

mount_to_body(|| {
view! { <App /> }
});
leptos::mount::mount_to_body(|| {
view! {
<Router>
<Home />
</Router>
}
})
}
5 changes: 5 additions & 0 deletions tailwind/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,11 @@ fn _invalid_group_usage_3() {}

fn _happy_paths() {
fn main() {
let _classnames = tw!("group-data-[selected=Right]:w-[30px]");
let _classnames = tw!("group-aria-[main-page=false]/main:hidden");
let _classnames = tw!("group-data-[main-page=false]/main:hidden");
let _classnames = tw!("*:overflow-scroll");

let _classnames = tw!("bg-taxvhiti bg-tahiti-500 bg-tahiti bg-midnight bg-red-50");
let _classnames = tw!("bg-taxvhiti bg-tahiti-500 bg-tahiti bg-midnight bg-purple bg-red-50 bg-tahiti-800 border-s-tahiti-800");
let _classnames = tw!("md:text-red-50 text-slate-50 text-purple text-tahiti-500");
Expand Down
18 changes: 18 additions & 0 deletions twust-macro/src/config/classes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -516,6 +516,24 @@ define_tailwind_field!({
variants: []
});

// 3. Placeholder
// Placeholder Color
// Placeholder Opacity
define_tailwind_color_field!({
name: PlaceholderColor,
prefix: "placeholder-color",
field_name: placeholder_color,
variants: []
});

define_tailwind_field!({
name: PlaceholderOpacity,
prefix: "placeholder-opacity",
inherited: placeholder_opacity,
field_name: placeholder_opacity,
variants: []
});

// 3. Spacing
// Padding
// Margin
Expand Down
12 changes: 6 additions & 6 deletions twust-macro/src/config/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ macro_rules! define_tailwind_color_field {
fn get_default(&self, config: &TailwindConfig) -> Vec<&str> {
if let Some(ref core_plugins) = config.core_plugins {
if let Some(enabled) = core_plugins.$default_field {
if enabled == false {
if !enabled {
return vec![];
}
}
Expand All @@ -65,7 +65,7 @@ macro_rules! define_tailwind_color_field {
fn get_override(&self, config: &TailwindConfig) -> Vec<String> {
if let Some(ref core_plugins) = config.core_plugins {
if let Some(enabled) = core_plugins.$default_field {
if enabled == false {
if !enabled {
return vec![];
}
}
Expand All @@ -80,7 +80,7 @@ macro_rules! define_tailwind_color_field {
fn get_extend(&self, config: &TailwindConfig) -> Vec<String> {
if let Some(ref core_plugins) = config.core_plugins {
if let Some(enabled) = core_plugins.$default_field {
if enabled == false {
if !enabled {
return vec![];
}
}
Expand Down Expand Up @@ -117,7 +117,7 @@ macro_rules! define_tailwind_field {
fn get_default(&self, config: &TailwindConfig) -> Vec<&str> {
if let Some(ref core_plugins) = config.core_plugins {
if let Some(enabled) = core_plugins.$field_name {
if enabled == false {
if !enabled {
return vec![];
}
}
Expand All @@ -129,7 +129,7 @@ macro_rules! define_tailwind_field {
fn get_override(&self, config: &TailwindConfig) -> Vec<String> {
if let Some(ref core_plugins) = config.core_plugins {
if let Some(enabled) = core_plugins.$field_name {
if enabled == false {
if !enabled {
return vec![];
}
}
Expand All @@ -144,7 +144,7 @@ macro_rules! define_tailwind_field {
fn get_extend(&self, config: &TailwindConfig) -> Vec<String> {
if let Some(ref core_plugins) = config.core_plugins {
if let Some(enabled) = core_plugins.$field_name {
if enabled == false {
if !enabled {
return vec![];
}
}
Expand Down
6 changes: 4 additions & 2 deletions twust-macro/src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ pub(crate) fn read_tailwind_config() -> Result<TailwindConfig, std::io::Error> {
return Err(std::io::Error::new(
std::io::ErrorKind::NotFound,
format!(
"tailwind.config.json was not found in the top-level directory - \n{config_path:?}. Ensure it exists."
"tailwind.config.json was not found in the top-level directory - \n{config_path:?}. Make sure it exists."
),
));
}
Expand All @@ -86,7 +86,7 @@ pub fn get_classes(config: &TailwindConfig) -> Vec<String> {
// by the user.

let mut classes = Vec::new();
let utilities: [Box<dyn TailwindField>; 175] = [
let utilities: [Box<dyn TailwindField>; 177] = [
Box::new(AspectRatio),
Box::new(Container),
Box::new(Columns),
Expand Down Expand Up @@ -143,6 +143,8 @@ pub fn get_classes(config: &TailwindConfig) -> Vec<String> {
Box::new(PlaceContent),
Box::new(PlaceItems),
Box::new(PlaceSelf),
Box::new(PlaceholderColor),
Box::new(PlaceholderOpacity),
Box::new(Padding),
Box::new(Margin),
Box::new(SpaceBetween),
Expand Down
25 changes: 20 additions & 5 deletions twust-macro/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,14 @@ fn get_classes_straight() -> HashSet<String> {
}

fn is_valid_classname(class_name: &str) -> bool {
get_classes_straight().contains(&class_name.to_string())
get_classes_straight().contains(class_name)
}

fn is_valid_modifier(modifier: &str) -> bool {
let modifiers: HashSet<String> = HashSet::from_iter(get_modifiers(
&read_tailwind_config().expect("Problem getting modifiers"),
));
modifiers.contains(&modifier.to_string())
modifiers.contains(modifier)
}

fn parse_predefined_tw_classname(input: &str) -> IResult<&str, ()> {
Expand Down Expand Up @@ -616,13 +616,16 @@ fn supports_arbitrary(input: &str) -> IResult<&str, ()> {

// aria-[sort=ascending]:bg-[url('/img/down-arrow.svg')]
// aria-[sort=descending]:bg-[url('/img/up-arrow.svg')]
fn aria_arbitrary(input: &str) -> IResult<&str, ()> {
// group-data-[selected=Right]:w-[30px]
// group-aria-[main-page=false]/main:hidden / group-data-[main-page=false]/main:hidden
fn aria_or_data_arbitrary(input: &str) -> IResult<&str, ()> {
let (input, _) = opt(tag("group-"))(input)?;
let (input, _) = tag("aria-[")(input)?;
let (input, _) = alt((tag("aria-["), tag("data-[")))(input)?;
let (input, _) = take_while1(is_ident_char)(input)?;
let (input, _) = tag("=")(input)?;
let (input, _) = take_while1(is_ident_char)(input)?;
let (input, _) = tag("]")(input)?;
let (input, _) = opt(tuple((tag("/"), take_while1(is_ident_char))))(input)?;
Ok((input, ()))
}

Expand All @@ -645,6 +648,12 @@ fn min_max_arbitrary_modifier(input: &str) -> IResult<&str, ()> {
Ok((input, ()))
}

// *:overflow-scroll
fn wildcard_modifier(input: &str) -> IResult<&str, ()> {
let (input, _) = tag("*")(input)?;
Ok((input, ()))
}

fn modifier(input: &str) -> IResult<&str, ()> {
alt((
group_modifier_selector,
Expand All @@ -656,9 +665,10 @@ fn modifier(input: &str) -> IResult<&str, ()> {
arbitrary_at_media_rule_modifier,
predefined_modifier,
supports_arbitrary,
aria_arbitrary,
aria_or_data_arbitrary,
data_arbitrary,
min_max_arbitrary_modifier,
wildcard_modifier,
))(input)
}

Expand Down Expand Up @@ -723,6 +733,11 @@ fn parse_top(input: &str) -> IResult<&str, Vec<&str>> {
all_consuming(parse_class_names)(input)
}

#[test]
fn test_group_attr_arbitrary2() {
assert_eq!(parse_top("group-data-[selected=Right]"), Ok(("", vec![])));
}

#[proc_macro]
pub fn tw(raw_input: TokenStream) -> TokenStream {
let r_input = raw_input.clone();
Expand Down
1 change: 1 addition & 0 deletions twust-macro/src/tailwind/default_classnames.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
// placescreen_readers-shown
// placeholder-slate-400

#[allow(dead_code)]
#[derive(Debug, Clone, Copy)]
pub struct TailWindCssDefaultClassNames {
pub aspect_ratio: [&'static str; 3],
Expand Down
5 changes: 3 additions & 2 deletions twust-macro/src/tailwind/modifiers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ use crate::config::{add_classes_for_field, modifiers};

use super::tailwind_config::TailwindConfig;

const MODIFIERS: [&str; 49] = [
const MODIFIERS: [&str; 50] = [
"*",
"hover",
"focus",
"focus-within",
Expand Down Expand Up @@ -160,7 +161,7 @@ pub fn get_modifiers(config: &TailwindConfig) -> Vec<String> {
// "max-[…]",
]
.into_iter()
.map(|x| x.to_string())
.map(Into::into)
.collect::<Vec<String>>();

if let Some(ref screens) = config.theme.overrides.screens {
Expand Down