{#
Macros used by multiple templates.
Original Moin code should be added here. Macros derived from Flatland should be added to forms.html.
#}
{% import 'forms.html' as forms %}
{# "item" must be passed because of flakey jinja2 context passing #}
{% macro rev_navigation(rev_navigation_ids_dates, fqname, view='frontend.show_item', item=item) %}
{% set prior_rev, current_rev, next_rev, prior_mtime, current_mtime, next_mtime = rev_navigation_ids_dates %}
{% if not current_rev == None %}
{%- if next_mtime and not ('trash' in item.meta and item.meta.trash) %}
{%- endif %}
{% endif %}
{% endmacro %}
{% macro show_editor_info(info) %}
{%- if info.uri -%}
{{ info.text }}
{%- elif info.email -%}
{{ info.text }}
{%- else -%}
{{ info.text }}
{%- endif -%}
{% endmacro %}
{% macro editor_info(meta) %}
{%- set info = get_editor_info(meta) -%}
{{ show_editor_info(info) }}
{% endmacro %}
{% macro table(headings, rows, itemname_cols=[], url_cols=[]) %}
{% for heading in headings %}
{% if rows and rows[0][loop.index0] is number %}
{{ heading }} |
{% else %}
{{ heading }} |
{% endif %}
{% endfor %}
{% for row in rows %}
{% for col in row %}
{% if col is number %}
{{ col }} |
{% elif loop.index in itemname_cols %}
{{ col }} |
{% elif loop.index in url_cols %}
{{ col }} |
{%- else -%}
{{ col }} |
{% endif %}
{% endfor %}
{% endfor %}
{% endmacro %}
{% macro header_search(form) %}
{{ gen.form.open(form, id='moin-searchform', method='get', action=url_for('frontend.search')) }}
{{ forms.render(form['q']) }}
{{ forms.render_submit(form, id='moin-search-submit') }}
{{ forms.render_errors(form) }}
{{ gen.form.close() }}
{% endmacro %}
{# return help for editors based upon current item's contenttype #}
{% macro help_on_editing(help) %}
{% if help %}
{% if isinstance(help, tuple) %}
{# display nice button with link to internal help: moinwiki, creole, markdown... #}
{{ help[1] }}
{% else %}
{# no help, one sentence help, or link to help in external site: CSV, images, binary... #}
{{ help|safe }}
{% endif %}
{% endif %}
{% endmacro %}
{# display meta info in delete, destroy, rename, revert and meta view. #}
{% macro meta_info(meta) %}
{#- Bootstrap classes list-group and list-group-item used to display the metadata info in an unordered list #}
{%- if user.may.admin(fqname) %}
{%- set acl = meta['acl'] or '(None)' %}
- ACL: {{ acl }}
{%- endif %}
- Action: {{ meta['action'] }}
- Address: {{ meta['address'] }}
- Comment: '{{ meta['comment'] }}'
- Content Type: {{ meta['contenttype']|shorten_ctype }} [{{ meta['contenttype'] }}]
- Data ID: {{ meta['dataid'] }}
- External Links:
{%- if meta['externallinks'] -%}
{%- for item in meta['externallinks']|sort -%}
{{ item }}
{%- if not loop.last %}, {% endif -%}
{%- endfor -%}
{%- else -%}
(None)
{%- endif -%}
{% if meta.get('has_tag') %}
{# has_tag should not exist in metadata file, belongs only in whoosh index #}
- Has Tag ERROR: {{ meta['has_tag'] }}
{% endif %}
- Item ID: {{ meta['itemid'] }}
- Item Links:
{%- if meta['itemlinks'] -%}
{%- for item in meta['itemlinks']|sort -%}
{{ item }}
{%- if not loop.last %}, {% endif -%}
{%- endfor -%}
{%- else -%}
(None)
{%- endif -%}
- Item Transclusions:
{%- if meta['itemtransclusions'] -%}
{%- for item in meta['itemtransclusions']|sort -%}
{{ item }}
{%- if not loop.last %}, {% endif -%}
{%- endfor -%}
{%- else -%}
(None)
{%- endif -%}
- Item Type: {{ meta['itemtype'] }}
- Language: {{ meta['language'] }}
- Modified Time: {{ meta['mtime']|time_datetime }}
- Name:
{%- if meta['name'] -%}
{%- set names = ' '.join(meta['name']) -%}
{{ names|safe }}
{%- else -%}
(None)
{%- endif -%}
- Old Name:
{%- if meta['name_old'] -%}
{%- set names = ' '.join(meta['name_old']) -%}
{{ names|safe }}
{%- else -%}
(None)
{%- endif -%}
- Namespace: '{{ meta['namespace'] }}'
- Parent Revision ID: {{ meta['parentid'] }}
- Revision ID: {{ meta['revid'] }}
- Revision Number: {{ meta['rev_number'] }}
- SHA1: {{ meta['sha1'] }}
- Size: {{ meta['size']|filesizeformat }}
- Summary: '{{ meta['summary'] }}'
- Tags:
{%- if meta['tags'] -%}
{%- for tag in meta['tags'] -%}
{{ tag }} {%- if not loop.last %}, {% endif -%}
{%- endfor -%}
{%- else -%}
(None)
{%- endif -%}
- Trash: {{ meta['trash'] or False }}
{% if 'usergroup' in meta %}
- User Group: {{ meta['usergroup'] }}
{% endif %}
- User ID: {{ meta['userid'] }}
{% if 'wikidict' in meta %}
- Wiki Dict: {{ meta['wikidict'] }}
{% endif %}
- Wiki Name: {{ meta['wikiname'] }}
{% endmacro %}
{%- macro alias_list(alias) -%}
{%- if alias %}
{%- endif %}
{%- endmacro -%}
{% macro page_trail_link(wiki_name, fqname) %}
{%- if wiki_name -%}
{{ fqname|shorten_fqname }}
{%- else -%}
{{ fqname|shorten_fqname }}
{%- endif %}
{% endmacro %}
{% macro breadcrumbs(breadcrumbs, title_name) %}
{#
Produce a page trail given a list of recently visited items,
and an optional title_name (means current view is a Navigation Link: History, Index, Tags...).
- if an item has alias names, all alias names must be provided (themes can show, suppress or provide a rollover action)
- if an item is not in the default namespace, the namespace will be prefixed to the item name
- last item on page trail must show individual links to all parent items
#}
- {{ _('Page Trail') }}
{%- set trail_items = breadcrumbs() %}
{%- if trail_items %}
{%- for wiki_name, fqname, item_href, aliases, err in trail_items %}
{%- if not loop.last %}
-
{{ page_trail_link(wiki_name, fqname) }}
{{ alias_list(aliases) }}
{%- endif %}
{%- if loop.last %}
-
{%- for segment_name, segment_path in theme_supp.location_breadcrumbs(fqname) -%}
{%- if not loop.last %}
{{ segment_name|shorten_fqname }}
{%- else %}
{{ segment_name|shorten_fqname }}
{%- endif %}
{%- endfor %}
{{ alias_list(aliases) }}
{%- if title_name %}
-
{{ title_name }}
{%- endif %}
{%- endif %}
{%- endfor %}
{%- endif %}
{% endmacro %}
{# Given an fqname, create a link to the item. The full name is displayed, including the namespace. #}
{% macro make_item_link(fq_name) %}
{{ fq_name.fullname }}
{% endmacro %}
{# called by diff to provide revision navigation on right column: < revision: 5 > >> #}
{% macro show_newer_rev_links(item_name, rev, rev_links) %}
{% if rev_links['r2_older'] %}
{% endif %}
{{ _('Revision') }}:
{{ rev.meta['rev_number'] or rev.revid|shorten_id }}
{% if rev_links['r2_newer'] %}
{% endif %}
{% if rev_links['r2_newest'] %}
{% endif %}
{% endmacro %}
{# called by diff to provide revision navigation on left column: << < revision: 5 > #}
{% macro show_older_rev_links(item_name, rev, rev_links) %}
{% if rev_links['r1_oldest'] %}
{% endif %}
{% if rev_links['r1_older'] %}
{% endif %}
{{ _('Revision') }}:
{{ rev.meta['rev_number'] or rev.revid|shorten_id }}
{% if rev_links['r1_newer'] %}
{% endif %}
{% endmacro %}
{# create a header for a diff revision #}
{% macro show_meta(rev, do_rev=True) %}
{% if do_rev %}
{{ _('Revision') }}:
{{ rev.meta['rev_number'] or rev.revid|shorten_id }}
{% endif %}
{{ _('Editor') }}:
{{ editor_info(rev.meta) }}
{{ _('Size') }}:
{{ rev.meta['size'] }}:
{{ _('Time') }}:
{{ rev.meta.mtime|time_datetime }}
{{ _('Comment') }}:
{{ rev.meta['comment'] }}
{% endmacro %}
{# Render a table showing diffs for two text item revisions. #}
{% macro diff_table(diffs) %}
{% if rev_links %}
{# caller is from Item History, show links to older/newer revisions. #}
{% endif %}
{{ _('Deletions are marked like this.') }} |
{{ _('Additions are marked like this.') }} |
{% for llineno, lcontent, rlineno, rcontent in diffs %}
{# these links are to non-existent anchors, see diffScroll in common.js #}
{{ _('Line') }} {{ llineno }}: |
{{ _('Line') }} {{ rlineno }}: |
{{ lcontent }} |
{{ rcontent }} |
{% endfor %}
{% endmacro %}
{# Return links to Login or User/Settings/Logout; callers must provide an enclosing UL tag #}
{%- macro user_login_logoff() %}
{%- if user.valid -%}
{%- set avatar = user.avatar(20) %}
{%- if avatar %}
{%- endif %}
{% if user.name -%}
{%- set wiki_href, display_name, title, exists = theme_supp.userhome() %}
{{ display_name }}
{%- if 'frontend.usersettings' not in cfg.endpoints_excluded -%}
{{ _('Settings') }}
{%- endif %}
{%- endif %}
{%- if user.auth_method in cfg.auth_can_logout %}
{{ _('Logout') }}
{%- endif %}
{%- else %}
{%- set login_url = theme_supp.login_url() %}
{%- if login_url %}
{{ _('Login') }}
{%- endif %}
{%- endif %}
{% endmacro %}
{# create an icon with a link to revert or diff, or an icon based on contenttype of item #}
{% macro item_status_icon(fqname, meta, bookmark_time) %}
{% if meta.trash %}
{% set trash_class = "fa fa-undo fa-lg" if meta.parentid else "fa fa-trash-o" %}
{% elif meta.rev_number > 1 %}
{% if bookmark_time -%}
{% else %}
{%- endif %}
{% else %}
{% endif %}
{% endmacro %}
{# Display an item name, item alias names, item summary or item ID and old names #}
{%- macro item_moniker(meta, fqnames) %}
{%- if meta.name %}
{#- if there are alias names, create a link to each alias #}
{%- for name in fqnames -%}
{%- if not loop.first %}
{% endif -%}
{% if name.field == 'itemid' %}
{# an item revision of a deleted item is being destroyed #}
{{ name|shorten_fqname }} ~( {{ meta.name[0] }})
{% else %}
{{ name }}
{% endif %}
{%- endfor -%}
{%- else %}
{% if meta.summary %}
{{ fqnames[0]|shorten_fqname }}
{% else %}
{{ fqnames[0]|shorten_fqname }}
{% endif %}
{%- endif %}
{%- if not meta.name and meta.name_old %}
{#- this is a deleted item, show old name(s) #}
~({{ meta.name_old|join(' | ') }})
{%- endif %}
{%- endmacro %}
{# Create next page, prior page links for multi-page reports. #}
{% macro page_links(page_num, pages, url) %}
{# if history is long and displayed as several pages, create links to show next and/or prior pages #}
{% if page_num > 1 %}
«
{% endif %}
{% if pages > 1 %}
{% set page_number = _("Page {page_num} of {pages}").format(page_num=page_num, pages=pages) %}
{{ page_number }}
{% endif %}
{% if page_num < pages %}
»
{% endif %}
{% endmacro %}