{% macro gravatar(user, size) -%}
{% set display_name = h.really_unicode(user.display_name) %}
{% set icon_url = '/u/'+user.username.replace('_', '-')+'/user_icon' %}
{% if user.preferences.email_address %}
{% set icon_url = g.gravatar(user.preferences.email_address, default=g.url('/u/'+user.username.replace('_', '-')+'/user_icon')) %}
{% elif user == user.anonymous() %}
{% set icon_url = g.forge_static('images/user.png') %}
{% endif %}
{% if size %}
<img src="{{icon_url}}"
alt="{{display_name}}"
title="{{display_name}}"
height="{{size}}"
width="{{size}}"/>
{% else %}
<img src="{{icon_url}}" alt="{{display_name}}" title="{{display_name}}"/>
{% endif %}
{%- endmacro %}
{% macro email_gravatar(email, title=None, size=None) -%}
{% set title=h.really_unicode(title) %}
{% if email %}
<img src="{{g.gravatar(email, size=size)}}" alt="{{title or email}}" title="{{title or email}}"{% if size %} width="{{size}}" height="{{size}}"{% endif %}/>
{% else %}
<img src="{{g.forge_static('images/user.png')}}" alt="{{title}}" title="{{title}}"{% if size %} width="{{size}}" height="{{size}}"{% endif %}/>
{% endif %}
{%- endmacro %}
{% macro file_field(name, label) %}
{% if label %}
<label for="{{name}}">{{label}}</label>
{% endif %}
<input type="file" id="{{name}}" name="{{name}}" class="text" /><br/>
{% endmacro %}
{% macro text_area(name, label, value=None) %}
{% if label %}
<label for="{{name}}">{{label}}</label><br/>
{% endif %}
<textarea id="{{name}}" name="{{name}}">{{value}}</textarea><br/>
{% endmacro %}
{% macro text_field(name, label, value='') %}
{% if label %}
<label for="{{name}}">{{label}}</label><br/>
{% endif %}
<input type="text" id="{{name}}" name="{{name}}" class="text" value="{{value}}"/><br/>
{% endmacro %}
{% macro radio_button(name, label, option, value=None) %}
{% if label %}
<label for="{{name}}">{{label}}</label><br/>
{% endif %}
<input type="radio" id="{{name}}" name="{{name}}" class="text" value="{{option}}"
{% if option == value %}checked="on"{% endif %}/><br/>
{% endmacro %}
{% macro submit_button(value, name=None) %}
<input type="submit" name="{{name}}" value="{{value}}"/><br/>
{% endmacro %}
{% macro path_links(parts) %}
{% set i=0 %}
{% for part in parts %}
<a href="{{'./' + '../' * (parts.__len__()-i-1)}}">{{part}}</a> /
{% set i=i+1 %}
{% endfor %}
{% endmacro %}
{% macro post_summary(post) %}
{% if post %}
<span>
by <a href="{{post.author().url()}}">{{post.author().display_name}}</a>
{{h.ago(post.timestamp)}}
</span>
{% endif %}
{% endmacro %}
{% macro crumbs(trail) %}
{% for (label, url) in trail %}
<li class="{{loop.index0 == 0 and 'first' or ''}}">
{% if url %}
<a href="{{url}}">{{label}}</a>
{% else %}
<span>{{label}}</span>
{% endif %}
</li>
{% endfor %}
{% endmacro %}