Much of the manual editing described in Chapters Chapter 6, Chapter 7, and Chapter 8 can be automated with special scripts and templates being developed in the Mozilla source tree's tools/wizards section (these files are referred to collectively as the XULKit and can be found at http://www.hacksrus.com/~ginda/xulkit/doc/).
These tools help you develop your Mozilla application by generating as much of the basic content, structure, and packaging of an application as possible, leaving you free to work only on the aspects of your application that you care about. We mention XULKit first because it can make setting up new Mozilla applications a snap.
XULKit is essentially a set of two scripts: new-from-template.pl, which creates a new application framework, and makexpi.pl, which packages your application once you finish developing it.
Using these scripts, you can add content and logic to your application, restyle it, or build your application however you would like. You can also register the resulting directory with the chrome registry to see it working in your local copy of Mozilla, and when you finish developing it, the application directory is already structured in exactly the way it must be to be checked into the Mozilla source tree's extensions directory (if you want to check it into this common location for applications that become a part of Mozilla). When you want to distribute your application as described in Chapter 6, you can use the other script in the XULKit, makexpi.pl, to package your application files into a cross-platform archive that can be installed from a regular web page.
To use the new-from-template.pl script, point it at a template that you filled out with your own information. It then generates the basic application code in the appropriate subdirectory structure:
new-from-template.pl -t FILE [-o DIRECTORY] [-f[d]] [-h] [-?]
When you run the script, the XULKit creates a new top-level application directory. In this directory, the script creates the three main package directories, and it places some basic content in each one: a CSS file called mozreg.css in the skins subdirectory, a few XUL files in the content directory (including the overlay that defines a new menu item for the main browser that opens this new application), and localizable data in the mozref.dtd file in the locale subdirectory.
In addition to these files, the XULKit script creates contents.rdf files that describe each package, some Makefiles that instruct the Mozilla build process how to integrate this application into the build (which is a later step and not necessary to run the application), and an install.js file that executes the installation of this application when it appears in a XPI. (See Chapter 6 for more information about XPI, Mozilla's cross-platform installation file format.)
If you look at Example B-1 -- xul-app.tpl, which comes with the distribution of new-from-template.pl -- you can see how easy it is to fill out the basic information and create your own template.
Table B-1. Options for the new-from-template.pl script
Option |
Description |
---|---|
-d |
Recursively deletes the output directory before starting; requires the -f option. |
-f |
Forces file overwriting in the output directory. |
-h |
Displays a description of the specified template with -o. The template will not be processed. The template description is taken from the value of the template_description variable in the template file. template_descriptions provided by the main template file's template file(s) are not displayed. |
-o DIRECTORY |
Generates the template into the directory specified by DIRECTORY. If this directory already exists, new-from-template.pl will fail. This failure prevents you from accidentally overwriting an existing application. Use the -f option to continue anyway. Use -fd to force DIRECTORY to be deleted before the template is processed. |
-t TEMPLATE |
Processes the template specified by TEMPLATE. This file is usually in the my/ sub-directory, ending in .tpl. |
-? |
Shows usage information and exits. |
makexpi.pl [-c <config-file>] [-d] [-r <revision>] [-?]
perl makexpi.pl -c ~/appdev/MyApp/makexpi.conf -r 0.9.9
Table B-2 lists the options that are recognized by makexpi.pl.
Table B-2. Options for the makexpi.pl script
Options |
Description |
---|---|
-c FILE |
Specifies the configuration file to use. |
-d |
Doesn't remake the JAR, but packages the existing contents of the chrome/ directory as an XPI. |
-r REVISION |
Specifies the value of the ${revision} variable. This specification overrides any value specified in the configuration file and defaults to "0.01". Typically, this number is used in the install.js script and as part of the XPI filename. |
-? |
Shows usage information and exits. |
When you run the script against the configuration file, you end up with two separate pieces -- the XPI in which your application and its installation script are stored and a web page that you can post on a server to guide the XPI's installation. As described in Chapter 6, the web page interacts with the XPI's install.js to install and register your application in Mozilla. If you start your application with the new-from-template.pl script, then a template-processed version of install.js that works with your application is included as templates/xpi/install.js as part of the XULKit package.
Fill out a new-from-template.pl template with your application information.
Run the new-from-template.pl script to generate the application directory.
Register your application in flat mode: as a directory in your local copy of Mozilla.
Develop your application: the XUL content, the CSS, the application code in JS, etc.
Run makexpi.pl against your working application to create an installable package.
Put the XPI and the web page up on a server to create an install for your application.