Source

digrsser / app / digrsser / templates / macros.html

<!-- YET ANOTHER FORM FIELD MACRO -->
{% macro with_errors(field) %}
  <div class="form_field">
  {% if field.errors %}
      {% set css_class = 'has_error ' + kwargs.pop('class', '') %}
      {{ field(class=css_class, **kwargs) }}
      <ul class="errors">{% for error in errors %}<li>{{ error|e }}</li>{% endfor %}</ul>
  {% else %}
      {{ field(**kwargs) }}
  {% endif %}
  </div>
{% endmacro %}

<!-- LIST ENTRIES -->
{% macro entrylist(entries) -%}
    {% include "entrylist.html" %}
{%- endmacro %}

<!-- ADD SUBSCRIPTION FORM -->
{% macro render_add_sub_form(form) %}
  <form id="form-add-sub-form" action="{{ url_for('add_sub') }}" method="post" accept-charset="utf-8">
    {{ form.csrf_token }}
    {{ form.key }}
    <div class="url">{{ render_field(form.url) }}</div>
    <div class="rule">{{ render_field(form.grouping_rule) }}</div>
    <div class="submit">{{ form.submit }}</div>
    <div class="cancel">{{ form.cancel }}</div>
  </form>
  <div class="actions">
    <a class="add" href="#"></a>
  </div>
{% endmacro %}

<!-- EDIT SUBSCRIPTION FORM -->
{% macro render_edit_sub_form(form, sub) %}
	<div>
		<form id="form-edit-sub-form" action="{{ url_for('edit_sub', id=sub.key().id()) }}" method="post" accept-charset="utf-8">
        {{ form.csrf_token }}
        {{ form.key }}
        <div class="url">{{ render_field(form.url) }}</div>
        <div class="name">{{ render_field(form.title) }}</div>
        <div class="rule">{{ render_field(form.grouping_rule) }}</div>
        <div class="submit">{{ form.submit }}</div>
        <div class="cancel">{{ form.cancel }}</div>
    </form>
	</div>
{% endmacro %}

<!-- RENDER FORM FIELD WITH VALIDATION ERRORS -->
{% macro render_field(field) %}
  <dt>{{ field.label }}</dt>
  <dd>{{ field(**kwargs)|safe }}
  {% if field.errors %}
    <ul class="errors">
      {% for error in field.errors %}<li>{{ error }}{% endfor %}</li>
    </ul>
  {% endif %}
  </dd>
  <div class="end"></div>
{% endmacro %}

<!-- SUBSCRIPTION LISTING -->
{% macro render_sub_list(subs, sub_in_edit=None, form=None) %}
{% from "macros.html" import render_edit_sub_form %}
<div class="subscriptions">

  {{ render_add_sub_form(form) }}

  {% for sub in subs %}
  {% set state = 'active' if (sub_in_edit and sub_in_edit.key() == sub.key()) else 'passive' %}
  <div class="subscription {{ state }}" id="sub-{{ sub.key().id() }}">
    <div class="title">
        <h2 class="title"><a href="{{ url_for('edit_sub', id=sub.key().id()) }}">{{ sub.title }}</a></h2>
    </div>
    <ul class="urls">
      {% for url in sub.urls %}
      <li><a href="{{ url_for('edit_sub', id=sub.key().id()) }}">{{ url }}</a></li>
      {% endfor %}
    </ul>

    {% if sub_in_edit and sub.key() == sub_in_edit.key() %}
      <div class="active">
        {{ render_edit_sub_form(form, sub) }}
      </div>
    {% else %}
      <div class="actions">
        <a class="edit" href="{{ url_for('edit_sub', id=sub.key().id()) }}">Edit</a>
        <a class="remove" href="{{ url_for('del_sub', id=sub.key().id()) }}">Remove</a>
        <a class="update" href="{{ url_for('update_sub', id=sub.key().id()) }}">Update</a>
        <a class="rss" href="{{ url_for('show_sub_rss', key=sub.key()) }}">Show RSS</a>
      </div>
    {% endif %}

    <div class="clear"></div>
    <div class="entries"><div class="list"></div></div>
  </div>
  {% endfor %}
</div>
{% endmacro %}

<!-- LIST SUBSCRIPTION FEED DIGESTS, PER GROUP  -->
{% macro render_sub_groups(sub) %}
<div class="groups">
  {% set onc = {0:'open', 1:'closed'} %}
  {% for group in sub.get_groups() %}
  <div class="group {{ onc[group.closed] }}">
    <ul>
    {% for entry in group.get_entries() %}
      <li><a href="{{ entry.url }}">{{ entry.title }}</a></li>
    {% endfor %}
    </ul>
  </div>
  {% endfor %}
</div>
{% endmacro %}