Pillar Extensions can now add links to the sidebar.
This commit is contained in:
parent
6429c3df21
commit
5dd49fa5dd
@ -1,5 +1,6 @@
|
||||
"""Pillar server."""
|
||||
|
||||
import collections
|
||||
import copy
|
||||
import logging
|
||||
import logging.config
|
||||
@ -36,7 +37,8 @@ class PillarServer(Eve):
|
||||
kwargs.setdefault('validator', custom_field_validation.ValidateCustomFields)
|
||||
super(PillarServer, self).__init__(settings=empty_settings, **kwargs)
|
||||
|
||||
self.pillar_extensions = {} # mapping from extension name to extension object.
|
||||
# mapping from extension name to extension object.
|
||||
self.pillar_extensions = collections.OrderedDict()
|
||||
self.pillar_extensions_template_paths = [] # list of paths
|
||||
|
||||
self.app_root = os.path.abspath(app_root)
|
||||
@ -517,3 +519,15 @@ class PillarServer(Eve):
|
||||
"""
|
||||
|
||||
return self.data.driver.db
|
||||
|
||||
def extension_sidebar_links(self, project):
|
||||
"""Returns the sidebar links for the given projects.
|
||||
|
||||
:returns: HTML as a string for the sidebar.
|
||||
"""
|
||||
|
||||
if not project:
|
||||
return ''
|
||||
|
||||
return jinja2.Markup(''.join(ext.sidebar_links(project)
|
||||
for ext in self.pillar_extensions.values()))
|
||||
|
@ -86,3 +86,11 @@ class PillarExtension(object):
|
||||
|
||||
def setup_app(self, app):
|
||||
"""Called during app startup, after all extensions have loaded."""
|
||||
|
||||
def sidebar_links(self, project):
|
||||
"""Returns the sidebar link(s) for the given projects.
|
||||
|
||||
:returns: HTML as a string for the sidebar.
|
||||
"""
|
||||
|
||||
return ''
|
||||
|
@ -301,6 +301,8 @@ def render_project(project, api, extra_context=None, template_name=None):
|
||||
embed_string = ''
|
||||
template_name = "projects/view{0}.html".format(embed_string)
|
||||
|
||||
extension_sidebar_links = current_app.extension_sidebar_links(project)
|
||||
|
||||
return render_template(template_name,
|
||||
api=api,
|
||||
project=project,
|
||||
@ -308,6 +310,7 @@ def render_project(project, api, extra_context=None, template_name=None):
|
||||
show_node=False,
|
||||
show_project=True,
|
||||
og_picture=project.picture_header,
|
||||
extension_sidebar_links=extension_sidebar_links,
|
||||
**extra_context)
|
||||
|
||||
|
||||
@ -355,13 +358,16 @@ def view_node(project_url, node_id):
|
||||
# Append _theatre to load the proper template
|
||||
theatre = '_theatre' if theatre_mode else ''
|
||||
|
||||
extension_sidebar_links = current_app.extension_sidebar_links(project)
|
||||
|
||||
return render_template('projects/view{}.html'.format(theatre),
|
||||
api=api,
|
||||
project=project,
|
||||
node=node,
|
||||
show_node=True,
|
||||
show_project=False,
|
||||
og_picture=og_picture)
|
||||
og_picture=og_picture,
|
||||
extension_sidebar_links=extension_sidebar_links)
|
||||
|
||||
|
||||
def find_project_or_404(project_url, embedded=None, api=None):
|
||||
|
@ -82,6 +82,7 @@ link(href="{{ url_for('static_pillar', filename='assets/css/project-main.css', v
|
||||
a(href="{{url_for('projects.search', project_url=project.url, _external=True)}}")
|
||||
i.pi-search
|
||||
| {% endif %}
|
||||
| {{ extension_sidebar_links }}
|
||||
|
||||
.project_nav-toggle-btn(
|
||||
title="Expand Navigation [T]",
|
||||
|
Loading…
x
Reference in New Issue
Block a user