Re-Export Manganis & Update Examples (#2625)
* feat: export manganis * revision: use manganis in examples * fix: manganis dep * fix: workspace root finder * fix: manganis dep * fix: ci
This commit is contained in:
1 parent
856fadc9d6
commit
672f4dfefc
23 files changed
+154
-134
No files matched your search
@@ -135,21 +135,6 @@ name = "calculator_mutable"
|
||||
path = "../../examples/calculator_mutable.rs"
|
||||
doc-scrape-examples = true
|
||||
|
||||
[[example]]
|
||||
name = "calculator"
|
||||
path = "../../examples/calculator.rs"
|
||||
doc-scrape-examples = true
|
||||
|
||||
[[example]]
|
||||
name = "clock"
|
||||
path = "../../examples/clock.rs"
|
||||
doc-scrape-examples = true
|
||||
|
||||
[[example]]
|
||||
name = "crm"
|
||||
path = "../../examples/crm.rs"
|
||||
doc-scrape-examples = true
|
||||
|
||||
[[example]]
|
||||
name = "custom_html"
|
||||
path = "../../examples/custom_html.rs"
|
||||
@@ -160,11 +145,6 @@ name = "custom_menu"
|
||||
path = "../../examples/custom_menu.rs"
|
||||
doc-scrape-examples = true
|
||||
|
||||
[[example]]
|
||||
name = "dynamic_asset"
|
||||
path = "../../examples/dynamic_asset.rs"
|
||||
doc-scrape-examples = true
|
||||
|
||||
[[example]]
|
||||
name = "errors"
|
||||
path = "../../examples/errors.rs"
|
||||
|
||||
@@ -2,7 +2,12 @@ use crate::{assets::*, edits::EditQueue};
|
||||
use dioxus_html::document::NATIVE_EVAL_JS;
|
||||
use dioxus_interpreter_js::unified_bindings::SLEDGEHAMMER_JS;
|
||||
use dioxus_interpreter_js::NATIVE_JS;
|
||||
use std::path::{Component, Path, PathBuf};
|
||||
use serde::Deserialize;
|
||||
use std::{
|
||||
path::{Component, Path, PathBuf},
|
||||
process::Command,
|
||||
sync::OnceLock,
|
||||
};
|
||||
use wry::{
|
||||
http::{status::StatusCode, Request, Response},
|
||||
RequestAsyncResponder, Result,
|
||||
@@ -108,8 +113,18 @@ fn assets_head() -> Option<String> {
|
||||
|
||||
fn resolve_resource(path: &Path) -> PathBuf {
|
||||
let mut base_path = get_asset_root_or_default();
|
||||
|
||||
if running_in_dev_mode() {
|
||||
base_path.push(path);
|
||||
|
||||
// Special handler for Manganis filesystem fallback.
|
||||
// We need this since Manganis provides assets from workspace root.
|
||||
if !base_path.exists() {
|
||||
let workspace_root = get_workspace_root_from_cargo();
|
||||
let asset_path = workspace_root.join(path);
|
||||
println!("ASSET PATH: {:?}", asset_path);
|
||||
return asset_path;
|
||||
}
|
||||
} else {
|
||||
let mut resource_path = PathBuf::new();
|
||||
for component in path.components() {
|
||||
@@ -305,3 +320,31 @@ fn get_mime_by_ext(trimmed: &Path) -> &'static str {
|
||||
None => "application/octet-stream",
|
||||
}
|
||||
}
|
||||
|
||||
/// A global that stores the workspace root. Used in [`get_workspace_root_from_cargo`].
|
||||
static WORKSPACE_ROOT: OnceLock<PathBuf> = OnceLock::new();
|
||||
|
||||
/// Describes the metadata we need from `cargo metadata`.
|
||||
#[derive(Deserialize)]
|
||||
struct CargoMetadata {
|
||||
workspace_root: PathBuf,
|
||||
}
|
||||
|
||||
/// Get the workspace root using `cargo metadata`. Should not be used in release mode.
|
||||
pub(crate) fn get_workspace_root_from_cargo() -> PathBuf {
|
||||
WORKSPACE_ROOT
|
||||
.get_or_init(|| {
|
||||
let out = Command::new("cargo")
|
||||
.args(["metadata", "--format-version", "1", "--no-deps"])
|
||||
.output()
|
||||
.expect("`cargo metadata` failed to run");
|
||||
|
||||
let out =
|
||||
String::from_utf8(out.stdout).expect("failed to parse output of `cargo metadata`");
|
||||
let metadata = serde_json::from_str::<CargoMetadata>(&out)
|
||||
.expect("failed to deserialize data from `cargo metadata`");
|
||||
|
||||
metadata.workspace_root
|
||||
})
|
||||
.to_owned()
|
||||
}
|
||||
@@ -24,7 +24,8 @@ dioxus-desktop = { workspace = true, default-features = true, optional = true }
|
||||
dioxus-fullstack = { workspace = true, default-features = true, optional = true }
|
||||
dioxus-static-site-generation = { workspace = true, optional = true }
|
||||
dioxus-liveview = { workspace = true, optional = true }
|
||||
dioxus-ssr ={ workspace = true, optional = true }
|
||||
dioxus-ssr = { workspace = true, optional = true }
|
||||
manganis = { workspace = true, optional = true }
|
||||
|
||||
serde = { version = "1.0.136", optional = true }
|
||||
axum = { workspace = true, optional = true }
|
||||
@@ -33,7 +34,7 @@ axum = { workspace = true, optional = true }
|
||||
dioxus-hot-reload = { workspace = true, optional = true }
|
||||
|
||||
[features]
|
||||
default = ["macro", "html", "hot-reload", "signals", "hooks", "launch", "mounted", "file_engine", "document"]
|
||||
default = ["macro", "html", "hot-reload", "signals", "hooks", "launch", "mounted", "file_engine", "document", "asset"]
|
||||
minimal = ["macro", "html", "signals", "hooks", "launch"]
|
||||
signals = ["dep:dioxus-signals"]
|
||||
macro = ["dep:dioxus-core-macro"]
|
||||
@@ -42,6 +43,7 @@ hooks = ["dep:dioxus-hooks"]
|
||||
hot-reload = ["dep:dioxus-hot-reload", "dioxus-web?/hot_reload", "dioxus-fullstack?/hot-reload"]
|
||||
mounted = ["dioxus-web?/mounted", "dioxus-html?/mounted"]
|
||||
file_engine = ["dioxus-web?/file_engine"]
|
||||
asset = ["dep:manganis"]
|
||||
document = ["dioxus-web?/document", "dioxus-html?/document"]
|
||||
|
||||
launch = ["dep:dioxus-config-macro"]
|
||||
|
||||
@@ -122,6 +122,10 @@ pub mod prelude {
|
||||
#[cfg(feature = "axum")]
|
||||
#[cfg_attr(docsrs, doc(cfg(feature = "axum")))]
|
||||
pub use axum;
|
||||
|
||||
#[cfg(feature = "asset")]
|
||||
#[cfg_attr(docsrs, doc(cfg(feature = "asset")))]
|
||||
pub use manganis::{self, classes, mg as asset, ImageAsset, ImageType};
|
||||
}
|
||||
|
||||
#[cfg(feature = "web")]
|
||||
|
||||
@@ -61,36 +61,17 @@ serde = { version = "1", features = ["derive"] }
|
||||
[package.metadata.docs.rs]
|
||||
cargo-args = ["-Zunstable-options", "-Zrustdoc-scrape-examples"]
|
||||
# Most of the examples live in the workspace. We include some here so that docs.rs can scrape our examples for better inline docs
|
||||
[[example]]
|
||||
name = "crm"
|
||||
path = "../../examples/crm.rs"
|
||||
doc-scrape-examples = true
|
||||
|
||||
[[example]]
|
||||
name = "flat_router"
|
||||
path = "../../examples/flat_router.rs"
|
||||
doc-scrape-examples = true
|
||||
|
||||
[[example]]
|
||||
name = "hash_fragment_state"
|
||||
path = "../../examples/hash_fragment_state.rs"
|
||||
doc-scrape-examples = true
|
||||
|
||||
[[example]]
|
||||
name = "link"
|
||||
path = "../../examples/link.rs"
|
||||
doc-scrape-examples = true
|
||||
|
||||
[[example]]
|
||||
name = "query_segment_search"
|
||||
path = "../../examples/query_segment_search.rs"
|
||||
doc-scrape-examples = true
|
||||
|
||||
[[example]]
|
||||
name = "router"
|
||||
path = "../../examples/router.rs"
|
||||
doc-scrape-examples = true
|
||||
|
||||
[[example]]
|
||||
name = "simple_router"
|
||||
path = "../../examples/simple_router.rs"
|
||||
|
||||
Reference in new issue
Block a user