#!/home/mahnve/.virtualenvs/blog/bin/python
from sinor import posts
from sinor.config import config
import argparse

__author__ = 'mahnve'


def render_single():
    print(posts.render_markdown_page(args.markdown_content,
                                     args.template).encode('utf_8'))


def render_feed():
    print(posts.render_atom_feed(args.html_content).encode('utf_8'))


def render_archive():
    print(posts.render_post_list(args.html_content,
                                 args.template,
                                 args.limit,
                                 args.markdown_content).encode('utf_8'))


def render_mustache():
    print(posts.render_mustache_page(args.template).encode('utf_8'))

if(__name__ == "__main__"):
    parser = argparse.ArgumentParser(
        description="A simple blog tool for static websites")

    parser.add_argument('-f',
                        help='path to config file',
                        default='sinor.toml')

    parser.add_argument("type",
                        choices=['single', 'feed',
                                 'archive', 'mustache'],
                        default="single")

    parser.add_argument("--template",
                        help="Mustache template file")

    parser.add_argument("--markdown_content",
                        help="Markdown content file")

    parser.add_argument("--limit",
                        help="How many posts to include ",
                        type=int)

    parser.add_argument("--tags-dir",
                        help="directory to place tag list files")

    parser.add_argument("--html_content",
                        nargs='+',
                        help="HTML content files")
    args = parser.parse_args()

    config.config_filename = args.f
    commands = {'single': render_single,
                'feed': render_feed,
                'archive': render_archive,
                'mustache': render_mustache}

    commands[args.type]()
