From e53bb013611d3948c1d630a7649017d823fdf929 Mon Sep 17 00:00:00 2001 From: winkidney Date: Fri, 8 May 2020 11:25:04 +0800 Subject: [PATCH] Doc: Add docker and development how to for plugins --- docs/src/plugin-system.md | 59 ++++++++++++++++++++++++++++++++++----- 1 file changed, 52 insertions(+), 7 deletions(-) diff --git a/docs/src/plugin-system.md b/docs/src/plugin-system.md index 8683dba..d37714e 100644 --- a/docs/src/plugin-system.md +++ b/docs/src/plugin-system.md @@ -1,15 +1,39 @@ # New plugin system for Pinry -New plugin system is under development. +New plugin system is under development and a naive version has been released. -Now you could access it via project example plugin file `pinry_plugins/batteries/plugin_example.py`. +A `PinryPlugin` is a python class or object which is callable. +The plugin loader will call the plugin argument only once and use the plugin +instance after specified events triggered just like the way django-middleware works. -You could create a simple plugin which has a class which owns methods named: +You could create a plugin as python-package with content: -+ process_image_pre_creation -+ process_thumbnail_pre_creation - -And, add the plugin class to local_settings.py as: +``` +from core.models import Image +from django_images.models import Thumbnail + + +class Plugin: + + def __init__(self): + # do something you want, just be called only + pass + + def process_image_pre_creation(self, django_settings, image_instance: Image): + pass + + def process_thumbnail_pre_creation(self, django_settings, thumbnail_instance: Thumbnail): + pass + +``` + + +You could make some changes on Image object and Thumbnail object +before they actually be saved (for example, add water-mark to them). + +You could access example plugin via `pinry_plugins/batteries/plugin_example.py`. + +After all, enable the plugin in local_settings.py: ``` ENABLED_PLUGINS = [ @@ -18,3 +42,24 @@ ENABLED_PLUGINS = [ ``` Now the plugin will work like a charm! + +# List of Available Plugins + +left blank to fill, coming soon... + + +# Install Plugin in Docker +If you have some plugin which named `hello.py` and a have a `Plugin` class inside. + +You could just copy them to directory `pinry_plugins/batteries`. + +Now add config to local_settings.py + +``` +ENABLED_PLUGINS = [ + 'pinry_plugins.batteries.hello.Plugin', +] +``` + +Then, rebuild your docker image, the plugin will work +if no further python dependencies required.