{#
    tinkerbase/layout.html
    ~~~~~~~~~~~~~~~~~~~~~~

    Master layout template for Tinkerer blog themes.

    :copyright: Copyright 2011 by Vlad Riscutia
    :license: FreeBSD, see LICENSE file
#}

{% extends "basic/layout.html" %}

{# Prev/next nav ------------------------------------------------------------ #}

{# characters displayed before/after prev/next links #}
{%- set prevchar = prevchar is not defined and ' &laquo; ' or prevchar %}
{%- set nextchar = nextchar is not defined and ' &raquo; ' or nextchar %}

{# character displyed before and after "Blog Archive" #}
{%- set archivechar = archivechar is not defined and ' &mdash; ' or archivechar %}

{# Page nav ----------------------------------------------------------------- #}

{# page_nav before or after header (default after) #}
{%- set page_nav_first = page_nav_first is defined %}

{# RSS feed ----------------------------------------------------------------- #}

{# include RSS feed link in page_nav (default True) #}
{%- set rss_in_page_nav = rss_in_page_nav is not defined or rss_in_page_nav %}

{# RSS link text (default None) #}
{%- set rss_link_text = rss_link_text is not defined and None or rss_link_text %}

{# RSS symbol in link (default True) #}
{%- set rss_symbol = rss_symbol is not defined or rss_symbol %}

{# Timestamp format --------------------------------------------------------- #}

{# Timestamp format #}
{%- set timestamp_format = timestamp_format is not defined and 
    '<span class="month">%B</span> <span class="day">%d</span>, <span class="year">%Y</day>' 
    or timestamp_format %}
{%- set timestamp_short_format = timestamp_short_format is not defined and 
    '<span class="month">%b</span> <span class="day">%d</span>' or timestamp_short_format %}

{# Macros ------------------------------------------------------------------- #}

{# Blog header #}
{%- macro blog_header() %}
    <div class="header">
        <h1 class="heading">
            <a href="{{ pathto(pages[0][0]) }}">
                <span>{{ shorttitle|e }}</span>
            </a>
        </h1>
        <h2 class="tagline">{{ tagline }}</h2>
    </div>
{%- endmacro %}

{# RSS link #}
{%- macro rss_link() %}
    <a href="{%- if rss_service %}{{ rss_service }}{%- else %}{{ pathto('rss') }}{%- endif %}" title="Subscribe via RSS">
        <div class="rss">
            {%- if rss_symbol %}<span class="webfont">B</span>{%- endif %}
            {% if rss_link_text %}{{ rss_link_text }}{% endif %}
        </div>
    </a>
{%- endmacro %}
 
{# List of blog pages #}
{%- macro page_nav() %}
    <div class="page_nav">
        <ul>
            {% for page in pages %}
            <li>
                <a href="{{ pathto(page[0]) }}">{{ page[1] }}</a>
            </li>
            {% endfor %}
            {%- if rss_in_page_nav %}
            <li class="right">
                {{ rss_link() }}
            </li>
            {%- endif %}
        </ul>
    </div>
    <div class="clearer"></div>
{%- endmacro %}

{# Navigation #}
{%- macro tinkerer_relbar() %}
    {%- if prev or next %}
    <div class="related">
        <ul>
            {%- if prev %}
            <li>
                {{ prevchar }}<a href="{{ prev.link|e }}">{{ prev.title }}</a>
            </li>
            {%- endif %}
            {%- if next %}
            <li class="right">
                <a href="{{ next.link|e }}">{{ next.title }}</a>{{ nextchar }}
            </li>
            {%- endif %}
        </ul>
    </div>
    {%- endif %}
{%- endmacro %}

{# Timestamp #}
{%- macro timestamp(date, fmt) %}
    {%- if date %}
        <div class="timestamp postmeta">
            <span>{{ date.strftime(fmt) }}</span> 
        </div>
    {%- endif %}
{%- endmacro %}

{# Author #}
{%- macro author(author_name) %}
    {%- if author_name %}
        <div class="author">
            <span>Posted by {{ author_name }}</span>
        </div>
    {%- endif %}
{%- endmacro %}

{# Categories #}
{%- macro category_list(post_categories) %}
    {%- if post_categories %}
        <div class="categories">
            <span>
                Filed under:
                {% for link, category in post_categories %}
                    <a href="{{ pathto('categories/' + link + '.html', 1) }}">{{ category }}</a>
                    {%- if not loop.last %}, {%- endif %}
                {% endfor %}
            </span>
        </div>
    {%- endif %}
{%- endmacro %}    

{# Tags #}
{%- macro tag_list(post_tags) %}
    {%- if post_tags %}
        <div class="tags">
            <span>
                Tags:
                {% for link, tag in post_tags %}
                    <a href="{{ pathto('tags/' + link + '.html', 1) }}">{{ tag }}</a>
                    {%- if not loop.last %}, {%- endif %}
                {% endfor %}
            </span>
        </div>
    {%- endif %}
{%- endmacro %}

{# Comment count #}
{%- macro comment_count(code) %}
    {%- if code %}
        <div class="comments">
            {{ code }}
        </div>
    {%- endif %}
{%- endmacro %}

{# Post metadata #}
{%- macro post_meta(metadata, comment_count_code=None) %}
    <div class="postmeta">
        {{ author(metadata.author) }}
        {{ category_list(metadata.filing["categories"]) }}
        {{ tag_list(metadata.filing["tags"]) }}
        {{ comment_count(comment_count_code) }}
    </div>
{%- endmacro %}

{# Blocks ------------------------------------------------------------------- #}

{%- block header %}
    {%- if page_nav_first %}{{ page_nav() }}{%- endif %}
    {{ blog_header() }}
    {%- if not page_nav_first%}{{ page_nav() }}{%- endif %}
{%- endblock %}

{%- block relbar1 %}{%- endblock %}
{%- block relbar2 %}{%- endblock %}

{% block sidebar1 %}{{ sidebar() }}{% endblock %}
{% block sidebar2 %}{% endblock %}

{% block separator %}<div class="separator"></div>{% endblock %}

{%- block footer %}
    <div class="footer">
    {%- if show_copyright %}
        {% trans copyright=copyright|e %}&copy; Copyright {{ copyright }}.{% endtrans %}
    {%- endif %}
    {%- if show_sphinx %}
        Powered by <a href="http://www.tinkerer.me/">Tinkerer</a> and <a href="http://sphinx.pocoo.org/">Sphinx</a>.
    {%- endif %}

    {# Comment plug-in can initialize here #}
    {%- if comment_enabler %}{{ comment_enabler }}{%- endif %}
    </div>
{%- endblock %}
