Skip to main content

splice_region

Function splice_region 

Source
pub fn splice_region(
    host: Option<&str>,
    body: &str,
    stamp: &str,
) -> Result<String, String>
Expand description

Splice a rendered body into a host document between the region markers, the begin marker carrying stamp. With no host, or a host without a region, the region is appended (after a blank line when the host exists). Malformed markers (a begin without an end, out of order, or repeated) are an error.

use majordomus_cli::providers::splice_region;
let host = "# Mine\n\n<!-- majordomus:begin abc0 def1 -->\nstale\n<!-- majordomus:end -->\n\ntail\n";
let out = splice_region(Some(host), "fresh\n", "p c").unwrap();
assert_eq!(out, "# Mine\n\n<!-- majordomus:begin p c -->\nfresh\n<!-- majordomus:end -->\n\ntail\n");
assert_eq!(splice_region(None, "fresh\n", "p c").unwrap(), "<!-- majordomus:begin p c -->\nfresh\n<!-- majordomus:end -->\n");
assert!(splice_region(Some("<!-- majordomus:begin -->\nno end\n"), "x\n", "p c").is_err());