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

#481 in Text processing

Download history 89/week @ 2024-03-13 40/week @ 2024-03-20 384/week @ 2024-04-03 31/week @ 2024-04-10 132/week @ 2024-04-17 131/week @ 2024-04-24 262/week @ 2024-05-01 44/week @ 2024-05-08 2/week @ 2024-05-15 12/week @ 2024-05-22

165 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

~13–24MB
~323K SLoC