# -*- coding: utf-8 -*- vim:sw=4:sts=4:et:ai:si:sta:fenc=utf-8
import ulib.base.i_need_py23

__all__ = ('MarkdownTempl',)

import os

from ulib.base.uio import _u
from ulib.base.lines import Lines
from ulib.base.dates import datef
from base import FileTempl, register_templ

class MarkdownTempl(FileTempl):
    NAME = ('markdown', 'md')
    EXT = ('.mdt', '.mdwn', '.md', '.text')

    MODE = u"markdown"

    def get_lines(self):
        return self.appendtext(None, self.modeline)

class TwpageTempl(FileTempl):
    NAME = ('twpage', 'twp')
    EXT = '.twp'

    MODE = u"markdown"

    TWHEADER = u"""\
# Pense-bête:
#   ''bold'' ==striked== __underline__ //italic// ^^super^^ ~~sub~~
#   @@highlight@@ @@color:red;background-color:white; rouge sur noir@@
#   ~NotAWikiWord [[force wikiword]] [[friendly name|WikiWord]]
#   [[external|http://site.com]] ---- {{monospace}}
#   !h1 !!h2 !!!h3 !!!!h4 !!!!!h5
#   * dotlist   ** sublist   # numlist   ## sublist
#   {{{           |caption|c            [img[title|filename]]
#   pre text      |!header|!header|h    [img[filename]]
#   }}}           |cell|cell|           [img[title|filename][link]]
#   <<<           |>|colspan|           [img[filename][link]]
#   blockquote    |rowspan|one|         [<img[filename]]
#   <<<           |~|two|               [>img[filename]]
#   >quote1       |left| right|
#   >>quote2      |>| center |
#   >>>quote3
##@creator: %(user)s
##@created: %(now)s
##@modifier: %(user)s
##@changecount: 1
##@tags:
##@title: %(basename)s
"""

    def get_lines(self):
        self.user = _u(os.environ.get('USER', ''))
        self.now = _u(datef('%d/%m/%Y %H:%M'))
        lines = Lines()
        lines = self.appendtext(lines, self.modeline)
        return self.appendtext(lines, self.TWHEADER)

class PlantumlTempl(FileTempl):
    NAME = 'plantuml'
    EXT = ('.puml', '.iuml')

    MODE = u"text"

    TEMPLATE = u"""\
##@startuml
hide empty members
hide empty methods
hide circle
!ifndef SHOW_DETAILS
hide members
!endif

##@enduml"""

    def get_lines(self):
        lines = Lines()
        lines = self.appendtext(lines, self.modeline)
        lines = self.appendtext(lines, self.TEMPLATE)
        return lines

register_templ(MarkdownTempl, TwpageTempl, PlantumlTempl)
