Skip to content

Commit

Permalink
API refactor, bug fixes and enhancements (#62)
Browse files Browse the repository at this point in the history
  • Loading branch information
mondeja authored May 19, 2024
1 parent 24e68b9 commit bf4bc0c
Show file tree
Hide file tree
Showing 30 changed files with 445 additions and 266 deletions.
28 changes: 12 additions & 16 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,9 @@ jobs:
~/.cargo/git
target
key: ${{ runner.os }}-cargo-${{ matrix.browser }}-${{ hashFiles('**/Cargo.toml') }}-${{ hashFiles('**/Cargo.lock') }}
- name: Run tests
- name: Run end to end tests
run: |
cd tests
cd end2end
wasm-pack test --headless --${{ matrix.browser }}
build-example:
Expand All @@ -85,15 +85,11 @@ jobs:
strategy:
fail-fast: false
matrix:
include:
- example: csr-minimal
feature: csr
- example: csr-complete
feature: csr
- example: ssr-hydrate-actix
feature: ssr
- example: ssr-hydrate-axum
feature: ssr
example:
- csr-minimal
- csr-complete
- ssr-hydrate-actix
- ssr-hydrate-axum
steps:
- uses: actions/checkout@v4
- name: Setup Rust
Expand All @@ -106,12 +102,12 @@ jobs:
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Install trunk
if: ${{ contains(matrix.feature, 'csr') }}
if: ${{ startsWith(matrix.example, 'csr') }}
run: cargo binstall -y trunk
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Install cargo-leptos
if: ${{ matrix.feature == 'ssr' }}
if: ${{ startsWith(matrix.example, 'ssr') }}
run: cargo binstall -y cargo-leptos
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand All @@ -122,14 +118,14 @@ jobs:
~/.cargo/registry
~/.cargo/git
target
key: ${{ runner.os }}-cargo-${{ matrix.example }}-${{ matrix.feature }}-${{ hashFiles('**/Cargo.toml') }}-${{ hashFiles('**/Cargo.lock') }}
key: ${{ runner.os }}-cargo-${{ matrix.example }}-${{ hashFiles('**/Cargo.toml') }}-${{ hashFiles('**/Cargo.lock') }}
- name: Build with trunk
if: ${{ matrix.feature == 'csr' }}
if: ${{ startsWith(matrix.example, 'csr') }}
run: |
cd examples/${{ matrix.example }}
trunk build --release
- name: Build with cargo-leptos
if: ${{ matrix.feature == 'ssr' }}
if: ${{ startsWith(matrix.example, 'ssr') }}
run: |
cd examples/${{ matrix.example }}
cargo leptos build --release
Expand Down
22 changes: 22 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,26 @@
# CHANGELOG

## 2024-05-20 - [0.0.24]

### Enhancements

- Add `I18n.is_active_language` method.
- Add `I18n.language_key` method to return a hash for the current
language with their active status for usage in `For` components.
- Add `set_to_localstorage` parameter to `leptos_fluent!` macro.
- Add `use_i18n` and `expect_i18n` function.

### Breaking changes

- Replace `I18n.set_language_with_localstorage` method with
`I18n.set_language`. Use `set_to_localstorage` macro parameter
and `I18n.set_language` instead.
- Remove `csr` feature.

### Bug fixes

- Fix errors getting initial language from URL parameter and local storage.

## 2024-05-18 - [0.0.23]

- Add `axum` feature to integrate with Axum web framework.
Expand Down Expand Up @@ -44,6 +65,7 @@

- Added all ISO-639-1 and ISO-639-2 languages.

[0.0.24]: https://github.com/mondeja/leptos-fluent/compare/v0.0.23...v0.0.24
[0.0.23]: https://github.com/mondeja/leptos-fluent/compare/v0.0.22...v0.0.23
[0.0.22]: https://github.com/mondeja/leptos-fluent/compare/v0.0.21...v0.0.22
[0.0.21]: https://github.com/mondeja/leptos-fluent/compare/v0.0.20...v0.0.21
Expand Down
9 changes: 8 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,17 @@ wasm-pack test --{browser} --headless
Where `{browser}` is one of `firefox`, `chrome`, or `safari`. For example:

```sh
cd tests
cd end2end
wasm-pack test --firefox --headless
```

If you want to run a test suite:

```sh
cd end2end
wasm-pack test --firefox --headless --test csr_minimal
```

## Documentation

```sh
Expand Down
21 changes: 13 additions & 8 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
members = [
"leptos-fluent",
"leptos-fluent-macros",
"tests",
"end2end",
"end2end/tests-helpers",
"examples/csr-complete",
"examples/csr-minimal",
"examples/ssr-hydrate-actix",
Expand Down
13 changes: 8 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,13 @@ Add the following to your `Cargo.toml` file:

```toml
[dependencies]
leptos-fluent = "0.0.21"
leptos-fluent = "0.0.24"
fluent-templates = "0.9"

[features]
csr = ["leptos-fluent/csr"]
hydrate = ["leptos-fluent/hydrate"]
hydrate = [
"leptos-fluent/hydrate"
]
ssr = [
"leptos-fluent/ssr",
"leptos-fluent/actix", # actix and axum are supported
Expand Down Expand Up @@ -101,6 +102,9 @@ pub fn App() -> impl IntoView {
// Get the initial language from `navigator.languages` if not
// found in the local storage. By default, it is `false`.
initial_language_from_navigator: true,
// Set the language to local storage when the user changes it.
// By default, it is `false`.
set_to_localstorage: true,
// Name of the field in local storage to get and set the
// current language of the user. By default, it is `"lang"`.
localstorage_key: "language",
Expand Down Expand Up @@ -134,8 +138,7 @@ fn ChildComponent() -> impl IntoView {

### Features

- **Client side rendering (CSR)**: Use the `leptos-fluent/csr` feature.
- **Server side rendering (SSR)**: Use the `leptos-fluent/ssr` feature.
- **Server Side Rendering**: Use the `leptos-fluent/ssr` feature.
- **Hydration**: Use the `leptos-fluent/hydrate` feature.
- **Actix Web integration**: Use the `leptos-fluent/actix` feature.
- **Axum integration**: Use the `leptos-fluent/axum` feature.
Expand Down
7 changes: 1 addition & 6 deletions tests/Cargo.toml → end2end/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,9 @@ name = "leptos-fluent-tests"
edition = "2021"
version = "0.1.0"

[lib]
crate-type = ["cdylib"]

[dependencies]
tests-helpers = { path = "./tests-helpers" }
leptos-fluent-csr-minimal-example = { path = "../examples/csr-minimal" }
leptos-fluent-csr-complete-example = { path = "../examples/csr-complete" }
wasm-bindgen-test = "0.3"
leptos = "0.6"
js-sys = "0.3"
web-sys = "0.3"
wasm-bindgen-futures = "0.4"
10 changes: 10 additions & 0 deletions end2end/tests-helpers/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[package]
name = "tests-helpers"
edition = "2021"
version = "0.1.0"

[dependencies]
leptos = "0.6"
web-sys = { version = "0.3", features = ["Navigator", "Storage"] }
js-sys = "0.3"
wasm-bindgen-futures = "0.4"
93 changes: 93 additions & 0 deletions end2end/tests-helpers/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
#[macro_export]
macro_rules! mount {
($app:ident) => {{
::leptos::mount_to_body(
move || ::leptos::view! { <div id="wrapper"><$app/></div> },
);
}};
}

#[macro_export]
macro_rules! unmount {
() => {{
use leptos::wasm_bindgen::JsCast;
::leptos::document()
.body()
.unwrap()
.remove_child(
::leptos::document()
.get_element_by_id("wrapper")
.unwrap()
.unchecked_ref(),
)
.unwrap();
}};
}

pub async fn sleep(delay: i32) {
let mut cb = |resolve: js_sys::Function, _reject: js_sys::Function| {
::web_sys::window()
.unwrap()
.set_timeout_with_callback_and_timeout_and_arguments_0(
&resolve, delay,
)
.unwrap();
};

let p = ::js_sys::Promise::new(&mut cb);
::wasm_bindgen_futures::JsFuture::from(p).await.unwrap();
}

pub fn element_text(selector: &str) -> String {
::leptos::document()
.query_selector(selector)
.unwrap()
.unwrap()
.text_content()
.unwrap()
}

pub fn input_by_id(id: &str) -> web_sys::HtmlInputElement {
use leptos::wasm_bindgen::JsCast;
::leptos::document()
.get_element_by_id(id)
.unwrap()
.unchecked_into::<web_sys::HtmlInputElement>()
}

pub fn html() -> web_sys::HtmlHtmlElement {
use leptos::wasm_bindgen::JsCast;
::leptos::document()
.document_element()
.unwrap()
.unchecked_into::<web_sys::HtmlHtmlElement>()
}

pub mod localstorage {
pub fn delete(key: &str) {
::leptos::window()
.local_storage()
.unwrap()
.unwrap()
.remove_item(key)
.unwrap();
}

pub fn set(key: &str, value: &str) {
::leptos::window()
.local_storage()
.unwrap()
.unwrap()
.set_item(key, value)
.unwrap();
}

pub fn get(key: &str) -> Option<String> {
::leptos::window()
.local_storage()
.unwrap()
.unwrap()
.get_item(key)
.unwrap()
}
}
Loading

0 comments on commit bf4bc0c

Please sign in to comment.