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

Small QOL improvements #11

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open
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
14 changes: 14 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"rust-analyzer.rustfmt.overrideCommand": [
"leptosfmt",
"--stdin",
"--rustfmt"
],
"editor.formatOnSave": true,
"[rust]": {
"editor.defaultFormatter": "rust-lang.rust-analyzer",
},
"files.associations": {
"*.rs": "rust"
},
}
File renamed without changes.
32 changes: 32 additions & 0 deletions Cargo.stable.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
[package]
name = "{{project-name}}"
version = "0.1.0"
edition = "2021"
authors = ["{{authors}}"]

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

[dependencies]
leptos = { version = "0.6", features = ["csr"] }
leptos_meta = { version = "0.6", features = ["csr"] }
leptos_router = { version = "0.6", features = ["csr"] }
console_log = "1"
log = "0.4"
console_error_panic_hook = "0.1"

# utils
# strum = { version = "0.25", features = ["derive", "strum_macros"] }
# strum_macros = "0.25"


[dev-dependencies]
wasm-bindgen = "0.2"
wasm-bindgen-test = "0.3"
web-sys = { version = "0.3", features = ["Document", "Window"] }


[profile.release]
opt-level = 'z'
lto = true
codegen-units = 1
panic = "abort"
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ This is a template for use with the [Leptos][Leptos] web framework using the [Tr

## Creating your repo from the template

This template requires you to have `cargo-generate` installed. You can install it with
This template requires you to have `cargo-generate` and `trunk` installed. [`leptosfmt`](https://github.com/bram209/leptosfmt) is optional but highly recommended. You can install them with

```sh
cargo install cargo-generate
cargo install cargo-generate trunk leptosfmt
```


Expand Down
60 changes: 60 additions & 0 deletions Trunk.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
[build]
# The index HTML file to drive the bundling process.
target = "index.html"
# Build in release mode.
release = false
# Use a custom cargo profile. Overrides the default chosen by cargo. Ignored if the 'index.html' has one configured.
# cargo_profile = ""
# The output dir for all final assets.
dist = "dist"
# The public URL from which assets are to be served.
public_url = "/"
# Whether to include hash values in the output file names.
filehash = true
# Whether to inject scripts (and module preloads) into the finalized output.
inject_scripts = true
# Run without network access
# offline = false
# Require Cargo.lock and cache are up to date
# frozen = false
# Require Cargo.lock is up to date
# locked = false
# Control minification
# minify = "never" # can be one of: never, on_release, always
# Allow disabling sub-resource integrity (SRI)
# no_sri = false
# An optional cargo profile to use
# cargo_profile = "release-trunk"

[watch]
# Paths to watch. The `build.target`'s parent folder is watched by default.
watch = []
# Paths to ignore.
ignore = []

[serve]
# The address to serve on.
addresses = ["127.0.0.1"]
# The port to serve on.
port = 3000
# Aliases to serve, typically found in an /etc/hosts file.
# aliases = ["http://localhost.mywebsite.com"]
# Disable the reverse DNS lookup during startup
# disable_address_lookup = false
# Open a browser tab once the initial build is complete.
open = false
# Whether to disable fallback to index.html for missing files.
# no_spa = false
# Disable auto-reload of the web app.
# no_autoreload = false
# Disable error reporting
# no_error_reporting = false
# Additional headers set for responses.
# headers = { "test-header" = "header value", "test-header2" = "header value 2" }
# Protocol used for autoreload WebSockets connection.
# ws_protocol = "ws"
# The certificate/private key pair to use for TLS, which is enabled if both are set.
# tls_key_path = "self_signed_certs/key.pem"
# tls_cert_path = "self_signed_certs/cert.pem"
# Additional headers to send. NOTE: header names must be valid HTTP headers.
# headers = { "X-Foo" = "bar" }
15 changes: 15 additions & 0 deletions cargo-generate.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[template]
ignore = ["Cargo.lock", "switch_nightly_stable.rhai"]

[placeholders]
default_channel = { prompt = "Use stable or nightly channel?", choices = [
"stable",
"nightly",
], default = "stable", type = "string" }
vscode_settings = { prompt = "Generate default VS Code settings?", default = false, type = "bool" }

[conditional.'vscode_settings == false']
ignore = [".vscode"]

[hooks]
pre = ["switch_nightly_stable.rhai"]
29 changes: 16 additions & 13 deletions index.html
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
<!DOCTYPE html>
<html>
<head>
<!-- Add a plain CSS file: see https://trunkrs.dev/assets/#css -->
<!-- If using Tailwind with Leptos CSR, see https://trunkrs.dev/assets/#tailwind instead-->
<link data-trunk rel="css" href="public/styles.css" />

<!-- Include favicon in dist output: see https://trunkrs.dev/assets/#icon -->
<link data-trunk rel="icon" href="public/favicon.ico" />

<!-- include support for `wasm-bindgen --weak-refs` - see: https://rustwasm.github.io/docs/wasm-bindgen/reference/weak-references.html -->
<link data-trunk rel="rust" data-wasm-opt="z" data-weak-refs />
</head>
<body></body>
</html>

<head>
<!-- Add a plain CSS file: see https://trunkrs.dev/assets/#css -->
<!-- If using Tailwind with Leptos CSR, see https://trunkrs.dev/assets/#tailwind instead-->
<link data-trunk rel="scss" href="public/styles.scss" />

<!-- Include favicon in dist output: see https://trunkrs.dev/assets/#icon -->
<link data-trunk rel="icon" href="public/favicon.ico" />

<!-- include support for `wasm-bindgen --weak-refs` - see: https://rustwasm.github.io/docs/wasm-bindgen/reference/weak-references.html -->
<link data-trunk rel="rust" data-wasm-opt="z" data-weak-refs />
</head>

<body></body>

</html>
File renamed without changes.
2 changes: 1 addition & 1 deletion rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
[toolchain]
channel = "nightly"
channel = "{{default_channel}}"
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@ use leptos::*;
pub fn Button(#[prop(default = 1)] increment: i32) -> impl IntoView {
let (count, set_count) = create_signal(0);
view! {
<button
on:click= move |_| {
set_count(count() + increment)
}
>
<button on:click=move |_| {
set_count(count() + increment)
}>

"Click me: " {count}
</button>
}
Expand Down
15 changes: 15 additions & 0 deletions src/components/counter_btn.stable.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
use leptos::*;

/// A parameterized incrementing button
#[component]
pub fn Button(#[prop(default = 1)] increment: i32) -> impl IntoView {
let (count, set_count) = create_signal(0);
view! {
<button on:click=move |_| {
set_count.set(count.get() + increment)
}>

"Click me: " {count}
</button>
}
}
16 changes: 16 additions & 0 deletions switch_nightly_stable.rhai
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
let default_channel = variable::get("default_channel").to_upper();

switch default_channel {
"STABLE" => {
file::delete("Cargo.nightly.toml");
file::rename("Cargo.stable.toml", "Cargo.toml");
file::delete("src/components/counter_btn.nightly.rs");
file::rename("src/components/counter_btn.stable.rs", "src/components/counter_btn.rs");
}
"NIGHTLY" => {
file::delete("Cargo.stable.toml");
file::rename("Cargo.nightly.toml", "Cargo.toml");
file::delete("src/components/counter_btn.stable.rs");
file::rename("src/components/counter_btn.nightly.rs", "src/components/counter_btn.rs");
}
}