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,9 +126,8 @@ 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 roc_output_str = unsafe { roc_transformFileContentForHost(roc_content) };
let input_relpath = input_file
.strip_prefix(input_dir)
.map_err(|e| e.to_string())?
@ -148,13 +147,6 @@ fn process_file(input_dir: &Path, output_dir: &Path, input_file: &Path) -> Resul
);
Ok(())
}
Err(roc_error_str) => Err(format!(
"Error transforming {}: {}",
input_file.to_str().unwrap_or("an input file"),
roc_error_str.as_str()
)),
}
}
fn find_files(dir: &Path, file_paths: &mut Vec<PathBuf>) -> std::io::Result<()> {
for entry in fs::read_dir(dir)? {

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 ->