Browse Source

Add hook before/after hooks for post content

Decided to go this way and let the post.content be modified by a
seperate hook which will probably involve the markup renderer.
Peter Justin 7 years ago
parent
commit
98f425896d
3 changed files with 41 additions and 6 deletions
  1. 2 0
      docs/hooks.rst
  2. 33 6
      flaskbb/plugins/spec.py
  3. 6 0
      flaskbb/templates/forum/topic.html

+ 2 - 0
docs/hooks.rst

@@ -99,6 +99,8 @@ Template Hooks
 .. autofunction:: flaskbb_tpl_profile_sidebar_stats
 .. autofunction:: flaskbb_tpl_profile_sidebar_stats
 .. autofunction:: flaskbb_tpl_post_author_info_before
 .. autofunction:: flaskbb_tpl_post_author_info_before
 .. autofunction:: flaskbb_tpl_post_author_info_after
 .. autofunction:: flaskbb_tpl_post_author_info_after
+.. autofunction:: flaskbb_tpl_post_content_before
+.. autofunction:: flaskbb_tpl_post_content_after
 .. autofunction:: flaskbb_tpl_post_menu_before
 .. autofunction:: flaskbb_tpl_post_menu_before
 .. autofunction:: flaskbb_tpl_post_menu_after
 .. autofunction:: flaskbb_tpl_post_menu_after
 .. autofunction:: flaskbb_tpl_topic_controls
 .. autofunction:: flaskbb_tpl_topic_controls

+ 33 - 6
flaskbb/plugins/spec.py

@@ -116,7 +116,7 @@ def flaskbb_event_topic_save_after(topic, is_new):
 # Form hooks
 # Form hooks
 @spec
 @spec
 def flaskbb_form_new_post(form):
 def flaskbb_form_new_post(form):
-    """Hook for modyfing the ReplyForm.
+    """Hook for modifying the :class:`~flaskbb.forum.forms.ReplyForm`.
 
 
     For example::
     For example::
 
 
@@ -126,13 +126,13 @@ def flaskbb_form_new_post(form):
                 DataRequired(message="This field is required"),
                 DataRequired(message="This field is required"),
                 Length(min=3, max=50)])
                 Length(min=3, max=50)])
 
 
-    :param form: The ``ReplyForm`` class.
+    :param form: The :class:`~flaskbb.forum.forms.ReplyForm` class.
     """
     """
 
 
 
 
 @spec
 @spec
 def flaskbb_form_new_post_save(form):
 def flaskbb_form_new_post_save(form):
-    """Hook for modyfing the ReplyForm.
+    """Hook for modifying the :class:`~flaskbb.forum.forms.ReplyForm`.
 
 
     This hook is called while populating the post object with
     This hook is called while populating the post object with
     the data from the form. The post object will be saved after the hook
     the data from the form. The post object will be saved after the hook
@@ -145,12 +145,23 @@ def flaskbb_form_new_post_save(form):
 
 
 @spec
 @spec
 def flaskbb_form_new_topic(form):
 def flaskbb_form_new_topic(form):
-    """ """
+    """Hook for modifying the :class:`~flaskbb.forum.forms.NewTopicForm`
+
+    :param form: The :class:`~flaskbb.forum.forms.NewTopicForm` class.
+    """
 
 
 
 
 @spec
 @spec
-def flaskbb_form_new_topic_save(form):
-    """ """
+def flaskbb_form_new_topic_save(form, topic):
+    """Hook for modifying the :class:`~flaskbb.forum.forms.NewTopicForm`.
+
+    This hook is called while populating the topic object with
+    the data from the form. The topic object will be saved after the hook
+    call.
+
+    :param form: The form object.
+    :param topic: The topic object.
+    """
 
 
 
 
 # Template Hooks
 # Template Hooks
@@ -326,6 +337,22 @@ def flaskbb_tpl_post_author_info_after(user, post):
 
 
 
 
 @spec
 @spec
+def flaskbb_tpl_post_content_before(post):
+    """Hook to do some stuff before the post content is rendered.
+
+    :param post: The current post object.
+    """
+
+
+@spec
+def flaskbb_tpl_post_content_after(post):
+    """Hook to do some stuff after the post content is rendered.
+
+    :param post: The current post object.
+    """
+
+
+@spec
 def flaskbb_tpl_post_menu_before(post):
 def flaskbb_tpl_post_menu_before(post):
     """Hook for inserting a new item at the beginning of the post menu.
     """Hook for inserting a new item at the beginning of the post menu.
 
 

+ 6 - 0
flaskbb/templates/forum/topic.html

@@ -91,7 +91,13 @@
                                 {{ gettext("This post is hidden (%(when)s  by %(who)s)", who=post.hidden_by.username, when=format_date(post.hidden_at, '%b %d %Y'))}}
                                 {{ gettext("This post is hidden (%(when)s  by %(who)s)", who=post.hidden_by.username, when=format_date(post.hidden_at, '%b %d %Y'))}}
                             </div>
                             </div>
                             {% endif %}
                             {% endif %}
+
+                        {{ run_hook("flaskbb_tpl_post_content_before", post=post) }}
+
                         {{ post.content|markup }}
                         {{ post.content|markup }}
+
+                        {{ run_hook("flaskbb_tpl_post_content_after", post=post) }}
+
                         <!-- Signature Begin -->
                         <!-- Signature Begin -->
                         {% if flaskbb_config["SIGNATURE_ENABLED"] and post.user_id and user.signature %}
                         {% if flaskbb_config["SIGNATURE_ENABLED"] and post.user_id and user.signature %}
                         <div class="post-signature hidden-xs">
                         <div class="post-signature hidden-xs">