canmove, Confirmed users, Bureaucrats and Sysops emeriti
1,093
edits
No edit summary |
No edit summary |
||
| Line 54: | Line 54: | ||
Create new settings | Create new settings | ||
== Other useful features == | |||
* Be able to use a Bespin project as a plugin (while working on plugins). Possibly even be able to use a directory within a Bespin project. | |||
* Be able to reload plugins that you're working on | |||
* Plugins should be loaded lazily to improve startup time. For example, a plugin that provides a syntax highlighter shouldn't be loaded until that highlighter is needed. | |||
== Core Plugin API == | == Core Plugin API == | ||
Here we will talk about the first goal, the core plugin API itself | Here we will talk about the first goal, the core plugin API itself | ||
=== A one-file plugin === | |||
Let's start with an example: | |||
// Typically, we'll start with some metadata. This metadata must be valid JSON | |||
// (no functions in the metadata). | |||
exports.info = { | |||
// Plugins all have a name that represents the namespace of the plugin | |||
// This allows the plugin system to locate any functions that are | |||
// referred to by name | |||
name: "luaHighlighter", | |||
// up to the first "." would be used as the short description. Everything | |||
// else is viewed in a long description context. | |||
description: "Syntax highlighter for the Lua programming language.", | |||
// version numbers will be good for automatic updates. | |||
version: "1.0", | |||
// core parts of Bespin (and even plugins) can query for metadata | |||
// and request that a plugin is loaded. In this case, | |||
// Bespin's simple syntax highlighting engine will look for plugins | |||
// when it opens a file type it doesn't know how to handle. | |||
// If it's a lua file, it will see that this plugin can handle | |||
// lua. | |||
"bespin.syntax.simple": { | |||
extensions: ["lua"] | |||
} | |||
} | |||
// The activate function is called when this plugin is loaded. | |||
// It is responsible for setting up even listeners. | |||
exports.activate = function() { | |||
// note the use of "subscribe" instead of "bespin.subscribe". | |||
// in a plugin context, all subscriptions are handled for | |||
// you automatically. If the plugin needs to be reloaded, | |||
// all event handlers will automatically be unsubscribed. | |||
subscribe("bespin:syntax:simple:highlightBlock", function(block) { | |||
// do something | |||
}) | |||
} | |||
Plugin modules are implemented not as Dojo modules, but rather as [https://wiki.mozilla.org/ServerJS/Modules/SecurableModules ServerJS Securable Modules]. This would allow seamless interop for plugins that have both client and server side JS components. | |||
=== Wordpress-like === | === Wordpress-like === | ||
(TODO: ideas in this section to be shuffled around in light of the new direction in the previous section.) | |||
What if we have a new directory, BespinSettings/plugins which is where your plugins go. | What if we have a new directory, BespinSettings/plugins which is where your plugins go. | ||