initial add of template processor

This commit is contained in:
rginda%netscape.com 2001-04-18 21:45:10 +00:00
Родитель 623af164d2
Коммит 138e2d8e2c
30 изменённых файлов: 1029 добавлений и 54 удалений

Просмотреть файл

@ -1,34 +1,14 @@
#
# The contents of this file are subject to the Mozilla Public License
# Version 1.1 (the "License"); you may not use this file except in
# compliance with the License. You may obtain a copy of the License at
# http://www.mozilla.org/MPL/
#
# Software distributed under the License is distributed on an "AS IS" basis,
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
# for the specific language governing rights and limitations under the
# License.
#
# The Original Code is mozilla.org code
#
# The Initial Developer of the Original Code is Netscape
# Communications Corporation. Portions created by Netscape are
# Copyright (C) 1998 Netscape Communications Corporation. All
# Rights Reserved.
#
# Contributor(s):
# Robert Ginda, rginda@nestcape.com, original author
#
#
${license_mak}
DEPTH = ../..
DEPTH = ${depth_0_nix}
topsrcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@
include $(DEPTH)/config/autoconf.mk
DIRS = resources
DIRS = resources
include $(topsrcdir)/config/rules.mk

Просмотреть файл

@ -1,35 +1,9 @@
#
# The contents of this file are subject to the Mozilla Public License
# Version 1.1 (the "License"); you may not use this file except in
# compliance with the License. You may obtain a copy of the License at
# http://www.mozilla.org/MPL/
#
# Software distributed under the License is distributed on an "AS IS" basis,
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
# for the specific language governing rights and limitations under the
# License.
#
# The Original Code is mozilla.org code
#
# The Initial Developer of the Original Code is Netscape
# Communications Corporation. Portions created by Netscape are
# Copyright (C) 1998 Netscape Communications Corporation. All
# Rights Reserved.
#
# Contributor(s):
# Robert Ginda, rginda@nestcape.com, original author
#
#
${license_mak}
DEPTH = ..\..
topsrcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@
DEPTH = ${depth_0_win}
include <$(DEPTH)\config\autoconf.mak>
include <$(DEPTH)\config\config.mak>
DIRS = resources
INSTALLROOT = $(DIST)\bin\chrome\packages\cview\cview
include <$(topsrcdir)\config\rules.mak>
include <$(DEPTH)\config\rules.mak>

Просмотреть файл

Просмотреть файл

Просмотреть файл

Просмотреть файл

Просмотреть файл

Просмотреть файл

Просмотреть файл

Просмотреть файл

Просмотреть файл

Просмотреть файл

