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

Simplify #4

Merged
merged 12 commits into from
May 7, 2024
Merged

Simplify #4

merged 12 commits into from
May 7, 2024

Conversation

swlkr
Copy link
Owner

@swlkr swlkr commented May 7, 2024

The multiple crates thing was weird, this just has two crates, one for ryde and one for the macros.

This also breaks everything, sorry ahead of time:

Before:

// src/main.rs
use ryde::*;

routes!(
    (get, "/", index),
    (get, "/*files", files_handler)
);

serve_static_files!("static", files_handler);

#[main]
async fn main() {
    serve("::1:9001", routes()).await
}

async fn index() -> Response {
    document()
        .head((title("ryde with rust"), render_static_files!()))
        .body(
            h1("ryde with rust")
                .css(css!(
                    "font-size: 1.5rem",
                    "line-height: 2rem"
                ))
        )
        .render()
}

After:

use ryde::*;

routes!(
    ("/", get(get_slash)),
    ("/*files", get(get_files))
);

embed_static_files!("static");

#[main]
async fn main() {
    serve("::1:9001", routes()).await
}

async fn get_slash() -> Html {
    html! {
        <!DOCTYPE html>
        <html lang="en">
            <head>
                <title>ryde with rust</title>
                {render_static_files!("static")}
            </head>
            <body>
                <h1 class="text-2xl">ryde with rust</h1>
            </body>
        </html>
    }
}

Two questions:

  1. why did I change everything?

It's way simpler for me to maintain and for you to use and make fast web apps fast, hopefully. In my mind I thought oh this built in css and html stuff will make me move faster, but honestly, it didn't, I was working on a cli thing to convert html and tailwind to rust code and I thought, this is dumb, I should just do what leptos does because most of the time we're copy pasting bits of html and tailwind anyway. I honestly learned a new trick with the macros and the tuple syntax and I way, way overused it. Also, I found out about leptos-fmt and that helix automatically does the right thing when you have html inside of an html! proc macro which were my two hangs up about html in rust.

The css side of it was just too try hard. tailwind is fine, there's so many pre-existing components out there, I might as well stop fighting it and just embrace it.

  1. will everything always be changing?

Yes, at least until v1 (if I ever get there). What I want you to take away from this library is how hypermedia apps in rust could be developed, check the source, get ideas, if you like what I'm doing here, go ahead and use it, but it's just for me. I plan on not making any major changes going forward, I like where the api is now. The only thing I can see happening is maybe around the static files or sql, it would be to great to have autocomplete and treesitter injections for sql.

@swlkr swlkr merged commit b28e744 into main May 7, 2024
@swlkr swlkr deleted the simplify branch May 7, 2024 21:55
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

Successfully merging this pull request may close these issues.

1 participant