{#-
    boilerplate/layout.html
    ~~~~~~~~~~~~~~~~~~~~~~~

    Master layout template for Tinkerer blog themes.

    :copyright: Copyright 2011-2012 by Vlad Riscutia and contributors (see
    CONTRIBUTORS file). 
    :license: FreeBSD. Parts of this file are licensed under BSD license. See
    LICENSE file.
-#}

{#- Doctype -#}
{%- block doctype -%}
<!doctype html>
{%- endblock -%}

{%- set render_sidebar = (not embedded) and (not theme_nosidebar|tobool) and
                         (sidebars != []) -%}
{%- set url_root = pathto('', 1) -%}
{%- if not embedded and docstitle -%}
  {%- set titlesuffix = " &mdash; "|safe + docstitle|e -%}
{%- else -%}
  {%- set titlesuffix = "" -%}
{%- endif -%}

{%- set prevchar = prevchar is not defined and ' &laquo; ' or prevchar -%}
{%- set nextchar = nextchar is not defined and ' &raquo; ' or nextchar -%}
{%- set archivechar = archivechar is not defined and ' &mdash; ' or archivechar -%}

{%- if rss_service -%}
    {%- set rss_feed_link = rss_service -%}
{%- else -%}
    {%- set rss_feed_link = pathto('rss') -%}
{%- endif -%}    

{%- set rss_in_page_nav = rss_in_page_nav is not defined or rss_in_page_nav -%}
{%- set rss_link_text = rss_link_text is not defined and None or rss_link_text -%}
{%- set rss_symbol = rss_symbol is not defined or rss_symbol -%}
{%- 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 -%}

{%- macro script() -%}
    <script type="text/javascript">
      var DOCUMENTATION_OPTIONS = {
        URL_ROOT:    '{{ url_root }}',
        VERSION:     '{{ release|e }}',
        COLLAPSE_INDEX: false,
        FILE_SUFFIX: '{{ '' if no_search_suffix else file_suffix }}',
        HAS_SOURCE:  {{ has_source|lower }}
      };
    </script>
    {%- for scriptfile in script_files -%}
        {#- Hack to filter out jquery.js auto-included by Sphinx since jquery is 
           already included in head. -#}
        {%- if scriptfile != "_static/jquery.js" -%}
            <script type="text/javascript" src="{{ pathto(scriptfile, 1) }}"></script>
        {%- endif -%}
    {%- endfor -%}
{%- endmacro -%}

{%- macro css() -%}
    <link rel="stylesheet" href="{{ pathto('_static/' + style, 1) }}" type="text/css" />
    <link rel="stylesheet" href="{{ pathto('_static/pygments.css', 1) }}" type="text/css" />
    {%- for cssfile in css_files -%}
    <link rel="stylesheet" href="{{ pathto(cssfile, 1) }}" type="text/css" />
    {%- endfor -%}
{%- endmacro -%}

{#- RSS link -#}
{%- macro rss_link() -%}
    <div class="rss">
        <a href="{{ rss_feed_link }}" title="Subscribe via RSS">
            {%- if rss_symbol -%}<span class="webfont">B</span>{%- endif -%}
            {% if rss_link_text -%}{{ rss_link_text }}{% endif -%}
        </a>
    </div>
{%- endmacro -%}

{#- prev/next -#}
{%- macro relbar() -%}
    {%- if prev or next -%}
    <div class="related">
        <ul>
            <li class="left">
            {%- if prev -%}
                {{ prevchar }}<a href="{{ prev.link|e }}">{{ prev.title }}</a>
            {%- endif -%}
            </li>
            <li class="right">
            {%- if next -%}
                <a href="{{ next.link|e }}">{{ next.title }}</a>{{ nextchar }}
            {%- endif -%}
            </li>
        </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 -%}

<!--[if lt IE 7]> <html class="no-js ie6 oldie" lang="en"> <![endif]-->
<!--[if IE 7]>    <html class="no-js ie7 oldie" lang="en"> <![endif]-->
<!--[if IE 8]>    <html class="no-js ie8 oldie" lang="en"> <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="en"> <!--<![endif]-->

<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  {{ metatags }}
  {%- block htmltitle -%}
  <title>{{ title|striptags|e }}{{ titlesuffix }}</title>
  {%- endblock -%}
  <!-- Mobile viewport optimized: j.mp/bplateviewport -->
  <meta name="viewport" content="width=device-width,initial-scale=1">
  <link rel="stylesheet" href="{{ pathto('_static/style.css', 1) }}" type="text/css">
  {{ css() }}
  <link rel="stylesheet" href="{{ pathto('_static/webfont.css', 1) }}" type="text/css">
  {%- if not embedded -%}
  {%- if favicon -%}
  <link rel="shortcut icon" href="{{ pathto('_static/' + favicon, 1) }}" />
  {%- endif -%}
  <!-- Load modernizr and JQuery -->
  <script src="{{ pathto('_static/modernizr-2.0.6.min.js', 1) }}"></script>
  <!-- Grab Google CDN's jQuery, fall back to local if offline -->
  <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script>
  <script>window.jQuery || document.write('<script src="{{ pathto('_static/jquery-1.6.2.min.js', 1) }}"><\/script>')</script>
  {%- if use_opensearch -%}
  <link rel="search" type="application/opensearchdescription+xml"
        title="{% trans docstitle=docstitle|e -%}Search within {{ docstitle }}{% endtrans -%}"
        href="{{ pathto('_static/opensearch.xml', 1) }}"/>
  {%- endif -%}
  {%- endif -%}
{%- block linktags -%}
  {%- if hasdoc('about') -%}
  <link rel="author" title="{{ _('About these documents') }}" href="{{ pathto('about') }}" />
  {%- endif -%}
  {%- if hasdoc('genindex') -%}
  <link rel="index" title="{{ _('Index') }}" href="{{ pathto('genindex') }}" />
  {%- endif -%}
  {%- if hasdoc('search') -%}
  <link rel="search" title="{{ _('Search') }}" href="{{ pathto('search') }}" />
  {%- endif -%}
  {%- if hasdoc('copyright') -%}
  <link rel="copyright" title="{{ _('Copyright') }}" href="{{ pathto('copyright') }}" />
  {%- endif -%}
  <link rel="top" title="{{ docstitle|e }}" href="{{ pathto('index') }}" />
  {%- if parents -%}
  <link rel="up" title="{{ parents[-1].title|striptags|e }}" href="{{ parents[-1].link|e }}" />
  {%- endif -%}
  {%- if next -%}
  <link rel="next" title="{{ next.title|striptags|e }}" href="{{ next.link|e }}" />
  {%- endif -%}
  {%- if prev -%}
  <link rel="prev" title="{{ prev.title|striptags|e }}" href="{{ prev.link|e }}" />
  {%- endif -%}
  <link rel="alternate" type="application/rss+xml" title="RSS" href="{{ rss_feed_link }}" />
{%- endblock -%}

{%- if not embedded -%}
{{ script() }}
{%- endif -%}

{%- block extrahead -%} {% endblock -%}
</head>
<body>
  <div id="container">

{%- block header -%}
    <header>
      <hgroup>
        <h1><a href="{{ pathto(pages[0][0]) }}">{{ shorttitle|e }}</a></h1>
        <h2>{{ tagline|e }}</h2>
      </hgroup>
    </header>
{% endblock -%}

{%- block navigation -%}
    <nav class="clearfix">
      <ul class="main-navigation">
        {%- block quicklinks -%}
          {%- if rss_in_page_nav -%}
          <li class="quicklink">{{ rss_link() }}</li>
          {%- endif -%}
        {%- endblock -%}
        {% for page in pages -%}
        <li class="main-nav">
          <a href="{{ pathto(page[0]) }}">{{ page[1]|e }}</a>
        </li>
        {% endfor -%}  
      </ul>
    </nav>
{%- endblock -%}

    <div class="main">
{%- block content -%}
      <div class="content clearfix">
      {%- block document -%}
        <div class="documentwrapper">
          {%- block relbar1 -%}{{ relbar() }}{% endblock -%}
            <article class="document">
              {% block body -%} {% endblock -%}
            </article>
          {%- block relbar2 -%}{{ relbar() }}{% endblock -%}
        </div>
      {%- endblock -%}
      {%- if render_sidebar -%}
        <aside class="sidebar">
          {%- if sidebars != None -%}
            {%- for sidebartemplate in sidebars -%}
            <section>
              {%- include sidebartemplate -%}
            </section>
            {%- endfor -%}
          {%- endif -%}
        </aside>
      {%- endif -%}
      </div>
{%- endblock -%}
    </div>

{%- block footer -%}
    <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 -%}
    </footer>
{%- endblock -%}

  </div> <!--! end of #container -->

  {#- Comment plug-in initialization -#}
  {%- if comment_enabler -%}{{ comment_enabler }}{%- endif -%}
  <!--[if lt IE 7 ]>
    <script src="//ajax.googleapis.com/ajax/libs/chrome-frame/1.0.3/CFInstall.min.js"></script>
    <script>window.attachEvent('onload',function(){CFInstall.check({mode:'overlay'})})</script>
  <![endif]-->
</body>
</html>