@ -0,0 +1,208 @@
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
<html>
<head>
<title>new-from-template.pl</title>
</head>
<body bgcolor="white">
<h1 align="right">new-from-template.pl</h1>
<dl>
<dt><b>NAME</b></dt>
<dd>
<b>new-from-template.pl</b> - Generates new code from templatized sources and
variable definition files.
<br>
<br>
<dt><b>SYNOPSIS</b></dt>
<dd>
<table>
<tr>
<td align="right" valign="top">
<code>
<b>new-from-template.pl</b>
</code>
</td>
<td>
<code>
-t FILE [-o DIRECTORY] [-f[d]] [-h] [-?]
</code>
</td>
</tr>
</table>
<br>
<br>
<dt><b>DESCRIPTION</b></dt>
<dd>
<b>new-from-template.pl</b> is used to generate new code from templatized source
files. <b>new-from-template.pl</b> takes a file containing a list of variables
as input, combines those variable values with source files containing
variable references, and produces a new set source files with the
variable references replaced by their values.<br>
<br>
Templatized source files can be found in the
<tt>templates/&lt;template-name&gt;</tt> directory. These files contain
a skeletal version of the application that the template is intended
to produce. Variables in the format <code>${variable-name}</code> can
be used in these files to refer to values that should be filled out by
<b>new-from-template.pl</b> when the template is processed<br>
<br>
Files containing variable lists usually have the extension
<tt>.tpl</tt>, although this is not an actual requirement. These
<tt>.tpl</tt> files contain lists of variables in the format
<code>variable-name = variable-value</code>. The
<code>variable-value</code> may refer to the value of other variables
by using the syntax <code>${other-variable-name}</code>. Note that
this is the same way a templatized source file would refer to a
variable. The order of declaration is not significant, as
<b>new-from-template.pl</b> loads the entire list of variables before it
it begins dereferencing them.
<br>
In addition to setting variables to plain text, and values derived from
other variables, there are two special functions can be used to set the
value of a variable. These functions must appear alone in the variable
definition in order to take effect.
<center>
<table border="1" width="85%">
<tr>
<th>Function</th><th>Description</th>
</tr>
<tr>
<td>
<code>file("&lt;file-name&gt;")</code>
</td>
<td>
The <code>file</code> function is used to set the variable to
the contents of another file.
</td>
</tr>
<tr>
<td>
<code>eval("&lt;perl-code&gt;")</code>
</td>
<td>
The <code>eval</code> function is used to set the variable to
the result of executing arbitrary perl code.
</td>
</tr>
</table>
</center>
<br>
<tt>.tpl</tt> files can include other <tt>.tpl</tt> files via
<code>include "&lt;filename.tpl&gt;"</code>. This will include
<tt>filename.tpl</tt> as if it were part of the <tt>.tpl</tt> at the
position of the <code>include</code>. If <tt>filename.tpl</tt> declares
any variables that had been set before the <code>include</code>,
they will be overridden. Any variables you define after the
<code>include</code> will remain intact.<br>
<br>
<b>new-from-template.pl</b> defines a variable called
<code>top_wizard_dir</code> that can be used to locate files relative to
the <b>new-from-template.pl</b> script. Any file references that are not
explicitly relative to this variable will be relative to the user's
working directory.<br>
<br>
To rename templatized source file names during template processing, use
<code>rename ("&lt;templatized-source-name&gt;", "&lt;target-source-name&gt;")</code>.
When <b>new-from-template.pl</b> process the template, any filename matching
<code>templatized-source-name</code> will be renamed to
<code>target-source-name</code>. This has the side effect of setting
the value of the <code>filename:templatized-source-name</code> variable
to <code>target-source-name</code>.<br>
<br>
Any undefined
variable that matches the pattern <code>filename:*</code> will return
the value following the <code>filename:</code> as its default value.
This allows you to refer to <code>filename:</code> variables in your
templatized source files, instead of the actual filenames.<br>
<br>
<dt><b>OPTIONS</b></dt>
<dd>
<dl>
<dt><b>-d</b></dt>
<dd>
Recursively delete the output directory before starting, requires
the <tt>-f</tt> option.
<br>
<br>
<dt><b>-f</b></dt>
<dd>
Force overwriting of files in the output directory.
<br>
<br>
<dt><b>-h</b></dt>
<dd>
Display a description of the template specified with <tt>-o</tt>.
The Template will not be processed. The template description is
taken from the value of the variable
<code>template_description</code> in the template file.
<code>template_description</code>s provided by template file(s)
<code>include</code>ed by the main template file will <b>not</b>
be displayed.
<br>
<br>
<dt><b>-o DIRECTORY</b></dt>
<dd>
Generate the template into the directory specified by DIRECTORY. If
this directory exists already, <b>new-from-template.pl</b> will fail. This
is to prevent you from accidentally overwriting an existing
application. Use the <tt>-f</tt> option to continue anyway. Use
<tt>-fd</tt> to force DIRECTORY to be deleted before the template is
processed.
<br>
<br>
<dt><b>-t TEMPLATE</b></dt>
<dd>
Process the template specified by TEMPLATE. This is usually a
file in the <tt>my/</tt> sub-directory, ending in <tt>.tpl</tt>.
<br>
<br>
<dt><b>-?</b></dt>
<dd>
Show usage information and exit.
<br>
<br>
</dl>
<dt><b>SEE ALSO</b></dt>
<dd>
<a href="http://lxr.mozilla.org/mozilla/source/tools/wizards/new-from-template.pl">new-from-template.pl</a>,
<a href="http://lxr.mozilla.org/mozilla/source/tools/wizards/templates/xul-app.tpl">xul-app.tpl</a>,
<a href="http://lxr.mozilla.org/mozilla/source/tools/wizards/my/sample.xpcom-component.tpl">sample.xpcom-component.tpl</a>,
<a href="http://lxr.mozilla.org/mozilla/source/tools/wizards/templates/xpcom-component.tpl">xpcom-component.tpl</a>,
<a href="http://lxr.mozilla.org/mozilla/source/tools/wizards/my/sample.xpcom-component.tpl">sample.xpcom-component.tpl</a>
<br>
<br>
<dt><b>REQUIREMENTS</b></dt>
<dd>
<b>new-from-template.pl</b> requires the <b>Getopt::Std</b> perl package, standard
in most perl distributions.
<br>
<br>
<dt><b>EXAMPLES</b></dt>
<dd>
<p>
<code>perl new-from-template.pl -t templates/xul-app.tpl -h</code><br>
Shows a description of the XUL App template.
<p>
<code>perl new-from-template.pl -t my/sample.xul-app.tpl</code><br>
Generates a new XUL Application from the variables defined by
<tt>sample.xul-app.tpl</tt> into the default output directory,
<tt>nft-results</tt>.
<p>
<code>perl new-from-template.pl -t my/sample.xpcom-component.tpl
-o ~/src/cvs/mozilla/extensions/jsdebugger/</code><br>
Generates a new XPCOM component from the variables defined by
<tt>sample.xpcom-component.tpl</tt> into the directory
<tt>~/src/cvs/mozilla/extensions/jsdebugger/</tt>
</dl>
<hr>
<address><a href="mailto:rginda@netscape.com">Robert Ginda</a></address>
<!-- Created: Thu Dec 2 19:08:05 PST 1999 -->
<!-- hhmts start -->
Last modified: Wed Apr 11 19:04:21 PDT 2001
<!-- hhmts end -->
</body>
</html>

