Skip to content

Commit

Permalink
Add option to specify embed URL for comments feed
Browse files Browse the repository at this point in the history
  • Loading branch information
Mendes committed May 3, 2017
1 parent 57edd11 commit b8b96b4
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
13 changes: 11 additions & 2 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,17 @@ To embed Discourse comments in your PyBossa theme:
{{ discourse.comments() }}
{% endif %}

The first time that someone visits each page on which the above snippet appears a new topic will be created.
When people post in that topic, their comments will show up on the page where that topic is embedded.
The above function takes a single optional parameter that specifies the URL of the page that is embedding the comment
feed. By default this is set to the URL of the current page. The first time that someone the page a new topic will be
created based on that URL.

So, if you wanted to create a new topic for each category and embed that topic in various different places you might do this:

.. code-block:: HTML+Django

{% if 'pybossa_discourse' in plugins %}
{{ discourse.comments(url_for('project.project_cat_index', category=short_name)) }}
{% endif %}


API variable
Expand Down
6 changes: 4 additions & 2 deletions pybossa_discourse/globals.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@ def __init__(self, app):
self.api = discourse_client
app.jinja_env.globals.update(discourse=self)

def comments(self):
def comments(self, embedUrl=None):
"""Return an HTML snippet used to embed Discourse comments."""
if not embedUrl:
embedUrl = request.base_url
return Markup("""
<div id="discourse-comments"></div>
<script type="text/javascript">
Expand All @@ -33,7 +35,7 @@ def comments(self):
(head || body).appendChild(d);
}}
</script>
""").format(self.url, request.base_url)
""").format(self.url, embedUrl)

def notifications(self):
"""Return a count of unread notifications for the current user."""
Expand Down
2 changes: 1 addition & 1 deletion pybossa_discourse/info.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@
"website": "https://github.com/alexandermendes/pybossa-discourse",
"license": "BSD",
"description": "A PyBossa plugin for Discourse integration.",
"version": "0.2.1"
"version": "0.2.2"
}

0 comments on commit b8b96b4

Please sign in to comment.