Changeset 11638
- Timestamp:
- 05/06/11 10:53:28 (2 years ago)
- Location:
- trunk/TopicCreatePlugin
- Files:
-
- 3 edited
-
data/System/TopicCreatePlugin.txt (modified) (4 diffs)
-
lib/Foswiki/Plugins/TopicCreatePlugin.pm (modified) (3 diffs)
-
test/unit/TopicCreatePlugin/TopicCreateTests.pm (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/TopicCreatePlugin/data/System/TopicCreatePlugin.txt
r8161 r11638 8 8 ---++ <nop>TOPICCREATE - Automatically Create a Set of Foswiki Topics 9 9 10 * The =%<nop>TOPICCREATE{}%= Macro is useful for creating topics based on templates10 * The =%<nop>TOPICCREATE{}%= macro is useful for creating topics based on templates 11 11 * Example scenario: You have a notebook application where users can create new notebooks based on a notebook template topic. Each time a user creates a new notebook you would like to create a set of child topics, each based on a separate template. 12 12 * Syntax: =%<nop>TOPICCREATE{ <attributes> }%= … … 19 19 | =<anything else>=""= | Any other parameters are passed to a child topic to initialize any urlparams.| Any string | None | 20 20 * The action to create the Foswiki topic will not occur until one hits the =Save Changes= button in preview 21 * The =%<nop>TOPICCREATE{}%= variablewill be removed upon saving of the topic21 * The =%<nop>TOPICCREATE{}%= macro will be removed upon saving of the topic 22 22 * Any attachments that are in the =template= will also be copied to the new topic 23 23 * =%<nop>TOPICCREATE%= is recursive … … 49 49 ---++ Plugin Settings 50 50 51 Plugin settings are stored as preferences va riables. To reference a plugin setting write ==%<nop><plugin>_<setting>%==, i.e. ==%<nop>TOPICCREATEPLUGIN_SHORTDESCRIPTION%==51 Plugin settings are stored as preferences values. You can override the defaults for these preferences in %LOCALSITEPREFS%, the <nolink>%WEBPREFSTOPIC%</nolink> topic of the current web, or in individual topics that use the plugin. *Changing them here will have no effect!* This allows you to upgrade the plugin without having to worry about losing your settings. 52 52 53 * One line description, is shown in the %SYSTEMWEB%.TextFormattingRules topic: 54 * Set SHORTDESCRIPTION = Automatically create a set of topics and attachments at topic save time 53 <!-- 54 * Set SHORTDESCRIPTION = Automatically create a set of topics and attachments at topic save time 55 --> 55 56 56 57 * Debug plugin: (See output in the Foswiki debug log) 57 * Set DEBUG = 058 * Set TOPICCREATEPLUGIN_DEBUG = 0 58 59 59 60 ---++ Installation Instructions … … 70 71 | Plugin Version: | %$VERSION% | 71 72 | Change History: | <!-- versions below in reverse order --> | 73 | 06 May 2011: | v1.5: No longer load preferences from plugin topic; doc updates -- Foswiki:Main.AndrewJones | 72 74 | 08 Feb 2010: | v1.4: Foswikitask:Item8281 - Changed the way extra parameters are passed using =%<nop>TOPICCREATE%=, so that special characters can now be passed -- Foswiki:Main.AndrewJones | 73 75 | 08 Feb 2010: | v1.3: Foswikitask:Item8480 - Fix for setting the parent; Fix for using Macros as the parent in =%<nop>TOPICCREATE%= -- Foswiki:Main.AndrewJones | -
trunk/TopicCreatePlugin/lib/Foswiki/Plugins/TopicCreatePlugin.pm
r8161 r11638 1 1 # Plugin for Foswiki - The Free and Open Source Wiki, http://foswiki.org/ 2 2 # 3 # Copyright (C) 2009 - 201 0Andrew Jones, http://andrew-jones.com3 # Copyright (C) 2009 - 2011 Andrew Jones, http://andrew-jones.com 4 4 # Copyright (C) 2005-2006 Peter Thoeny, peter@thoeny.org 5 5 # … … 25 25 ); 26 26 27 our$VERSION = '$Rev$';28 our$RELEASE = '1.4';29 our$SHORTDESCRIPTION =27 $VERSION = '$Rev$'; 28 $RELEASE = '1.4'; 29 $SHORTDESCRIPTION = 30 30 'Automatically create a set of topics and attachments at topic save time'; 31 our $NO_PREFS_IN_TOPIC = 0;32 our$pluginName = 'TopicCreatePlugin';31 $NO_PREFS_IN_TOPIC = 1; 32 $pluginName = 'TopicCreatePlugin'; 33 33 34 our$doInit = 0;34 $doInit = 0; 35 35 36 36 # ========================= … … 72 72 73 73 $_[0] =~ 74 s/%TOPICCREATE{(.*)}%[\n\r]*/Foswiki::Plugins::TopicCreatePlugin::Func::handleTopicCreate($1, $_[2], $_[1], $_[0] )/ge o;74 s/%TOPICCREATE{(.*)}%[\n\r]*/Foswiki::Plugins::TopicCreatePlugin::Func::handleTopicCreate($1, $_[2], $_[1], $_[0] )/ge; 75 75 76 76 # To be completed, tested and documented 77 # $_[0] =~ s/%TOPICPATCH{(.*)}%[\n\r]*/Foswiki::Plugins::TopicCreatePlugin::Func::handleTopicPatch($1, $_[2], $_[1], $_[0] )/ge o;77 # $_[0] =~ s/%TOPICPATCH{(.*)}%[\n\r]*/Foswiki::Plugins::TopicCreatePlugin::Func::handleTopicPatch($1, $_[2], $_[1], $_[0] )/ge; 78 78 79 79 if ( $_[0] =~ /%TOPICATTACH/ ) { 80 80 my @attachMetaData = (); 81 81 $_[0] =~ 82 s/%TOPICATTACH{(.*)}%[\n\r]*/Foswiki::Plugins::TopicCreatePlugin::Func::handleTopicAttach($1, \@attachMetaData)/ge o;82 s/%TOPICATTACH{(.*)}%[\n\r]*/Foswiki::Plugins::TopicCreatePlugin::Func::handleTopicAttach($1, \@attachMetaData)/ge; 83 83 my $fileName = ""; 84 84 foreach my $fileMeta (@attachMetaData) { -
trunk/TopicCreatePlugin/test/unit/TopicCreatePlugin/TopicCreateTests.pm
r8161 r11638 17 17 my $self = shift()->SUPER::new(@_); 18 18 return $self; 19 } 20 21 sub loadExtraConfig { 22 my $this = shift; 23 24 $Foswiki::cfg{Plugins}{TopicCreatePlugin}{Enabled} = 1; 25 $this->SUPER::loadExtraConfig(); 19 26 } 20 27 … … 135 142 } 136 143 144 # test the use of %TOPICCREATE{ parent="%TOPIC%" }% 145 sub test_parent_as_topic { 146 my $this = shift; 147 148 my $testTopic = "ParentTest2"; 149 150 my $sampleText = <<"HERE"; 151 %META:TOPICINFO{author="guest" date="1053267450" format="1.0" version="1.35"}% 152 %META:TOPICPARENT{name="WebHome"}% 153 154 %TOPICCREATE{template="$simpleTemplate" topic="$testTopic" parent="%TOPIC%"}% 155 156 HERE 157 158 Foswiki::Plugins::TopicCreatePlugin::initPlugin( $this->{test_topic}, 159 $this->{test_web}, 'guest', $Foswiki::cfg{SystemWebName} ); 160 Foswiki::Plugins::TopicCreatePlugin::beforeSaveHandler( $sampleText, 161 $this->{test_topic}, $this->{test_web} ); 162 163 # child topic should now exist 164 $this->assert( Foswiki::Func::topicExists( $this->{test_web}, $testTopic ), 165 "$testTopic was not created" ); 166 167 # parent of newly created topic should be WebHome 168 my ( $meta, undef ) = 169 Foswiki::Func::readTopic( $this->{test_web}, $testTopic ); 170 $this->assert_equals( $this->{test_topic}, $meta->getParent(), 171 "Parent of new child topic is incorrect. Should be the same as the current topic." 172 ); 173 } 174 137 175 # test the use of %TOPICCREATE{ disable="ThisTopic" }% 138 176 sub test_disable {
Note: See TracChangeset
for help on using the changeset viewer.
