Skip to content

Commit

Permalink
Item12493: Numerous small niggles in Empty* templates fixed. Removed …
Browse files Browse the repository at this point in the history
…dead EmptyTag.

git-svn-id: http://svn.foswiki.org/trunk@16712 0b4bb1d4-4e5a-0410-9cc4-b2b747904278
  • Loading branch information
CrawfordCurrie authored and CrawfordCurrie committed May 10, 2013
1 parent 7d42011 commit ded5359
Show file tree
Hide file tree
Showing 8 changed files with 161 additions and 149 deletions.
131 changes: 83 additions & 48 deletions BuildContrib/create_new_extension.pl
Expand Up @@ -3,7 +3,7 @@
#
# Author: Crawford Currie http://c-dot.co.uk
#
# Copyright (C) 2008-2012 FoswikiContributors. All rights reserved.
# Copyright (C) 2008-2013 FoswikiContributors. All rights reserved.
# FoswikiContributors are listed in the AUTHORS file in the root of
# the distribution.
#
Expand All @@ -23,6 +23,11 @@

use File::Path ();

our @ISOMONTH = (
'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun',
'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'
);

# The script works by creating a new directory structure from an
# existing DS, either an Empty* template or a user-specified
# existing DS. First, a file-set of required files is built up
Expand All @@ -40,17 +45,34 @@
$def{MODULE} = $ARGV[0];
usage() unless $def{MODULE};

$def{MODULE} =~ /^.*?(Skin|JQueryPlugin|Plugin|Contrib|AddOn)$/;
$def{TYPE} = $1;
usage() unless $def{TYPE};

$def{STUBS} = $def{TYPE} =~ /Plugin$/ ? 'Plugins' : 'Contrib';

# Determine the template module to use, either from an explicit parameter
# or by finding an appropriate Empty* template module
our $templateModule;
if ( $#ARGV >= 1 ) {
$templateModule = $ARGV[1];
}
else {
my @types;
if ( opendir( D, '.' ) ) {
foreach my $dir ( readdir(D) ) {
if ( -d $dir && $dir =~ /^Empty(.*)$/ ) {
push( @types, $1 );
}
}
}
unless (@types) {
usage( error =>
"No Empty* templates found in the current directory. A template with the same type as the extension you are creating must be present in the current directory (or you must give an explicit template name)"
);
}

my $types_re = join( '|', @types );
$def{MODULE} =~ /^.*?($types_re)$/;
$def{TYPE} = $1;
usage() unless $def{TYPE};

$def{STUBS} = $def{TYPE} =~ /Plugin$/ ? 'Plugins' : 'Contrib';

$templateModule = "Empty$def{TYPE}";
}

Expand All @@ -62,13 +84,17 @@

print "Creating $def{MODULE} from templates in $templateModule\n";

$def{SHORTDESCRIPTION} =
$def{CREATED_SHORTDESCRIPTION} =
prompt( "Enter a one-line description of the extension: ", '' );
$def{SHORTDESCRIPTION} =~ s/'/\\'/g;
$def{CREATED_SHORTDESCRIPTION} =~ s/'/\\'/g;

$def{AUTHOR} =
$def{CREATED_AUTHOR} =
prompt( "Enter the wikiname of the author (e.g. ThomasHardy): ", '' );

my @t = localtime( time() );
$def{CREATED_YEAR} = sprintf( "%04d", $t[5] + 1900 );
$def{CREATED_DATE} =
sprintf( "%02d %s %04d", $t[3] + 1, $ISOMONTH[ $t[4] ], $t[5] + 1900 );
my $modPath = "lib/Foswiki/$def{STUBS}/$def{MODULE}";

my $fileset = {
Expand All @@ -85,7 +111,7 @@
},
"$modPath/Config.spec" => {
template => "lib/Foswiki/$def{STUBS}/$templateModule/Config.spec",
extract => \&commonEmptyExtract
extract => \&configSpecExtract
},
"$modPath/MANIFEST" => {
template => "lib/Foswiki/$def{STUBS}/$templateModule/MANIFEST",
Expand Down Expand Up @@ -117,21 +143,23 @@
# Add in the extra files a JQuery plugin requires
$fileset->{"$modPath/$def{JQUERYPLUGINMODULE}.pm"} = {
template => "lib/Foswiki/Plugins/EmptyJQueryPlugin/YOUR.pm",
extract => \&jqpPMExtract
extract => \&YOURpmExtract
};

$fileset->{"data/System/JQuery$def{JQUERYPLUGIN}.txt"} = {
template => "data/System/JQueryYour.txt",
extract => \&jqpExtract
extract => \&commonEmptyExtract
};

$fileset->{"pub/System/$def{MODULE}/jquery.$def{JQUERYPLUGINMODULELC}.js"}
= {
template => "pub/System/EmptyJQueryPlugin/jquery.your.js",
extract => \&jqpPMExtract
extract => \&commonEmptyExtract
};
}

