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

Stylers-1.0.0-alpha #35

Open
6 of 9 tasks
abishekatp opened this issue Aug 28, 2023 · 1 comment
Open
6 of 9 tasks

Stylers-1.0.0-alpha #35

abishekatp opened this issue Aug 28, 2023 · 1 comment

Comments

@abishekatp
Copy link
Owner

abishekatp commented Aug 28, 2023

The current implementation of the style macro has some limitations which may cause some future problems as we discussed in this issue by @bluenote10 . Some problems which I have solved in this new version are as follows,

  • New implementation of style and style_sheet macro. Parse the css content from build.rs file instead of from the proc_macro. both proc_macro and build.rs should generate the same class name based on the content of the css.
  • Previously we were reading all the css files and rewriting the output.css file for each compilation step. That approach has a polynomial time complexity. To solve this problem parse all the rust files one time for each compilation step from the build.rs and wrting the final output css to the output file in a single step(no intermediate files should be needed). This approach will have linear time complexity in terms of reading and writing to the files.
  • remove all the side effects from the proc_macro scope. writing to the file system should only happen from the build.rs scope.
  • Extract the stylers core functionality to a separate crate so that it can be used for both proc_macro crate and non proc_macro crates.
    Stylers_core only uses proc_macro2 so it can be used independently by any rust project or wasm project to create scoped css by passing css content either as a token stream(stylers_core::from_ts) or as a string value(.stylers_core::from_str)

Extra steps needed by the users

  • Removeing the component name from style and style_sheet macros. The new implementaion no longer needs explicit declaration of component name. This will avoid global component name collisions.
  • Adding build.rs file and calling the build function from the stylers.
  • (OPTIONAL only for Trunk users) Trunk.toml import path will change from cp ./target/stylers/main.css $TRUNK_STAGING_DIR/ tocp ./target/main.css $TRUNK_STAGING_DIR/
  • Note: style_str and style_sheet_str will function same as previous versions. no changes in them.

Steps needed before stable version release

  • Release an 1.0.0-alpha version
  • Improve the randome calss generator function to generate the class name using the css string instead of length of the css content(basic prototype is completed).
  • As of now style and style_sheet macro can be only used as let variable declaration(let some_class_name = style!{ div{ color: red } };. Need to do extra parsing steps to handle invocation of the style and style_sheet macros from the different places of leptos component. (Note: This restriction is not for style_str and style_sheet_str macros)
  • New css! macro that will allow us to write css directly inside the RSX syntax like discussed here
  • Update the readme.md file for the new version.
@sambonbonne
Copy link

sambonbonne commented Sep 8, 2023

Is it planned to fix #25 (macros break using SSR in Leptos) for the first alpha realease?

Edit: after testing, it seems the new style! macro implementation fixes this on #36 and I understand it will be merged before 1.0.0-alpha so I have my answer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants