Skip to content

Commit

Permalink
Item8508: fixed order rules are checked against the topic name
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.foswiki.org/trunk/AutoTemplatePlugin@6286 0b4bb1d4-4e5a-0410-9cc4-b2b747904278
  • Loading branch information
MichaelDaum authored and MichaelDaum committed Feb 12, 2010
1 parent 4f51f90 commit 63e4788
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
14 changes: 9 additions & 5 deletions data/System/AutoTemplatePlugin.txt
Expand Up @@ -95,21 +95,24 @@ For both view and edit, a set of rules can be specified in =configure= where eac
</verbatim>

A topic's name will be matched against the regular expression in =&lt;pattern>= to decide on the template name
to be used for the current template.
to be used for the current template. A pattern can either cover the full qualified topic name (web.topic) or just
the topic name. Rules are checked against the FQTN first.

Examples:

<verbatim>
$Foswiki::cfg{Plugins}{AutoTemplatePlugin}{ViewTemplateRules} = {
'WebTopicList' => 'WebTopicListView',
'Tasks\.Item.*' => 'Tasks.ItemView',
'Item.*' => 'Applications.TaskApp.ItemView',
'WebSearch.*' => 'KinoSearchView',
};
</verbatim>

This will apply the <nop>WebTopicListView to the WebTopicList topic in all webs, the
<nop>KinoSearchView to all WebSearch and WebSearchAdvanced topics in all webs and
the <nop>Tasks.ItemView to all Item topics in the Tasks web.
This will apply the =<nop>WebTopicListViewTemplate= to the WebTopicList topic in all webs, the
=<nop>KinoSearchViewTemplate= to all WebSearch and WebSearchAdvanced topics in all webs and
the =<nop>Tasks.ItemViewTemplate= to all Item topics in the Tasks web. Other Item topics
will be displayed using the =<nop>Applications.TaskApp.ItemViewTemplate=

---++ Configuration Settings

Expand All @@ -136,11 +139,12 @@ The following settings can be defined in configure
* Set SHORTDESCRIPTION = Automatically sets VIEW_TEMPLATE and EDIT_TEMPLATE
-->
| Plugin Author: | Foswiki:Main.MichaelDaum |
| Copyright: | &copy; 2008-2009, Oliver Kr&uuml;ger, Michael Daum |
| Copyright: | &copy; 2008-2010, Oliver Kr&uuml;ger, Michael Daum |
| License: | GPL ([[http://www.gnu.org/copyleft/gpl.html][GNU General Public License]]) |
| Release: | %$RELEASE% |
| Version: | %$VERSION% |
| Change History: | <!-- versions below in reverse order -->&nbsp; |
| 12 Feb 2010: | fixed order rules are matched against the web.topic name |
| 15 Dec 2009: | forked Foswiki:Extensions.AutoViewTemplatePlugin as rule-based feature was rejected. See Foswiki:Development.RulebasedViewTemplates |
| 03 Nov 2009: | added rule-based strategy; made =mode= a priority list (MD) |
| 06 Oct 2009: | Item2213: Plugin got better documentation. No change in behaviour. |
Expand Down
11 changes: 7 additions & 4 deletions lib/Foswiki/Plugins/AutoTemplatePlugin.pm
Expand Up @@ -18,7 +18,7 @@ use vars qw( $VERSION $RELEASE $SHORTDESCRIPTION
);

$VERSION = '$Rev: 5221 $';
$RELEASE = '1.0';
$RELEASE = '1.1';
$SHORTDESCRIPTION = 'Automatically sets VIEW_TEMPLATE and EDIT_TEMPLATE';
$NO_PREFS_IN_TOPIC = 1;

Expand Down Expand Up @@ -158,10 +158,13 @@ sub _getTemplateFromRules {

return unless $rules;

# check full qualified topic name first
foreach my $pattern (keys %$rules) {
if ("$web.$topic" =~ /^($pattern)$/ || $topic =~ /^($pattern)$/) {
return $rules->{$pattern};
}
return $rules->{$pattern} if "$web.$topic" =~ /^($pattern)$/;
}
# check topic name only
foreach my $pattern (keys %$rules) {
return $rules->{$pattern} if $topic =~ /^($pattern)$/;
}

return;
Expand Down

0 comments on commit 63e4788

Please sign in to comment.