Просмотреть файл

@ -0,0 +1,7 @@
# include default values
include "${top_wizard_dir}templates/xpcom-component.tpl"
component_name = SampleComponent
implementation_guid = c6793b0c-1dd1-11b2-a246-92bf95c9d097
interface_name = tstISampleComponent
interface_guid = d03ea960-1dd1-11b2-9682-81ecad6a042a

Просмотреть файл

@ -0,0 +1,25 @@
# load default template for a XUL app
include "${top_wizard_dir}templates/xul-app.tpl"
# short app name (can not contain spaces.)
# until http://bugzilla.mozilla.org/show_bug.cgi?id=75670 is fixed, this needs
# to be all lowercase.
app_name_short=xulsample
# long app name (spaces are OK.)
app_name_long=Sample XUL Application (generated from sample.xul-app.tpl)
# name as it should appear in the menu
app_name_menu=Sample XUL App
# version to tell the .xpi installer
app_version=1.0
# author, used in various chrome and app registration calls
app_author=mozilla.org
# size of the package when installed, in kilobytes.
# this number is used by the install.js script to check for enough disk space
# before the .xpi is installed. You can just guess for now, or put 1, and fix it
# in install.js before you make your .xpi file.
install_size_kilobytes=1

Просмотреть файл

@ -0,0 +1,398 @@
#!/usr/bin/perl
#
# The contents of this file are subject to the Netscape Public
# License Version 1.1 (the "License"); you may not use this file
# except in compliance with the License. You may obtain a copy of
# the License at http://www.mozilla.org/NPL/
#
# Software distributed under the License is distributed on an "AS
# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express oqr
# implied. See the License for the specific language governing
# rights and limitations under the License.
#
# The Original Code is mozilla template processor
#
# The Initial Developer of the Original Code is Netscape
# Communications Corporation. Portions created by Netscape are
# Copyright (C) 1997-1999 Netscape Communications Corporation. All
# Rights Reserved.
#
# Alternatively, the contents of this file may be used under the
# terms of the GNU Public License (the "GPL"), in which case the
# provisions of the GPL are applicable instead of those above.
# If you wish to allow use of your version of this file only
# under the terms of the GPL and not to allow others to use your
# version of this file under the NPL, indicate your decision by
# deleting the provisions above and replace them with the notice
# and other provisions required by the GPL. If you do not delete
# the provisions above, a recipient may use your version of this
# file under either the NPL or the GPL.
#
# Contributers:
# Robert Ginda <rginda@netscape.com>
#
use strict;
use FileHandle;
use Getopt::Std;
my $pnm = $0;
my $description_var = "template_description";
my %opts;
getopts ("t:o:fdh?", \%opts);
if ($opts{"?"}) {
usage();
}
my $vars_file = $opts{"t"} || usage();
my $out_dir = $opts{"o"} || "nft-results/";
if (!($out_dir =~ /\/$/)) {
$out_dir = $out_dir . "/";
}
my @dereferences_in_progress = ();
my %vars;
$vars{"top_wizard_dir"} = {
value => "./",
processed => 1
};
if ($opts{"h"}) {
load_vars_file($vars_file);
show_description();
exit 0;
}
if (-d $out_dir) {
if ($opts{"f"}) {
if ($opts{"d"}) {
`rm -rf $out_dir`;
}
} elsif ($opts{"d"}) {
die "$pnm: bad option: -d (delete output directory, recusive) can " .
"only be used with -f (force.)\n";
} else {
die "$pnm: output directory ($out_dir) exists: use the -f (force) " .
"option to continue anyway. Files in the output directory with the " .
"same name as template files will be overwritten.\n";
}
}
load_vars_file($vars_file);
process_all_vars ();
process_template_dir (get_var("template_dir", $pnm), $out_dir);
exit 0;
sub usage () {
print STDERR
"Usage: $pnm -t <template-file> [-o <output-dir>]\n" .
" [-f[d]] [-h] [-?]\n" .
"\n" .
" -t FILE The template to use.\n" .
" -o DIRECTORY The directory to write results to.\n" .
" -f Force overwriting of files in the output directory.\n" .
" -d Recursively delete the output directory before starting\n" .
" (requires -f.)\n" .
" -h Display description of the selected template. Template\n" .
" will not be processed.\n" .
" -? Display this message.\n";
exit 1;
}
sub show_description () {
my $desc = get_var_with_default ($description_var);
if ($desc) {
print "Description of $vars_file:\n\n$desc\n\n";
} else {
print "Template file $vars_file contains no description.\n";
}
}
sub process_template_dir {
my ($from_dir, $to_dir) = @_;
print "Processing template files $from_dir -> $to_dir\n";
if (!( -d $to_dir)) {
print "mkdir $to_dir\n";
mkdir $to_dir;
}
my @dirs = get_subdirs($from_dir);
my $dir;
foreach $dir (@dirs) {
process_template_dir ("$from_dir$dir/", "$to_dir$dir/");
}
my @files = get_files($from_dir);
my $file;
foreach $file (@files) {
my $to_file = get_var_with_default ("filename:$file", $file,
"rename target for file $file");
open (TO, ">$to_dir$to_file") || die "Couldn't open $to_dir$to_file\n";
print TO process_file ("$from_dir$file");
close TO;
}
}
sub load_vars_file {
my ($filename) = @_;
my $fh = new FileHandle;
$fh->open ($filename) || die ("Couldn't open vars file $filename\n");
my $line;
my $line_no = 1;
my $continue_line;
my $var_name = "";
my $var_value = "";
while ($line = <$fh>) {
chomp($line);
if ($continue_line) {
# continuation of previous line
$line =~ /^(.*)(\\)?$/;
$var_value .= $1;
$continue_line = $2 ? 1 : 0;
} elsif ($line =~ /^\s*([\w\:\-]+)\s*=\s*(.*)$/) {
# var=value line
$var_name = $1;
$var_value = $2;
if ($var_value =~ /\\$/) {
$continue_line = 1;
$var_value .= "$var_value\n";
} else {
$continue_line = 0;
}
} elsif ($line =~ /^include\s*\"(.*?)\"\s*$/i) {
# include line
load_vars_file(process_string($1, "$filename, line $line_no"));
} elsif ($line =~ /^rename\s*\(\s*\"(.*?)\"\s*,\s*\"(.*?)\"\s*\)\s*$/i) {
# rename line
$var_name = "filename:$1";
$var_value = $2;
} elsif ($line =~ /^(\s*\#.*)?$/) {
# comment or blank line, ignore
$var_name = "";
} else {
die ("Huh?\nFile: $filename, Line: $line_no\n$line\n");
}
if ($var_name && !$continue_line) {
if ($var_name ne $description_var ||
$filename eq $vars_file) {
# don't set the description unless it's comming from the
# main template file.
$vars{$var_name} = {
value => $var_value,
processed => 0
};
}
}
++$line_no;
}
close ($fh);
}
sub get_var_with_default {
my ($var_name, $default, $source) = @_;
my $c = $vars{$var_name};
#print "getting var $var_name\n";
if (!$c) {
return $default;
}
if (!$c->{"processed"}) {
if (grep(/^$var_name$/, @dereferences_in_progress)) {
die "Circular reference to $var_name while processing $source\n";
}
push (@dereferences_in_progress, $var_name);
my $val = $c->{"value"};
if ($val =~ /^\s*file\s*\(\s*\"(.*)\"\s*\)\s*$/i) {
# get value from a file
#print "loading $1\n";
$c->{"value"} = process_file (process_string($1, $source));
} elsif ($val =~ /^eval\s*\(\s*\"(.*)\"\s*\)\s*$/i) {
# get value from a perl eval() call
my $eval_str = process_string ($1, $source);
$c->{"value"} = eval ($eval_str);
} else {
$c->{"value"} = process_string ($val, "variable $var_name");
}
$c->{"processed"} = 1;
if (pop(@dereferences_in_progress) ne $var_name) {
die "Internal error: dereference stack mismatch.";
}
}
return $c->{"value"};
}
sub get_var {
my ($var_name, $source) = @_;
my $c = $vars{$var_name};
my $default;
#print "getting var $var_name\n";
if (!$c) {
if ($var_name =~ /filename:(.+)/i) {
$default = $1;
} else {
die ("Undefined variable $var_name referenced in $source\n");
}
}
return get_var_with_default ($var_name, $default, $source);
}
sub process_file {
my ($file) = @_;
#print "processing $file\n";
open (FROM, "$file") || die "Couldn't open $file\n";
my @contents = <FROM>;
my $results = process_string (join ("", @contents), "file $file");
close FROM;
return $results;
}
sub process_string {
my ($str, $source) = @_;
my @lines = split(/\n/, $str, -1);
my $i;
for $i (0 .. $#lines) {
@lines[$i] = process_single_line_string ($lines[$i],
"$source, line " . ($i + 1));
}
return join ("\n", @lines);
}
sub process_single_line_string {
my ($str, $source) = @_;
my $start_pos = index ($str, '${');
if ($start_pos == -1) {
return $str;
}
my $end_pos = -1;
my $str_len = length ($str);
#print "processing string '$str'\n";
my $result_str = substr($str, 0, $start_pos);
while ($start_pos != -1 && $start_pos != $str_len) {
$start_pos += 2;
$end_pos = index ($str, "}", $start_pos);
if ($end_pos == -1) {
$end_pos = $start_pos;
} else {
my $var_name = substr ($str, $start_pos, $end_pos - $start_pos);
$result_str .= get_var ($var_name, $source);
}
$start_pos = index ($str, '${', $end_pos);
if ($start_pos == -1) {
$start_pos = $str_len;
}
$result_str .= substr ($str, $end_pos + 1, $start_pos - $end_pos - 1);
}
return $result_str;
}
sub process_all_vars {
# calling get_var on all variables causes them all to be dereferenced.
# useful for flushing out undefined variables.
my $var_name;
foreach $var_name (keys(%vars)) {
my $var_value = get_var ($var_name);
#print "var name $var_name is $var_value\n";
}
}
#
# given a uuid, return it in a format suitable for #define-ing
#
sub define_guid {
my ($uuid) = @_;
$uuid =~ /([a-f\d]+)-([a-f\d]+)-([a-f\d]+)-([a-f\d]+)-([a-f\d]+)/i;
my $uuid_out = "{ /* $uuid */ \\\n" .
" 0x$1, \\\n" .
" 0x$2, \\\n" .
" 0x$3, \\\n";
my @rest = ( "0x" . substr ($4, 0, 2), "0x" . substr ($4, 2, 2) );
my $i = 0;
while ($i < length ($5)) {
push (@rest, "0x" . substr ($5, $i, 2));
$i += 2;
}
my $rv = $uuid_out;
$rv .= " {" . join (", ", @rest) . "} \\\n";
$rv .= "}\n";
return $rv;
}
#
# given a directory, return an array of all the files that are in it.
#
sub get_files {
my ($subdir) = @_;
my (@file_array, @subdir_files);
opendir (SUBDIR, $subdir) || die ("couldn't open directory $subdir: $!");
@subdir_files = readdir(SUBDIR);
closedir(SUBDIR);
foreach (@subdir_files) {
my $file = $_;
if (!($file =~ /[\#~]$/) && -f "$subdir$file") {
$file_array[$#file_array+1] = $file;
}
}
return @file_array;
}
#
# given a directory, return an array of all subdirectories
#
sub get_subdirs {
my ($dir) = @_;
my @subdirs;
if (!($dir =~ /\/$/)) {
$dir = $dir . "/";
}
opendir (DIR, $dir) || die ("couldn't open directory $dir: $!");
my @testdir_contents = readdir(DIR);
closedir(DIR);
foreach (@testdir_contents) {
if ((-d ($dir . $_)) && ($_ ne 'CVS') && (!($_ =~ /^\..*/))) {
@subdirs[$#subdirs + 1] = $_;
}
}
return @subdirs;
}

Просмотреть файл

@ -0,0 +1,4 @@
This template contains some default values used by other templates. Used alone,
it will do nothing (actually, you'll get an error.) If you'd like to change the
license type that other templates use by default, this is the place to make the
change.

Просмотреть файл

@ -0,0 +1,23 @@
# default values for use by other templates.
# description of this template
template_description = file("${top_wizard_dir}templates/default.description")
# license information
license_original_code = mozilla.org code
license_author_short = Netscape
license_author_long = Netscape Communications Corporation
license_copyright = Copyright (C) 1998 Netscape Communications Corporation.
license_contrib =
# type of license
license_type = MPL-GPL
# license files
license_dir = ${top_wizard_dir}templates/licenses/${license_type}
license_mak = file("${license_dir}/lic.mak")
license_pl = file("${license_dir}/lic.pl")
license_c = file("${license_dir}/lic.c")
license_cpp = file("${license_dir}/lic.cpp")
license_xml = file("${license_dir}/lic.xml")
license_css = file("${license_dir}/lic.css")

Просмотреть файл

@ -0,0 +1,37 @@
This template creates a basic XPCOM component, including a new interface, and
an implementation of that interface.
The new interface will have only one method, named |method|, which takes no
parameters, and returns no result. When called, a message will be printed to
STDOUT.
This template creates the makefiles required to build your XPCOM component from
within the mozilla source tree. Unix and Windows makefiles will be created,
Mac will not. The template assumes you are going to generate the component in
mozilla/extensions/<component-name>. If you plan to place the application at
another depth in the source tree you will need to adjust the depth_0_nix,
depth_1_nix, depth_0_win, and depth_1_win variables.
The minimal variables required are:
component_name - The name of the component. By default, this will be used as the
C++ class name of the implementation, though this can be changed
by explicitly setting implementation_class_name in your
template. component_name is also used as the name of the
.cpp and .h files of your implementation, and the module and
library names.
implementation_guid - A guid to use as the class ID, without any surrounding
curly braces, but with the intermediate dashes. Exaclty
what you'd get from mozbot if you typed "/msg mozbot uuid"
on irc.mozilla.org.
ie. e0a9dd96-1dd1-11b2-8fc6-a8ccf526fe1c
interface_name - The name of the interface, with appropriate capitalization.
ie. myIMyInterface
interface_guid - A guid to use as the interface ID, same format as the
implementation_guid.
See my/sample.xpcom-component.tpl for a demonstration of how to use this
template.

Просмотреть файл

@ -0,0 +1,45 @@
# include default values
include "${top_wizard_dir}templates/default.tpl"
# location of templatized files
template_dir = ${top_wizard_dir}templates/xpcom-component/
# description of this template
template_description = file("${top_wizard_dir}templates/xpcom-component.description")
# directory depths
# if your xpcom component isn't going to end up in
# extensions/${component_name}, you'll need to adjust these depths accordingly.
depth_0_nix = ../..
depth_0_win = ..\..
depth_1_nix = ../../..
depth_1_win = ..\..\..
# variables the user's .tpl file MUST declare
required_variables = ${component_name}, ${implementation_guid}, \
${interface_name}, ${interface_guid}
# filename mappings
rename ("implementation.cpp", "${implementation_class_name}.cpp")
rename ("implementation.h", "${implementation_class_name}.h")
rename ("interface.idl", "${interface_name}.idl")
# .h file generated by the interface.idl file
interface_h_file = ${interface_name}.h
# component information
component_module_name = eval("lc('${component_name}')")
component_module_desc = ${component_name} (Generated from xpcom-component.tpl)
component_library_name = ${component_module_name}
component_required_libs = xpcom string xpconnect
# implementation information
implementation_class_name = ${component_name}
implementation_class_name_uc = eval("uc('${implementation_class_name}')")
implementation_contract_id = @mozilla.org/${component_name};1
implementation_guid_define = eval("define_guid('${implementation_guid}')")
# interface information
interface_name_uc = eval("uc('${interface_name}')")
interface_attribs = [scriptable, uuid(${interface_guid})]

Просмотреть файл

@ -0,0 +1,13 @@
${license_mak}
DEPTH = ${depth_0_nix}
topsrcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@
DIRS = idl src
include $(DEPTH)/config/autoconf.mk
include $(topsrcdir)/config/rules.mk

Просмотреть файл

@ -0,0 +1,16 @@
${license_mak}
DEPTH = ${depth_1_nix}
topsrcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@
include $(DEPTH)/config/autoconf.mk
MODULE = ${component_module_name}
XPIDLSRCS = \
${filename:interface.idl} \
$(NULL)
include $(topsrcdir)/config/rules.mk

Просмотреть файл

@ -0,0 +1,11 @@
${license_cpp}
#include "nsISupports.idl"
${interface_attribs}
interface ${interface_name} : nsISupports
{
void method ();
};

Просмотреть файл

@ -0,0 +1,13 @@
${license_mak}
DEPTH = ${depth_1_win}
include <$(DEPTH)/config/config.mak>
MODULE = ${interface_name}
XPIDLSRCS = \
${filename:interface.idl} \
$(NULL)
include <$(DEPTH)/config/rules.mk>

Просмотреть файл

@ -0,0 +1,10 @@
${license_mak}
DEPTH = ${depth_0_win}
include <$(DEPTH)\config\confif.mak>
DIRS = idl src
include <$(DEPTH)\config\rules.mak>

Просмотреть файл

@ -0,0 +1,18 @@
${license_mak}
DEPTH = ${depth_1_nix}
topsrcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@
include $(DEPTH)/config/autoconf.mk
MODULE = ${component_module_name}
LIBRARY_NAME = ${component_library_name}
IS_COMPONENT = 1
REQUIRES = ${component_required_libs}
CPPSRCS = ${filename:implementation.cpp}
include $(topsrcdir)/config/rules.mk

Просмотреть файл

@ -0,0 +1,27 @@
${license_cpp}
#include "nsIGenericFactory.h"
#include "${implementation_class_name}.h"
const char ${implementation_class_name}ContractID[] =
"${implementation_contract_id}";
NS_IMPL_THREADSAFE_ISUPPORTS1(${implementation_class_name}, ${interface_name});
NS_IMETHODIMP
${implementation_class_name}::Method (void)
{
printf ("${implementation_class_name}::method() called.\n");
return NS_OK;
}
NS_GENERIC_FACTORY_CONSTRUCTOR(${implementation_class_name});
static nsModuleComponentInfo components[] = {
{ "${component_module_desc}", ${implementation_class_name_uc}_CID,
${implementation_class_name}ContractID,
${implementation_class_name}Constructor},
};
NS_IMPL_NSGETMODULE("${component_module_desc}", components);

Просмотреть файл

@ -0,0 +1,28 @@
${license_cpp}
#ifndef ${implementation_class_name_uc}_H___
#define ${implementation_class_name_uc}_H___
#include "${interface_h_file}"
#define ${implementation_class_name_uc}_CID \
${implementation_guid_define}
class ${implementation_class_name} : public ${interface_name}
{
public:
NS_DECL_ISUPPORTS;
NS_DECL_${interface_name_uc};
${implementation_class_name}()
{
NS_INIT_ISUPPORTS();
}
virtual ~${implementation_class_name}() { }
private:
};
#endif /* ${implementation_class_name_uc}_H___ */

Просмотреть файл

@ -0,0 +1,17 @@
${license_mak}
DEPTH = ${depth_1_win}
topsrcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@
include <$(DEPTH)\config\config.mak>
MODULE = ${component_module_name}
LIBRARY_NAME = ${component_library_name}
IS_COMPONENT = 1
REQUIRES = ${component_required_libs}
CPPSRCS = ${filename:implementation.cpp}
include <$(DEPTH)\config\rules.mak>

Просмотреть файл

@ -0,0 +1,34 @@
This template will create a basic XUL application.
The application created will do the following things:
* register content, skin, and locale chrome urls
* register a XUL overlay (which will add the application to the tasks menu,
by default),
* create enough XUL, JavaScript, and DTD files to define a XUL window with
the standard menus and a quit button.
This template creates the makefiles required to build your XUL application from
within the mozilla source tree. Unix and Windows makefiles will be created,
Mac will not. The template assumes you are going to generate the application in
mozilla/extensions/<app-name>. If you plan to place the application at another
depth in the source tree you will need to adjust the depth_0_nix, depth_1_nix,
depth_0_win, and depth_1_win variables.
The XUL application created by this template will function as a single instance
application. That is, selecting the menu item for the application while it is
already running will cause the existing instance to be focused. Remove the
second argument from the toOpenWindowByType() call in your appname-overlay.js
file to allow multiple instances of the application.
The minimal variables required are:
app_name_short - A short name for this application. This name should no contain
any spaces. By default app_name_short will be used as your
chrome url prefix and filename prefix.
app_name_long - A long name for the application. This name can contain spaces.
By default this variable will be used as the name of the menu
item for the application, in chrome registration, and as the
original code section of the license comments.
See my/sample.xul-app.tpl for a demonstration of how to use this template.

Просмотреть файл

@ -0,0 +1,87 @@
# XUL application template, a simple XUL app that puts itself in the tasks
# menu, and displays a simple, single instance window.
# include default values
include "${top_wizard_dir}templates/default.tpl"
# location of templatized files
template_dir = ${top_wizard_dir}templates/xul-app/
# description of this template
template_description = file("${top_wizard_dir}templates/xul-app.description")
# variables the user's .tpl file MUST declare
required_variables = ${app_name_short}, ${app_name_long}
# directory depths
# if your xul app isn't going to end up in extensions/${app_name_short}, you'll
# need to adjust these depths accordingly.
depth_0_nix = ../..
depth_0_win = ..\..
depth_1_nix = ../../..
depth_1_win = ..\..\..
# filename mappings
rename ("app-ui.xul", "${app_name_short}.xul")
rename ("app-ui.css", "${app_name_short}.css")
rename ("app-ui.dtd", "${app_name_short}.dtd")
rename ("app-ui.js", "${app_name_short}.js")
rename ("app-static.js", "${app_name_short}-static.js")
rename ("app-handlers.js", "${app_name_short}-handlers.js")
rename ("app-utils.js", "${app_name_short}-utils.js")
rename ("app-overlay.xul", "${app_name_short}-overlay.xul")
rename ("app-overlay.css", "${app_name_short}-overlay.css")
rename ("app-overlay.dtd", "${app_name_short}-overlay.dtd")
rename ("app-overlay.js", "${app_name_short}-overlay.js")
# name of the jar file to create
jar_file_name = ${app_name_short}.jar
# name to use in the menu item
app_name_menu = ${app_name_long}
# original code portion of the license
license_original_code = ${app_name_long}
# skin that this package provides
skin_name_short = modern
skin_name_long = Modern
skin_version = 1.0
# locale that this package provides
locale_name_short = en-US
locale_name_long = English(US)
locale_preview_url = http://www.mozilla.org/locales/en-US.gif
# places to register chrome:// url types
content_reg_dir = content/${app_name_short}/
locale_reg_dir = locale/${locale_name_short}/${app_name_short}/
skin_reg_dir = skin/${skin_name_short}/${app_name_short}/
# chrome urls
chrome_content_url = chrome://${app_name_short}/content/
chrome_locale_url = chrome://${app_name_short}/locale/
chrome_skin_url = chrome://${app_name_short}/skin/
# files defining the main ui
chrome_main_xul_url = ${chrome_content_url}${filename:app-ui.xul}
chrome_main_css_url = ${chrome_skin_url}${filename:app-ui.css}
chrome_main_dtd_url = ${chrome_locale_url}${filename:app-ui.dtd}
# file we want to load our overlay on top of
overlay_trigger_url = chrome://communicator/content/tasksOverlay.xul
# node from the overlay_trigger_url that we want to overlay
overlay_trigger_node = taskPopup
# value of position attribute for the first overlayed node
overlay_trigger_position = 6
# file that contains the nodes we want to overlay
overlay_node_url = ${chrome_content_url}${filename:app-overlay.xul}
# file that contains the javascript we want to overlay
overlay_js_url = ${chrome_content_url}${filename:app-overlay.js}
# file that contains the dtd we want to overlay
overlay_dtd_url = ${chrome_locale_url}${filename:app-overlay.dtd}