5 releases (3 stable)

1.1.1 Sep 14, 2024
1.0.0 Jul 26, 2024
0.3.4 May 7, 2024
0.3.0 Apr 25, 2024
0.0.1 Mar 19, 2024

#469 in Text processing

Custom license

21KB
380 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 = "1.1.1"
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 result = Report::generate(&template, &data, &images, "pdf").unwrap();
    std::fs::write("report.pdf",result).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. Read "Contributor License Agreement (CLA)"
  2. Contact with me via telegram @ievkz or discord @igumnovnsk
  3. Confirm e-mail invitation in repository
  4. Do "git clone"
  5. Create branch with your assigned issue
  6. Create pull request to main branch

Dependencies

~4.5–7.5MB
~138K SLoC