/// Render a predicate as an html table
Render a predicate as an html table
Render a predicate as an html table
pub fn render(&self, pred_name: &String) -> Result<String> {
        let pred = self.get_predicate(pred_name)?.ok_or(ErrorKind::Invalid(
            "Predicate absent".to_string(),
        ))?;
        let data = self.derive(&vec![
            Clause {
                pred_name: pred_name.to_string(),
                args: pred.fields
                    .iter()
                    .enumerate()
                    .map(|(i, _)| MatchExpr::Var(i))
                    .collect(),
            },
        ])?;
        let descr = match pred.description {
            Some(descr) => format!("<h3>{}</h3><br />", descr),
            None => "".to_string(),
        };
        let mut html = format!("<h1>{}:</h1><br />{}<table><tr>", pred_name, descr);
        for field in pred.fields {
            let name = match field.name {
                Some(ref name) => name,
                None => "N/A",
            };
            let descr = match field.description {
                Some(ref descr) => format!(" title=\"{}\"", descr),
                None => "".to_string(),
            };
            html.push_str(&format!("<th{}>{}</th>", descr, name));
        }
        html.push_str("</tr>");
        for row in data {
            html.push_str("<tr>");
            for col in row {
                html.push_str(&format!("<td>{}</td>", col))
            }
        }
        html.push_str("</table>");
        Ok(html)
    }
pub fn render ( & self , pred_name : & String ) -> Result < String > { let pred = self . get_predicate ( pred_name ) ? . ok_or ( ErrorKind :: Invalid ( " " . to_string ( ) , ) ) ? ; let data = self . derive ( & vec ! [ Clause { pred_name pred_name to_string ( ) args pred fields iter ( ) enumerate ( ) map ( ( i ) MatchExpr Var ( i ) ) collect ( ) } ] ) ? ; let descr = match pred . description { Some ( descr ) => format ! ( " " descr ) , None => " " . to_string ( ) , } ; let mut html = format ! ( " " pred_name descr ) ; for field in pred . fields { let name = match field . name { Some ( ref name ) => name , None => " " , } ; let descr = match field . description { Some ( ref descr ) => format ! ( " \" \" " descr ) , None => " " . to_string ( ) , } ; html . push_str ( & format ! ( " " descr name ) ) ; } html . push_str ( " " ) ; for row in data { html . push_str ( " " ) ; for col in row { html . push_str ( & format ! ( " " col ) ) } } html . push_str ( " " ) ; Ok ( html ) }
Render a predicate as an html table
Render a predicate as an html table
&self
pred_name
&String