///|
fn render_html_list(items : Array[String]) -> String {
let mut out = ""
for item in items {
out = out + "- " + item + "
"
}
out + "
"
}
///|
pub fn ChemReport::to_html(self : ChemReport) -> String {
let assumption_items : Array[String] = []
for item in self.assumptions {
assumption_items.push(
"" +
escape_html(item.statement) +
"
" +
escape_html(item.impact) +
"",
)
}
let input_items : Array[String] = []
for item in self.inputs {
let mut line = "" +
escape_html(item.name) +
": " +
escape_html(item.value + unit_suffix(item.unit))
if item.note is Some(note) {
line = line + "
" + escape_html(note) + ""
}
input_items.push(line)
}
let result_items : Array[String] = []
for item in self.results {
let mut line = "" +
escape_html(item.name) +
": " +
escape_html(item.value + unit_suffix(item.unit)) +
" " +
escape_html(result_status_name(item.status)) +
""
if item.note is Some(note) {
line = line + "
" + escape_html(note) + ""
}
result_items.push(line)
}
let warning_items : Array[String] = []
for item in self.warnings {
warning_items.push(
"" +
escape_html(item.code) +
" " +
escape_html(severity_name(item.severity)) +
": " +
escape_html(item.summary) +
"
" +
escape_html(item.action) +
"",
)
}
let source_items : Array[String] = []
for item in self.sources {
let mut line = "" +
escape_html(item.label) +
" " +
escape_html(source_kind_name(item.kind)) +
""
if item.url is Some(url) {
line = line + " link"
}
if item.license is Some(license) {
line = line + " license: " + escape_html(license) + ""
}
if item.note is Some(note) {
line = line + "
" + escape_html(note) + ""
}
source_items.push(line)
}
let mut narrative = ""
for item in self.sections {
narrative = narrative +
"" +
escape_html(item.title) +
"
" +
escape_html(section_kind_name(item.kind)) +
"
" +
escape_html(item.body) +
"
"
}
"" +
escape_html(self.metadata.title) +
"" +
escape_html(self.metadata.title) +
"
" +
escape_html(self.summary) +
"
Metadata
" +
render_html_list([
"Report ID: " + escape_html(self.metadata.report_id) + "",
"Process unit: " + escape_html(self.metadata.process_unit) + "",
"Scenario: " + escape_html(self.metadata.scenario) + "",
"Generated at: " + escape_html(self.metadata.generated_at) + "",
"Tool version: " + escape_html(self.metadata.tool_version) + "",
]) +
"Assumptions
" +
render_html_list(assumption_items) +
"Inputs
" +
render_html_list(input_items) +
"Formulas
" +
render_html_list(
[
for item in self.formulas => {
"" +
escape_html(item.name) +
": " +
escape_html(item.expression) +
"
" +
escape_html(item.explanation) +
""
}
],
) +
"Results
" +
render_html_list(result_items) +
"Warnings
" +
(if warning_items.length() == 0 {
"None
"
} else {
render_html_list(warning_items)
}) +
"Sources
" +
render_html_list(source_items) +
"Narrative Sections
" +
narrative +
""
}