import json import time from typing import List, Dict class HTML(object): def __init__(self, path='/index.html', title=None, styles='gitstats.css', version='v0.0.1') -> None: self.path = path self.title = title self.styles = styles self.version = version self.content = [] def add(self, content): self.content.append(content) def create(self, content = []): f = open(self.path, 'w') head = self.getHeader(title=self.title) body = self.getBody(content, title=self.title) html = self.getHTML(head, body) f.write(html) f.close() def getHTML(self, head: str, body: str) -> str: return f'''{head}{body}''' def getHeader(self, title: str = None) -> str: title = title or f'GitStats - {self.title}' config = json.load(open('tailwind.json')) return ''' %s ''' % (title, self.styles, self.version, json.dumps(config)) def getBody(self, content: List[str], title: str) -> str: sidebar = self.getSideBar() topBar = self.getTopBar(title=title) if len(self.content) > 0 : content = [*self.content, *content] content = '\n'.join(content) return f'''
{sidebar}
{topBar}
{content}
''' def tilesItemStat(self, title: str = '', info: str = '', icon: str = None, stat: str = None) -> str: if icon is not None: icon = f'''
''' if stat is not None: stat = '''

Home Loan Account

deposit
''' self.add(f'''
{icon or ''}

{info}

{title}

{stat or ''}
''') def cardItemStat(self, count: str = '$3.456K', title: str = 'Total views', stat: str = None, arrow: str = 'up', icon=None) -> str: stat_html = '' if stat is not None: stat_html = f''' {stat} {arrow == 'up' and ''} {arrow == 'down' and ''} ''' if icon is None: icon = ''' ''' self.add(f'''
{icon}

{count}

{title}
{stat_html}
''') def getSideBar(self) -> str: menu = ''.join([f'''
  • {label}
  • ''' for (label, href) in [ ("General", "index.html"), ("Activity", "activity.html"), ("Authors", "authors.html"), ("Files", "files.html"), ("Lines", "lines.html"), ("Tags", "tags.html") ]]) return f''' ''' def getTopBar(self, title: str) -> str: return f'''
    ''' def addChart(self, config: Dict, name: str = None, title: str = 'Chart', className: str=None): if name is None: name = f'chart_{int(time.time())}' self.addCard([f'
    '], title=title, className=className, extra=f''' ''') def addCard(self, content, title: str = 'Chart', className: str=None, extra: str=None): content = '\n'.join(content) self.add(f'''

    {title}

    {content}
    {extra or ""}
    ''')