Labs/Bespin/DesignDocs/PluginAPI: Difference between revisions

No edit summary
Line 76: Line 76:
         // referred to by name
         // referred to by name
         name: "luaHighlighter",
         name: "luaHighlighter",
   
 
         // up to the first "." would be used as the short description. Everything
         // up to the first "." would be used as the short description. Everything
         // else is viewed in a long description context.
         // else is viewed in a long description context.
         description: "Syntax highlighter for the Lua programming language.",
         description: "Syntax highlighter for the Lua programming language.",
   
 
         // version numbers will be good for automatic updates.
         // version numbers will be good for automatic updates.
         version: "1.0",
         version: "1.0",
   
 
         // core parts of Bespin (and even plugins) can query for metadata
         // core parts of Bespin (and even plugins) can query for metadata
         // and request that a plugin is loaded. In this case,
         // and request that a plugin is loaded. In this case,
Line 90: Line 90:
         // If it's a lua file, it will see that this plugin can handle
         // If it's a lua file, it will see that this plugin can handle
         // lua.
         // lua.
         entryPoints: {
         provides: [
             "bespin.syntax.simple": {
             ["bespin.syntax.simple", {
                 extensions: ["lua"]
                 extensions: ["lua"],
             }
                // in the single file version of a plugin, you just refer to the
         }
                // functions in the plugin itself
                load: "luaHighlighter"
             ]
         ],
        subscribes: [
            ["file:savefile", "savehandler"]
        ]
     }
     }
      
      
    // The activate function is called when this plugin is loaded.
     exports.luaHighlighter = function() {
    // It is responsible for setting up even listeners.
         // return a lua highlighter instance
     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
        })
     }
     }
      
      
    // The deactivate function is optional and provides a way
     exports.savehandler = function(event) {
    // for the plugin to cleanup after itself.
         // do whatever it is we do on save
     exports.deactivate = function() {
         // 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.
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.
canmove, Confirmed users, Bureaucrats and Sysops emeriti
1,093

edits