From f668f2981a431256926fde42b873e85b0e812fa6 Mon Sep 17 00:00:00 2001 From: JC Brand Date: Sun, 3 Sep 2017 22:10:45 +0200 Subject: [PATCH] Update plugin example with code from the yeoman generator Also improve the introductory text. --- docs/source/plugin_development.rst | 295 +++++++++++++++-------------- 1 file changed, 158 insertions(+), 137 deletions(-) diff --git a/docs/source/plugin_development.rst b/docs/source/plugin_development.rst index df4a5cf6e..a058db2b1 100644 --- a/docs/source/plugin_development.rst +++ b/docs/source/plugin_development.rst @@ -14,24 +14,36 @@ Writing a plugin Introduction ------------ -Developers are able to extend and override the objects, functions and the -Backbone models and views that make up converse.js by means of writing plugins. +Converse.js is exposes a plugin architecture which allows developers to modify +and extend its functionality. + +Specifically, plugins enable developers to extend and override existing objects, +functions and `Backbone `_ models and views that make up +Converse.js, and also give them the ability to write new models and views. + +Various core features of Converse.js, such as +`Message Archive Management `_ and +`Group chats `_ are implemented +as plugins, thereby showing their power and flexibility. Converse.js uses `pluggable.js `_ as its plugin architecture. -To understand how this plugin architecture works, please read the +To more deeply understand how this plugin architecture works, please read the `pluggable.js documentation `_ and to understand its inner workins, please refer to the `annotated source code `_. -Below you'll find an example plugin. Because convers.js is only Javascript, -HTML and CSS (with no backend code required like PHP, Python or Ruby) it runs -fine in JSFiddle. +Playing with a Converse.js plugin in JSFiddle +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -Here's an Fiddle with a plugin that calls `alert` when the plugin gets -initialized and when a message gets rendered: https://jsfiddle.net/4drfaok0/15/ +Because Converse.js consists only of JavaScript, HTML and CSS (with no backend +code required like PHP, Python or Ruby) it runs fine in JSFiddle. +Here's an Fiddle with a Converse.js plugin that calls `alert` once it gets +initialized and also when a chat message gets rendered: + +https://jsfiddle.net/4drfaok0/15/ Registering a plugin -------------------- @@ -231,148 +243,157 @@ A full example plugin .. code-block:: javascript - (function (root, factory) { - if (typeof define === 'function' && define.amd) { - // AMD. Register as a module called "myplugin" - define("myplugin", ["converse"], factory); - } else { - // Browser globals. If you're not using a module loader such as require.js, - // then this line below executes. Make sure that your plugin's