#print "PREMO ".join(', ', map { $_->{template} } values %$fileset)."\n";

# If we have a template dir, override the default files with those from the template
# and add any missing.
if ($templateModule) {
Expand Down Expand Up @@ -305,9 +333,16 @@ sub manifest {
$mask = eval $1;
$e = $2;
}
if ( $fileset->{$f} ) {
$fileset->{$f}->{extra} = $e if $e;
$fileset->{$f}->{mask} = $mask;
my $found;
while ( my ( $k, $v ) = each %$fileset ) {
if ( $v->{template} eq $f ) {
$found = $v;
last;
}
}
if ($found) {
$found->{extra} = $e if $e;
$found->{mask} = $mask;
}
else {
add2Manifest( "manifest", $f, $mask, $e );
Expand All @@ -327,6 +362,7 @@ sub manifest {

sub add2Manifest {
my ( $what, $f, $mask, $e ) = @_;

my $rw = \&commonEmptyExtract;
if ( $f =~ /\.(\w+)/ ) {
my $fn = "${1}EmptyExtract";
Expand All @@ -351,43 +387,42 @@ sub add2Manifest {
sub commonEmptyExtract {
my $s = shift;
die unless defined $s;
if ( defined $def{JQUERYPLUGIN} ) {
$s =~
s/(Foswiki::Plugins::EmptyJQueryPlugin::)YOUR/$1$def{JQUERYPLUGINMODULE}/g;
$s =~ s/"Your"/$def{JQUERYPLUGIN}/g;
$s =~ s/"your"/$def{JQUERYPLUGINMODULELC}/g;
}
$s =~ s/$templateModule/%\$MODULE%/g;
return $s;
}

sub manifestExtract {
sub YOURpmExtract {
my $s = shift;

# Rename templatemodule to this module
$s =~ s/$templateModule/$def{MODULE}/gs;

$s = commonEmptyExtract($s);

# Special case for renaming
$s =~ s/your\.(\w+)$/'%$JQUERYPLUGINMODULELC%'.$1/e;
$s =~ s/Your\.(\w+)$/'%$JQUERYPLUGIN%'..$1/e;
$s =~ s/YOUR\.(\w+)$/'%$JQUERYPLUGINMODULE%'.$1/e;
return $s;
die unless defined $s;
$s =~ s/Your/$def{JQUERYPLUGIN}/g;
$s =~ s/YOUR/$def{JQUERYPLUGINMODULE}/g;
$s =~ s/your/$def{JQUERYPLUGINMODULELC}/g;
return commonEmptyExtract($s);
}

sub pmEmptyExtract {
my $s = commonEmptyExtract(shift);
$s =~ s/^# change the package name.*$//m; # we're doing it!
$s =~ s/(\$SHORTDESCRIPTION = ').*?'/$1.'%$SHORTDESCRIPTION%'."';"/e;
return $s;
sub configSpecExtract {
my $s = shift;
die unless defined $s;
$s =~ s/\{Your\}/\{$def{JQUERYPLUGIN}\}/g;
$s =~ s/YOUR/$def{JQUERYPLUGINMODULE}/g;
return commonEmptyExtract($s);
}

sub jqpExtract {
my $s = commonEmptyExtract(shift);
$s =~ s/Your/%\$JQUERYPLUGIN%/sg;
$s =~ s/YOUR/%\$JQUERYPLUGINMODULE%/sg;
return $s;
}
sub manifestExtract {
my $s = shift;

sub jqpPMExtract {
my $s = jqpExtract(shift);
$s =~ s/your/%\$JQUERYPLUGINMODULELC%/sg;
return $s;
if ( defined $def{JQUERYPLUGIN} ) {
$s =~ s/Your/$def{JQUERYPLUGIN}/g;
$s =~ s/YOUR/$def{JQUERYPLUGINMODULE}/g;
$s =~ s/your/$def{JQUERYPLUGINMODULELC}/g;
}
return commonEmptyExtract($s);
}

# Prompt for a yes/no answer, with possible default to be applied
Expand Down Expand Up @@ -452,13 +487,13 @@ sub usage {
is normally run at the root of a Foswiki checkout, where existing
extensions are found in subdirectories.
You pass the name of your new extension - which must end in Skin,
You pass the name of your new extension - which must end in
JQueryPlugin, Plugin, or Contrib - to the script. For example,
$0 MyNewSkin
$0 MyNewPlugin
will create the directory structure and support files for a new skin
called "MyNewSkin"
will create the directory structure and support files for a new plugin
called "MyNewPlugin"
You can also build a new extension using sources from an existing
extension. When you build from an existing extension, copies of all
Expand Down
10 changes: 5 additions & 5 deletions EmptyJQueryPlugin/data/System/EmptyJQueryPlugin.txt
@@ -1,4 +1,4 @@
%META:TOPICPARENT{name="Plugins"}%
%META:TOPICPARENT{name="JQueryPlugin"}%
<!--
One line description, required for extensions repository catalog.
* Set SHORTDESCRIPTION = %$SHORTDESCRIPTION%
Expand All @@ -21,13 +21,13 @@ Available [[JQueryPlugin][jQuery]] plugins:

---++ Info

| Author: | %$AUTHOR% |
| Copyright: | &copy; 2011, Foswiki Contributors |
| Author: | %$CREATED_AUTHOR% |
| Copyright: | &copy; %$CREATEDYEAR%, %$CREATED_AUTHOR%, All Rights Reserved |
| License: | GPL ([[http://www.gnu.org/copyleft/gpl.html][GNU General Public License]]) |
| Release: | %$RELEASE% |
| Dependencies: | %$DEPENDENCIES% |
| Version: | %$VERSION% |
| Release: | %$RELEASE% |
| Change&nbsp;History: | <!-- versions below in reverse order -->&nbsp; |
| 1.0.0 (XX Mmm 20XX) | Initial release |
| Home: | http://foswiki.org/Extensions/%TOPIC% |
| Support: | http://foswiki.org/Support/%TOPIC% |

83 changes: 38 additions & 45 deletions EmptyJQueryPlugin/lib/Foswiki/Plugins/EmptyJQueryPlugin.pm
Expand Up @@ -16,31 +16,25 @@ use Foswiki::Func (); # The plugins API
use Foswiki::Plugins (); # For the API version

# $VERSION is referred to by Foswiki, and is the only global variable that
# *must* exist in this package. Two version formats are supported:
# *must* exist in this package. Two formats are supported; the Foswiki
# convention is to use the "v1.2.3" format described in "perldoc version".
# Foswiki also supports a simpler tuple, such as "1.2.3". This format
# can be used when this identifier is taken from another source, such as
# the version number of the JQuery plugin that this module encapsulates.
#
# Recommended: Dotted triplet. Use "v1.2.3" format for releases, and
# "v1.2.3_001" for "alpha" versions. The v prefix is required.
# This format uses the "declare" format
# use version; our $VERSION = version->declare("v1.2.0");
# You are strongly recommended to keep the version number in lock-step
# between the JQuery plugin and the Foswiki plugin.
#
# Alternative: Simple decimal version. Use "1.2" format for releases, and
# "1.2_001" for "alpha" versions. Do NOT use the "v" prefix. This style
# must be set using the "parse" method
# use version; our $VERSION = version->parse("1.20_001");
#
# Note: Alpha versions compare as numerically lower than the non-alpha version
# so the versions in ascending order are:
# v1.2.1_001 -> v1.2.1 -> v1.2.2_001 -> v1.2.2
#
# These statements MUST be on the same line. See "perldoc version" for more
# information on version strings.
use version; our $VERSION = version->declare("v1.0.0_001");

our $RELEASE = '03 Mar 2010';
# The RELEASE is used in the Foswiki Extensions installer
our $RELEASE = '%$CREATED_DATE%';

# Short description of this plugin
# One line description, is shown in the %SYSTEMWEB%.TextFormattingRules topic:
our $SHORTDESCRIPTION = 'Your New Jquery plugin module..';
# One line description of the module
our $SHORTDESCRIPTION = '%$CREATED_SHORTDESCRIPTION%';

# Author information
our $AUTHOR = '%$CREATED_AUTHOR%';

our $NO_PREFS_IN_TOPIC = 1;

Expand Down Expand Up @@ -78,28 +72,27 @@ sub initPlugin {
__END__
This copyright information applies to the EmptyJQueryPlugin:
# Plugin for Foswiki - The Free and Open Source Wiki, http://foswiki.org/
#
# EmptyJQueryPlugin is Copyright (C) 2010 Foswiki Contributors
#
# The Javascript files packaged with this plugin are Copyright (C) and licensed
# separately by their respective authors, please review those files separately
# for more detailed information.
#
# Foswiki Contributors are listed in the AUTHORS file in the root
# of this distribution. NOTE: Please extend that file, not this notice.
#
#
# This license applies to EmptyJQueryPlugin and to any derivatives.
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version. For
# more details read LICENSE in the root of this distribution.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
#
# For licensing info read LICENSE file in the root of this distribution.
Plugin for Foswiki - The Free and Open Source Wiki, http://foswiki.org/
Copyright (C) 2010-%$CREATED_YEAR% Foswiki Contributors
The Javascript files packaged with this plugin are Copyright (C) and licensed
separately by their respective authors, please review those files separately
for more detailed information.
Foswiki Contributors are listed in the AUTHORS file in the root
of this distribution. NOTE: Please extend that file, not this notice.
This license applies to EmptyJQueryPlugin and to any derivatives:
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version. For
more details read LICENSE in the root of this distribution.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
For licensing info read LICENSE file in the root of this distribution.

0 comments on commit ded5359

Please sign in to comment.