static-site-gen: get rid of Result

This commit is contained in:
Brian Carroll 2022-09-03 18:23:28 +01:00
parent 65a18591e5
commit bbc8c36d30
No known key found for this signature in database
GPG Key ID: 5C7B2EC4101703C0
3 changed files with 21 additions and 30 deletions

View File

@ -1,9 +1,9 @@
platform "static-site-gen"
requires {} { transformFileContent : Str -> Result Str Str }
requires {} { transformFileContent : Str -> Str }
exposes []
packages {}
imports []
provides [transformFileContentForHost]
transformFileContentForHost : Str -> Result Str Str
transformFileContentForHost : Str -> Str
transformFileContentForHost = \list -> transformFileContent list

View File

@ -9,7 +9,7 @@ use std::path::{Path, PathBuf};
extern "C" {
#[link_name = "roc__transformFileContentForHost_1_exposed"]
fn roc_transformFileContentForHost(content: RocStr) -> RocResult<RocStr, RocStr>;
fn roc_transformFileContentForHost(content: RocStr) -> RocStr;
}
#[no_mangle]
@ -126,34 +126,26 @@ fn process_file(input_dir: &Path, output_dir: &Path, input_file: &Path) -> Resul
})?;
let roc_content = RocStr::from(rust_content.as_str());
let roc_result = unsafe { roc_transformFileContentForHost(roc_content) };
match Result::from(roc_result) {
Ok(roc_output_str) => {
let input_relpath = input_file
.strip_prefix(input_dir)
.map_err(|e| e.to_string())?
.to_path_buf();
let roc_output_str = unsafe { roc_transformFileContentForHost(roc_content) };
let mut output_relpath = input_relpath.clone();
output_relpath.set_extension("html");
let input_relpath = input_file
.strip_prefix(input_dir)
.map_err(|e| e.to_string())?
.to_path_buf();
let output_file = output_dir.join(&output_relpath);
let rust_output_str: &str = &roc_output_str;
fs::write(&output_file, rust_output_str).map_err(|e| format!("{}", e))?;
let mut output_relpath = input_relpath.clone();
output_relpath.set_extension("html");
println!(
"{} -> {}",
input_relpath.display(),
output_relpath.display()
);
Ok(())
}
Err(roc_error_str) => Err(format!(
"Error transforming {}: {}",
input_file.to_str().unwrap_or("an input file"),
roc_error_str.as_str()
)),
}
let output_file = output_dir.join(&output_relpath);
let rust_output_str: &str = &roc_output_str;
fs::write(&output_file, rust_output_str).map_err(|e| format!("{}", e))?;
println!(
"{} -> {}",
input_relpath.display(),
output_relpath.display()
);
Ok(())
}
fn find_files(dir: &Path, file_paths: &mut Vec<PathBuf>) -> std::io::Result<()> {

View File

@ -3,12 +3,11 @@ app "static-site"
imports [pf.Html.{ html, head, body, div, text }]
provides [transformFileContent] to pf
transformFileContent : Str -> Result Str Str
transformFileContent : Str -> Str
transformFileContent = \content ->
content
|> view
|> Html.render
|> Ok
view : Str -> Html.Node
view = \content ->