1 unstable release

new 0.3.0 Apr 25, 2024
0.2.1 Apr 18, 2024
0.1.3 Apr 6, 2024
0.0.1 Mar 19, 2024

#421 in Text processing

Download history 129/week @ 2024-03-18 355/week @ 2024-04-01 60/week @ 2024-04-08 132/week @ 2024-04-15

549 downloads per month

Custom license

590KB
794 lines

Metatron

Metatron

Metatron library: Implementation in Rust of a report generation based on Shiva library

Supported report types

  • Plain text
  • Markdown
  • HTML
  • PDF

Usage

Cargo.toml

[dependencies]
metatron = "0.3.0"
fn main() {
    let template_vec = std::fs::read("report-template.yaml").unwrap();
    let template = std::str::from_utf8(&template_vec).unwrap();
    let data_vec = std::fs::read("report-data.json").unwrap();
    let data = std::str::from_utf8(&data_vec).unwrap();
    let images = HashMap::new();
    let doc = Report::generate(template, data, &images).unwrap();
    let result = shiva::pdf::Transformer::generate(&doc).unwrap();
    std::fs::write("report.pdf",result.0).unwrap();
}

How it works

report-template.kdl

template {
    title {
        header level=1 "$P{company_name} Employee Report"
    }
    page_header {
        text size=7 "Confidential information"
    }
    column_header {
        column name="Name" width=30
        column name="Age" width=10
        column name="Salary" width=20
    }
    row {
        value "$F(name)"
        value "$F(age)"
        value "$F(salary)"
    }
    column_footer {
        value "Average:"
        value "$P{average_age}"
        value "$P{average_salary}"
    }
    page_footer {
        text size=7 "Tel: +1 123 456 789"
    }
    summary {
        paragraph {
            text size=10 "Company address: $P{company_address}"
        }
    }
}

report-data.json

{
   "rows": [
     {
       "name": "John",
       "age": 25,
       "salary": 50000
     },
     {
       "name": "Jane",
       "age": 30,
       "salary": 60000
     },
     {
       "name": "Jim",
       "age": 35,
       "salary": 70000
     }
   ],
   "params": {
     "company_name": "ABCDFG Ltd",
     "company_address": "1234 Elm St, Springfield, IL 62701",
     "average_age": 30,
     "average_salary": 60000
   }
}

Generated report

PDF

TODO

  • Add image support
  • CLI
  • Rest API server

Dependencies

~11MB
~71K SLoC