Created
March 17, 2021 09:14
-
-
Save addrummond/c7c627f1ef5f8a3ef8548f16b288e326 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#[rustler::nif] | |
fn lint(env: Env, input: String) -> Result<Term, Error> { | |
let parse_errors = lint_html::lint(input); | |
return convert_errors(env, parse_errors); | |
} | |
fn convert_errors(env: Env, parse_errors: Vec<(u64, String)>) -> Result<Term, Error> { | |
if parse_errors.len() == 0 { | |
return Ok(ok().to_term(env)); | |
} else { | |
let e = error().encode(env); | |
let msgs: Vec<Term> = parse_errors.iter().map(|x| x.encode(env)).collect(); | |
let msgs_term: Term = msgs.encode(env); | |
let tuple_elems = vec![e, msgs_term]; | |
return Ok(make_tuple(env, &tuple_elems)); | |
} | |
} | |
rustler::init!( | |
"Elixir.Platform.Plugs.HtmlLintNative", | |
[lint] | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment