Skip to content

Commit

Permalink
Item13070: public API to get auto-assigned tmpl
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelDaum committed Nov 3, 2014
1 parent 4414bfb commit f5f94a5
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 16 deletions.
8 changes: 8 additions & 0 deletions .gitignore
@@ -0,0 +1,8 @@
*.swp
AutoTemplatePlugin.md5
AutoTemplatePlugin.sha1
AutoTemplatePlugin.tgz
AutoTemplatePlugin.txt
AutoTemplatePlugin.zip
AutoTemplatePlugin_installer
AutoTemplatePlugin_installer.pl
2 changes: 1 addition & 1 deletion data/System/AutoTemplatePlugin.txt
Expand Up @@ -156,6 +156,7 @@ The following settings can be defined in configure
| Release: | %$RELEASE% |
| Version: | %$VERSION% |
| Change History: | <!-- versions below in reverse order -->&nbsp; |
| 03 Nov 2014: | implemented public API to get the auto-assigned template |
| 25 Aug 2011: | added more default views for tools in the System web |
| 05 Apr 2011: | added VIEW_TEMPLATE_RULES, EDIT_TEMPLATE_RULES preference variables |
| 09 Nov 2010: | added defaults to ease templating !ChangePassword, !SiteChanges, !WebIndex |
Expand All @@ -178,4 +179,3 @@ The following settings can be defined in configure
| Other Dependencies: | none |
| Home: | Foswiki:Extensions/%TOPIC% |
| Support: | Foswiki:Extensions/%TOPIC% |

36 changes: 22 additions & 14 deletions lib/Foswiki/Plugins/AutoTemplatePlugin.pm
Expand Up @@ -14,8 +14,8 @@ package Foswiki::Plugins::AutoTemplatePlugin;
use strict;
use warnings;

our $VERSION = '2.01';
our $RELEASE = '2.01';
our $VERSION = '3.00';
our $RELEASE = '3.00';
our $SHORTDESCRIPTION = 'Automatically sets VIEW_TEMPLATE and EDIT_TEMPLATE';
our $NO_PREFS_IN_TOPIC = 1;
our $debug;
Expand All @@ -31,7 +31,6 @@ sub initPlugin {
}

# get configuration
my $modeList = $Foswiki::cfg{Plugins}{AutoTemplatePlugin}{Mode} || "rules, exist";
my $override = $Foswiki::cfg{Plugins}{AutoTemplatePlugin}{Override} || 0;
$debug = $Foswiki::cfg{Plugins}{AutoTemplatePlugin}{Debug} || 0;

Expand All @@ -55,17 +54,7 @@ sub initPlugin {
}

# get it
my $templateName = "";
foreach my $mode (split(/\s*,\s*/, $modeList)) {
if ( $mode eq "section" ) {
$templateName = _getTemplateFromSectionInclude( $web, $topic );
} elsif ( $mode eq "exist" ) {
$templateName = _getTemplateFromTemplateExistence( $web, $topic );
} elsif ( $mode eq "rules" ) {
$templateName = _getTemplateFromRules( $web, $topic );
}
last if $templateName;
}
my $templateName = getTemplateName($web, $topic);

# only set the view template if there is anything to set
return 1 unless $templateName;
Expand Down Expand Up @@ -98,6 +87,25 @@ sub initPlugin {
return 1;
}

sub getTemplateName {
my ($web, $topic) = @_;

my $templateName = "";
my $modeList = $Foswiki::cfg{Plugins}{AutoTemplatePlugin}{Mode} || "rules, exist";
foreach my $mode (split(/\s*,\s*/, $modeList)) {
if ( $mode eq "section" ) {
$templateName = _getTemplateFromSectionInclude( $web, $topic );
} elsif ( $mode eq "exist" ) {
$templateName = _getTemplateFromTemplateExistence( $web, $topic );
} elsif ( $mode eq "rules" ) {
$templateName = _getTemplateFromRules( $web, $topic );
}
last if $templateName;
}

return $templateName;
}

sub _getFormName {
my ($web, $topic) = @_;

Expand Down
2 changes: 1 addition & 1 deletion lib/Foswiki/Plugins/AutoTemplatePlugin/Config.spec
@@ -1,5 +1,5 @@
# ---+ Extensions
# ---++ AutoTemplate settings
# ---++ AutoTemplatePlugin
# This is the configuration used by the <b>AutoTemplatePlugin</b>.

# **BOOLEAN**
Expand Down

0 comments on commit f5f94a5

Please sign in to comment.