Plugins - Content Integration

From bemoko developer wiki

(Redirected from Plugins)
Jump to: navigation, search

Groovy

The out-of-the-box plugin language in bemkoLive is Groovy. Groovy is wildly acclaimed agile scripting language based on Java. It is great for creating light-weight data access scripts that are easy to read and require minimal coding.

Creating a Plugin

The simplest way to create a plugin is with the content-sources/source construction in the site configuration file, e.g

<content-sources>
  <source name="me" plugin="MyPlugin"/>	
</content-sources>

This tells the platform to load the plugin named "MyPlugin.groovy" in the plugins directory of the site and make it available to the templating under the name ${content.me}

A very simple plugin would like:

class MyPlugin {
  def value="hello"
}

This would result in the template variable ${content.me.value} being rendered as "hello".

Plugin lifecycle

Initialise

When a plugin is created the initialise method is executed on the plugin with the initialisation parameters available for processing, for example the following example sets the class level variable value to the value of myparam from the initialisation parameters:

class MyPlugin {
  def value
  void initialise(Map parameters) {
    myvar = parameters.myparam
  }
}

Execute

For every page request for which the plugin is available for the execute method of the plugin is executed. The intent parameters are passed into the plugin execution as a Map and available to processing logic, for example:

  def count
  void execute(Map parameters) {
    count++
    switch (parameters.action) {
      case "up":
        // going up
        break
      case "down":
        // going down
        break
      default:
        // don't know where I'm going    
    }
  }

Further Reading

Example plugins can also be found in the bemoko opensource plugin repository. These plugins provide working examples for rss, twitter and wordpress integration which you can drop into your site.