23 lines
904 B
Rust
23 lines
904 B
Rust
use renamr_core::format::ExpressionFormat;
|
|||
|
|
use renamr_core::string_bindings;
|
||
|
|
use std::collections::HashMap;
|
||
|
|
|
||
|
|
/// Renders a naming-scheme expression against a set of binding values.
|
||
|
|
/// This is the Tauri-facing entry point into the core format engine, used by the
|
||
|
|
/// rename-preview panel in the UI so users see live results as they edit a pattern.
|
||
|
|
#[tauri::command]
|
||
|
|
fn render_expression(expression: String, bindings: HashMap<String, String>) -> Result<String, String> {
|
||
|
|
let compiled = ExpressionFormat::compile(&expression).map_err(|e| e.to_string())?;
|
||
|
|
compiled
|
||
|
|
.format(&string_bindings(bindings))
|
||
|
|
.map_err(|e| e.to_string())
|
||
|
|
}
|
||
|
|
|
||
|
|
#[cfg_attr(mobile, tauri::mobile_entry_point)]
|
||
|
|
pub fn run() {
|
||
|
|
tauri::Builder::default()
|
||
|
|
.invoke_handler(tauri::generate_handler![render_expression])
|
||
|
|
.run(tauri::generate_context!())
|
||
|
|
.expect("error while running Renamr");
|
||
|
|
}
|