Permalink
Browse files

Item5425: Finish off template rename support. Need to add unit tests

git-svn-id: http://svn.foswiki.org/trunk@8452 0b4bb1d4-4e5a-0410-9cc4-b2b747904278
  • Loading branch information...
GeorgeClark GeorgeClark
GeorgeClark authored and GeorgeClark committed Aug 10, 2010
1 parent 3cc806e commit e310bc9a73fcbc02f954a42ab96f0b78e12f93f1
Showing with 30 additions and 11 deletions.
  1. +7 −4 core/lib/Foswiki/Render.pm
  2. +23 −7 core/lib/Foswiki/UI/Rename.pm
View
@@ -1749,7 +1749,7 @@ sub forEachLine {
* =grep= - if true, generate a GNU-grep compatible RE instead of the
default Perl RE.
* =nosot= - If true, do not generate "Spaced out text" match
* =template= - If true, match for template setting and strip Template suffix from topic name
* =template= - If true, match for template setting in Set/Local statement
* =in_noautolink= - Only match explicit (squabbed) WikiWords. Used in <noautolink> blocks
* =url= - if set, generates an expression that will match a Foswiki
URL that points to the web/topic, instead of the default which
@@ -1823,9 +1823,8 @@ sub getReferenceRE {
$re = "$bow$matchWeb\\.$topic$eow";
}
elsif ( $options{template} ) {
($topic) = $topic =~ m/(.*)Template$/;
# SMELL: Incomplete - need
# Regex to lookback match Set statement
# $1 is used in replace. Can't use lookbehind because of variable length restriction
$re = '('.$Foswiki::regex{setRegex}.'(?:VIEW|EDIT)_TEMPLATE\s*=\s*)('.$matchWeb.'\\.'.$topic.')\s*$';
}
elsif ( $options{in_noautolink} ) {
$re = "$squabo$matchWeb\\.$topic$squabc";
@@ -1851,6 +1850,10 @@ sub getReferenceRE {
if ( $options{grep} ) {
$re = "(($back\[^./])|^)$bow($matchWeb\\.)?$topic$eow";
}
elsif ( $options{template} ) {
# $1 is used in replace. Can't use lookbehind because of variable length restriction
$re = '('.$Foswiki::regex{setRegex}.'(?:VIEW|EDIT)_TEMPLATE\s*=\s*)'."($matchWeb\\.)?$topic".'\s*$';
}
elsif ( $options{in_noautolink} ) {
$re = "$squabo($matchWeb\\.)?$topic$squabc";
}
@@ -850,10 +850,28 @@ sub _replaceTopicReferences {
# Do any references for Templates
if ( $oldTopic =~ m/(.*)Template$/ ) {
$re = Foswiki::Render::getReferenceRE( $oldWeb, $1,
nosot => 1
);
print STDERR "Using #$re# on $oldWeb.$oldTopic \n";
my $ot = $1;
# Only if the rename is also to a template, otherwise give up.
if ($repl =~ m/(.*)Template$/) {
my $nt = $1;
# Handle META Preference settings
if ( $nt && $args->{_type} && $args->{_type} eq 'PREFERENCE' && $args->{_key} eq 'value' ) {
$re = Foswiki::Render::getReferenceRE( $oldWeb, $ot,
nosot => 1
);
$text =~ s/($re)/_doReplace($1, $newWeb, $nt)/ge;
}
# Handle Set/Local statements inline
$re = Foswiki::Render::getReferenceRE( $oldWeb, $ot,
nosot => 1,
template => 1
);
# SMELL: This will rewrite qualified topic names to be unqualified
# But regex is matching too much to use the _doReplace routine
$text =~ s/$re/$1$nt/g;
}
}
# Now URL form
@@ -1338,8 +1356,6 @@ sub _getReferringTopics {
interweb => $interWeb,
);
$searchString .= '|' . $refre
#SMELL: Still needs code to change the template references.
# - this finds the topic with the references.
}
my $matches =
@@ -1392,7 +1408,7 @@ sub _updateReferringTopics {
$options->{inWeb} = $itemWeb;
my $text =
$renderer->forEachLine( $topicObject->text(), $fn, $options );
$topicObject->forEachSelectedValue( qw/^(FIELD|FORM|TOPICPARENT)$/,
$topicObject->forEachSelectedValue( qw/^(FIELD|FORM|PREFERENCE|TOPICPARENT)$/,
undef, $fn, $options );
$topicObject->text($text);
$topicObject->save( minor => 1 );

0 comments on commit e310bc9

Please sign in to comment.