diff --git a/docs/source/dev.rst b/docs/source/dev.rst index 51bfcc7..34da2b7 100644 --- a/docs/source/dev.rst +++ b/docs/source/dev.rst @@ -4,3 +4,47 @@ Developer Documentation Getting Started --------------- .. TODO + +Widgets +------- + +A widget is a piece of HTML that will be inserted in a specific spot in a page to render some view. + +To create a new widget you need to extend the ``Widget`` class from ``colab.widgets``. In the child class you can override the methods below, but it is not mandatory: + +.. attribute:: get_header + + This method should return the HTML code to be used in the page's head. So, it will extract the head content from the ``content``. + +.. attribute:: get_body + + This method should return the HTML code to be used in the page's body. So, it will extract the body content from the ``content``. + +.. attribute:: generate_content + + This method will set the ``content`` when the widget is requested by the ``WidgetManager``. The ``content`` contains a HTML code that will be rendered in the target page. + +The Widget class has the following attributes: + +.. attribute:: identifier + + The identifier has to be a unique string across the widgets. + +.. attribute:: name + + The widget name is the string that will be used to render in the view, if needed. + +Example Widget: + +.. code-block:: python + + from colab.widgets.widget_manager import Widget + + class MyWidget(Widget): + identifier = 'my_widget_id' + name = 'My Widget' + def generate_content(self, request): + # process HTML content + self.content = processed_content + +To add the widget in a view check the Widgets section in User Documentation. diff --git a/docs/source/user.rst b/docs/source/user.rst index 101cfe4..34d5813 100644 --- a/docs/source/user.rst +++ b/docs/source/user.rst @@ -58,6 +58,27 @@ View the following file: The file /etc/colab/settings.py have the configurations of colab, this configurations overrides the django settings.py +Widgets +------- + +A widget is a piece of HTML that will be inserted in a specific spot in a page to render some view. + +To configure the widgets you have to edit, or create, the file ``/etc/colab/widgets_settings.py``. Or you can create a py file inside the folder ``/etc/colab/widgets.d``. + +Example: + +.. code-block:: python + + # Widget Manager handles all widgets and must be imported to register them + from colab.widgets.widget_manager import WidgetManager + + # Specific code for Gitlab's Widget + from colab_gitlab.widgets import GitlabProfileWidget + + WidgetManager.register_widget('profile', GitlabProfileWidget()) + + +In this example the Gitlab's widget is added in a new tab inside the user profile. Add a new plugin ---------------- -- libgit2 0.21.2