Metadata-Version: 2.1
Name: python-okreport
Version: 1.0.1
Summary: simple report automatic rendering
Home-page: https://github.com/lawley0316/okreport
Author: Lawley
Author-email: lawley0316@gmail.com
License: MIT
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.6
Classifier: Programming Language :: Python :: Implementation :: CPython
Classifier: Programming Language :: Python :: Implementation :: PyPy
Requires-Python: >=3.6.0
Description-Content-Type: text/markdown
Requires-Dist: jinja2


# okreport: simple report automatic rendering

## Installation

```shell
pip install python-okreport
```

## Usage

```python
from okreport import Var, Paragraph, Report

class ResultX(Var):
    def parse(self, result, conf, env):  # noqa
        return result['x']
    
    
class ResultY(Var):
    def parse(self, result, conf, env):  # noqa
        return result['y']
    
    
class ResultSum(Var):
    def parse(self, result, conf, env):  # noqa
        return result['x'] + result['y']

class ConfX(Var):
    def parse(self, result, conf, env):  # noqa
        return conf['x']


class ConfY(Var):
    def parse(self, result, conf, env):  # noqa
        return conf['y']


class ConfSum(Var):
    def parse(self, result, conf, env):  # noqa
        return conf['x'] + conf['y']
    
    
class ResultParagraph(Paragraph):
    """
    In result, x = {{ x }}, y = {{ y }}, sum is {{ sum }}.
    """
    x = ResultX()
    y = ResultY()
    sum = ResultSum()
    
    def get_template_text(self, result, conf, env):  # noqa
        return self.__doc__


class ConfParagraph(Paragraph):
    """
    In conf, x = {{ x }}, y = {{ y }}, sum is {{ sum }}.
    """
    x = ConfX()
    y = ConfY()
    sum = ConfSum()
    
    def get_template_text(self, result, conf, env):  # noqa
        return self.__doc__


class MyReport(Report):
    """
    {{ p1 }}
    {{ p2 }}
    """
    p1 = ResultParagraph()
    p2 = ConfParagraph()
    
    def get_template_text(self, result, conf, env):  # noqa
        return self.__doc__


result = {'x': 1, 'y': 2}
conf = {'x': 3, 'y': 4}
my_report = MyReport()
text = my_report.render(result, conf, None)
print(text)
```
