Changeset 11638


Ignore:
Timestamp:
05/06/11 10:53:28 (2 years ago)
Author:
AndrewJones
Message:

Item8480: don't load preferences from plugin topic; ensure parent is being set correctly when using %TOPIC%; doc updates

Location:
trunk/TopicCreatePlugin
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/TopicCreatePlugin/data/System/TopicCreatePlugin.txt

    r8161 r11638  
    88---++ <nop>TOPICCREATE - Automatically Create a Set of Foswiki Topics 
    99 
    10    * The =%<nop>TOPICCREATE{}%= Macro is useful for creating topics based on templates 
     10   * The =%<nop>TOPICCREATE{}%= macro is useful for creating topics based on templates 
    1111   * 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. 
    1212   * Syntax: =%<nop>TOPICCREATE{ &lt;attributes&gt; }%= 
     
    1919     | =&lt;anything else>=""= | Any other parameters are passed to a child topic to initialize any urlparams.| Any string | None | 
    2020   * The action to create the Foswiki topic will not occur until one hits the =Save Changes= button in preview 
    21    * The =%<nop>TOPICCREATE{}%= variable will be removed upon saving of the topic 
     21   * The =%<nop>TOPICCREATE{}%= macro will be removed upon saving of the topic 
    2222   * Any attachments that are in the =template= will also be copied to the new topic 
    2323   * =%<nop>TOPICCREATE%= is recursive 
     
    4949---++ Plugin Settings 
    5050 
    51 Plugin settings are stored as preferences variables. To reference a plugin setting write ==%<nop>&lt;plugin&gt;_&lt;setting&gt;%==, i.e. ==%<nop>TOPICCREATEPLUGIN_SHORTDESCRIPTION%== 
     51Plugin 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. 
    5252 
    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--> 
    5556 
    5657   * Debug plugin: (See output in the Foswiki debug log) 
    57       * Set DEBUG = 0 
     58      * Set TOPICCREATEPLUGIN_DEBUG = 0 
    5859 
    5960---++ Installation Instructions 
     
    7071|  Plugin Version: | %$VERSION% | 
    7172|  Change&nbsp;History: | <!-- versions below in reverse order -->&nbsp; | 
     73|  06 May 2011: | v1.5: No longer load preferences from plugin topic; doc updates -- Foswiki:Main.AndrewJones | 
    7274|  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 | 
    7375|  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  
    11# Plugin for Foswiki - The Free and Open Source Wiki, http://foswiki.org/ 
    22# 
    3 # Copyright (C) 2009 - 2010 Andrew Jones, http://andrew-jones.com 
     3# Copyright (C) 2009 - 2011 Andrew Jones, http://andrew-jones.com 
    44# Copyright (C) 2005-2006 Peter Thoeny, peter@thoeny.org 
    55# 
     
    2525); 
    2626 
    27 our $VERSION = '$Rev$'; 
    28 our $RELEASE = '1.4'; 
    29 our $SHORTDESCRIPTION = 
     27$VERSION = '$Rev$'; 
     28$RELEASE = '1.4'; 
     29$SHORTDESCRIPTION = 
    3030  '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'; 
    3333 
    34 our $doInit = 0; 
     34$doInit = 0; 
    3535 
    3636# ========================= 
     
    7272 
    7373    $_[0] =~ 
    74 s/%TOPICCREATE{(.*)}%[\n\r]*/Foswiki::Plugins::TopicCreatePlugin::Func::handleTopicCreate($1, $_[2], $_[1], $_[0] )/geo; 
     74s/%TOPICCREATE{(.*)}%[\n\r]*/Foswiki::Plugins::TopicCreatePlugin::Func::handleTopicCreate($1, $_[2], $_[1], $_[0] )/ge; 
    7575 
    7676# To be completed, tested and documented 
    77 # $_[0] =~ s/%TOPICPATCH{(.*)}%[\n\r]*/Foswiki::Plugins::TopicCreatePlugin::Func::handleTopicPatch($1, $_[2], $_[1], $_[0] )/geo; 
     77# $_[0] =~ s/%TOPICPATCH{(.*)}%[\n\r]*/Foswiki::Plugins::TopicCreatePlugin::Func::handleTopicPatch($1, $_[2], $_[1], $_[0] )/ge; 
    7878 
    7979    if ( $_[0] =~ /%TOPICATTACH/ ) { 
    8080        my @attachMetaData = (); 
    8181        $_[0] =~ 
    82 s/%TOPICATTACH{(.*)}%[\n\r]*/Foswiki::Plugins::TopicCreatePlugin::Func::handleTopicAttach($1, \@attachMetaData)/geo; 
     82s/%TOPICATTACH{(.*)}%[\n\r]*/Foswiki::Plugins::TopicCreatePlugin::Func::handleTopicAttach($1, \@attachMetaData)/ge; 
    8383        my $fileName = ""; 
    8484        foreach my $fileMeta (@attachMetaData) { 
  • trunk/TopicCreatePlugin/test/unit/TopicCreatePlugin/TopicCreateTests.pm

    r8161 r11638  
    1717    my $self = shift()->SUPER::new(@_); 
    1818    return $self; 
     19} 
     20 
     21sub loadExtraConfig { 
     22    my $this = shift; 
     23 
     24    $Foswiki::cfg{Plugins}{TopicCreatePlugin}{Enabled} = 1; 
     25    $this->SUPER::loadExtraConfig(); 
    1926} 
    2027 
     
    135142} 
    136143 
     144# test the use of %TOPICCREATE{ parent="%TOPIC%" }% 
     145sub 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 
     156HERE 
     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 
    137175# test the use of %TOPICCREATE{ disable="ThisTopic" }% 
    138176sub test_disable { 
Note: See TracChangeset for help on using the changeset viewer.