2 releases

0.3.4 May 7, 2024
0.3.3 May 4, 2024
0.3.0 Apr 25, 2024
0.2.1 Apr 18, 2024
0.0.1 Mar 19, 2024

#473 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 125/week @ 2024-04-22 159/week @ 2024-04-29 153/week @ 2024-05-06

572 downloads per month

Custom license

670KB
374 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.4"
fn main() {
    let template = std::fs::read_to_string("report-template.kdl").unwrap();
    let data = std::fs::read_to_string("report-data.json").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 {
        image src="data/logo.png" width=100 height=100
        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

Contributing

I would love to see contributions from the community. If you experience bugs, feel free to open an issue. If you would like to implement a new feature or bug fix, please follow the steps:

  1. Contact with me via telegram @ievkz or discord @igumnovnsk
  2. Confirm e-mail invitation in repository
  3. Do "git clone"
  4. Create branch with your assigned issue
  5. Create pull request to main branch

Dependencies

~15MB
~302K SLoC