Giter Site home page Giter Site logo

sparqxi / metatron Goto Github PK

View Code? Open in Web Editor NEW

This project forked from igumnoff/metatron

0.0 0.0 0.0 40.65 MB

Metatron library: Implementation in Rust of a report generation

Home Page: https://docs.rs/metatron

License: GNU General Public License v3.0

Rust 97.43% HTML 2.57%

metatron's Introduction

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. 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

metatron's People

Contributors

evgenyigumnov avatar scripthound avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.