mirror of
https://github.com/storytold/gridcraft.git
synced 2026-11-11 04:49:33 +00:00
The transports, the message types and the origin checks come from the shared crate (storytold/craft-libs#420); GridCraft keeps the download hook, the open size limit, the workbook-saved rule and the author.
29 lines
1.1 KiB
Rust
29 lines
1.1 KiB
Rust
//! Pure host-mode rules, shared by the bridge ([`crate::host`]) and testable without a browser
|
|
//! (like [`crate::prefs`]): the name the bridge fills in when a host's open request has none.
|
|
//! Which pages host the app is `craft-web-host`'s.
|
|
|
|
/// The file name used when an open request carries no usable one.
|
|
pub const DEFAULT_OPEN_NAME: &str = "Book.xlsx";
|
|
|
|
/// The name `craft-web-host` gives an open request that carries no usable one (it cleans a host's
|
|
/// name and falls back to this).
|
|
const NAMELESS: &str = "document";
|
|
|
|
/// A usable file name for an open request: the cleaned name the crate hands over, or
|
|
/// [`DEFAULT_OPEN_NAME`] when the host sent none.
|
|
pub fn open_name(name: &str) -> String {
|
|
if name == NAMELESS { DEFAULT_OPEN_NAME.to_string() } else { name.to_string() }
|
|
}
|
|
|
|
#[cfg(test)]
|
|
mod tests {
|
|
use super::*;
|
|
|
|
#[test]
|
|
fn open_names_fall_back_to_the_default_when_the_host_sent_none() {
|
|
assert_eq!(open_name("Budget.xlsx"), "Budget.xlsx");
|
|
assert_eq!(open_name("Sheet2!Book.xlsx"), "Sheet2!Book.xlsx");
|
|
assert_eq!(open_name("document"), DEFAULT_OPEN_NAME, "what the crate says for a missing or blank name");
|
|
}
|
|
}
|