Fork me on GitHub

Adding New Gadget Specs

The whole point of the OpenSocial Explorer is to provide sample gadgets for developers to learn how to build OpenSocial gadgets, so adding new gadget specs will be a common operation. All of the gadget specs live in the gadget-specs module and are packaged into a Jar file. Each spec in this module has its own folder containing all the resources for that sample gadget. In addition specs may be grouped into categories by creating sub-directories.

The simplest gadget spec will have at least two files, a gadget XML file and then a file called spec.json. The XML file is the actual gadget XML. The spec.json file is a file we use to identify all the resources for a given gadget spec. The spec.json file must have a JSON object containing the following properties.

  • title: A string that is a title for the sample. It will be used in the spec navigator in the OpenSocial Explorer.
  • gadget: A string that is the name of the gadget XML file. This should include the file extension, which is always .xml. For example "myGadget.xml".
  • htmlFiles: An array of strings that point to HTML files references by the gadget. This is an optional parameter. For example ["example1.html", "example2.html"].
  • jsFiles: An array of strings that point to JavaScript files referenced by the gadget or any of the HTML files. This is an optional parameter. For example ["example.js", "example2.js"].
  • cssFiles: An array of strings that point to CSS files referenced by the gadget or any of the HTML files. This is an optional parameter. For example ["example1.css", "example2.css"].
  • isDefault: A boolean indicating whether the gadget is the default gadget to be shown when the OpenSocial Explorer is opened. There should only be one spec that has the value set to true.

Here is a sample spec.json

{
  "isDefault" : true,
  "gadget" : "gadget.xml",
  "htmlFiles" : ["welcome.html"],
  "cssFiles" : ["welcome.css"],
  "jsFiles" : ["welcome.js"],
  "title" : "Welcome"
}

When a new spec is added you need to add a reference to it in specs.txt file, so we know which specs should be loaded.