Plugins

On this page, we will discuss the implementation of a plugin API, which should be included in version 0.7.

Everything on this page is still preliminary work. It's a gathering of ideas, nothing of this is finally decided yet.

Hooks for plugins

The native Chameleon code will provide ways for plugins to hook into the main app in the following ways:

  • Filters provide a way for plugins to modify a value requested or returned by a function. This will be used mainly in the models.
  • Hooks provide a way for plugins to add code to a function, at the start or the end of the function, or before or after a code chunk. This will probably mostly be used in the controllers. (? This could be used on any function that does processing, in the models too.) (Rails' filters and the alias_method_chain function already provide similar functionality.)
  • Widgets provide a way for plugins to add code and values to the template. This will mainly be used in the templates. (Although template writers would still have to add the hooks to their templates.)

(? What about the Liquid drops, tags, filters… Should plugins be able to modify those too?)

Plugin location and structure

Chameleon plugins are put in the directory vendor/chameleon_plugins. Each plugin gets its own directory, with its own init.rb, possibly a README and LICENSE file, a lib subdirectory and possibly also test, examples and/or doc subdirectories.

So:

  • vendor/chameleon_plugins/ - All Chameleon plugins
    • example_plugin/ - A plugin
      • doc/ (optional) - Contains documentation for the plugin
      • examples/ (optional) - Contains some examples of the plugin in use
      • lib/ - Contains the actual code
      • test/ (optional) - Contains test code for the plugin
      • init.rb - The file that Chameleon will call when loading the plugin, which calls the needed code in the lib subdirectory
      • README (optional) - A file on how to get started with the plugin
      • LICENSE, INSTALL, CHANGELOG, VERSION (optional) - Other files you'd like to include

(? How does this integrate with Rails plugins? Rails already has the code to load all plugins, they have the ./script/generate plugin plugin_name command, and so on… Can we use this code for Chameleon too. Can plugins then be in vendor/chameleon_plugins? Should they be in vendor/chameleon_plugins in the first place, can't they be in vendor/plugins too, next to the Rails plugin?)

page_revision: 12, last_edited: 1197751036|%e %b %Y, %H:%M %Z (%O ago)
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution 2.5 License.