plugins.rst 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. .. _plugins:
  2. Plugins
  3. =======
  4. .. module:: flaskbb.plugins
  5. FlaskBB provides an easy way to extend the functionality of your forum
  6. via so called `Plugins`. Plugins do not modify the `core` of FlaskBB, so
  7. you can easily activate and deactivate them anytime. This part of the
  8. documentation only covers the basic things for creating plugins. If you are
  9. looking for a tutorial you need to go to this section of the documentation:
  10. :doc:`plugin_tutorial/index`.
  11. Structure
  12. ---------
  13. A plugin has it's own folder where all the plugin specific files are living.
  14. For example, the structure of a plugin could look like this
  15. .. sourcecode:: text
  16. my_plugin
  17. |-- info.json Contains the Plugin's metadata
  18. |-- license.txt The full license text of your plugin
  19. |-- __init__.py The plugin's main class is located here
  20. |-- views.py
  21. |-- models.py
  22. |-- forms.py
  23. |-- static
  24. | |-- style.css
  25. |-- templates
  26. |-- myplugin.html
  27. Management
  28. ----------
  29. Deactivating
  30. ~~~~~~~~~~~~
  31. The only way to disable a plugin without removing it is, to add a ``DISABLED``
  32. file in the plugin's root folder. You need to reload your application in order
  33. to have the plugin fully disabled. A disabled plugin could look like this::
  34. my_plugin
  35. |-- DISABLED # Just add a empty file named "DISABLED" to disable a plugin
  36. |-- info.json
  37. |-- __init__.py
  38. .. important:: Restart the server.
  39. You must restart the wsgi/in-built server in order to make the changes
  40. effect your forum.
  41. Activating
  42. ~~~~~~~~~~
  43. Simply remove the ``DISABLED`` file in the plugin directory and restart the
  44. server.
  45. Example Plugin
  46. --------------
  47. A really simple Plugin could look like this:
  48. .. sourcecode:: python
  49. from flask import flash
  50. from flask.ext.plugins import connect_event
  51. from flaskbb.plugins import FlaskBBPlugin
  52. # This is the name of your Plugin class which implements FlaskBBPlugin.
  53. # The exact name is needed in order to be recognized as a plugin.
  54. __plugin__ "HelloWorldPlugin"
  55. def flash_index():
  56. """Flashes a message when visiting the index page."""
  57. flash("This is just a demonstration plugin", "success")
  58. class HelloWorldPlugin(FlaskBBPlugin):
  59. def setup(self):
  60. connect_event(before-forum-index-rendered, flash_index)
  61. def install(self):
  62. # there is nothing to install
  63. pass
  64. def uninstall(self):
  65. # and nothing to uninstall
  66. pass
  67. Your plugins also needs a ``info.json`` file, where it stores some meta data
  68. about the plugin. For more information see the `Metadata <#metadata>`_
  69. section below.
  70. Metadata
  71. ~~~~~~~~
  72. In order to get a working plugin, following metadata should be defined
  73. in a ``info.json`` file.
  74. ``identifier`` : **required**
  75. The plugin's identifier. It should be a Python identifier (starts with a
  76. letter or underscore, the rest can be letters, underscores, or numbers)
  77. and should match the name of the plugin's folder.
  78. ``name`` : **required**
  79. A human-readable name for the plugin.
  80. ``author`` : **required**
  81. The name of the plugin's author, that is, you. It does not have to include
  82. an e-mail address, and should be displayed verbatim.
  83. ``description``
  84. A description of the plugin in a few sentences. If you can write multiple
  85. languages, you can include additional fields in the form
  86. ``description_lc``, where ``lc`` is a two-letter language code like ``es``
  87. or ``de``. They should contain the description, but in the indicated
  88. language.
  89. ``website``
  90. The URL of the plugin's Web site. This can be a Web site specifically for
  91. this plugin, Web site for a collection of plugins that includes this plugin,
  92. or just the author's Web site.
  93. ``license``
  94. A simple phrase indicating your plugin's license, like ``GPL``,
  95. ``MIT/X11``, ``Public Domain``, or ``Creative Commons BY-SA 3.0``. You
  96. can put the full license's text in the ``license.txt`` file.
  97. ``version``
  98. This is simply to make it easier to distinguish between what version
  99. of your plugin people are using. It's up to the theme/layout to decide
  100. whether or not to show this, though.
  101. Events
  102. ------
  103. A full list with events can be found here :doc:`events`.
  104. Plugin Class
  105. ------------
  106. .. autoclass:: FlaskBBPlugin
  107. .. autoattribute:: settings_key
  108. .. autoattribute:: installable
  109. .. autoattribute:: uninstallable
  110. .. automethod:: setup
  111. .. automethod:: install
  112. .. automethod:: uninstall
  113. .. automethod:: register_blueprint
  114. .. automethod:: create_table
  115. .. automethod:: drop_table
  116. .. automethod:: create_all_tables
  117. .. automethod:: drop_all_tables