Changed the Help so that chapters with only 1 page are directly linked, saving a click.
Added pluggable template parser docs. From the dev list, changed HTMLTemplateExpr to translate all dots in template variables to underscores, since EXPR's don't do dots, just like TemplateToolkit.
This commit is contained in:
parent
8905b7252c
commit
0b1e077f69
14 changed files with 319 additions and 4 deletions
|
|
@ -6,6 +6,12 @@
|
|||
- change: made all LWP user agents use env_proxy
|
||||
- Help: If a Help Chapter only has 1 page, then in the TOC view it links
|
||||
right to the page instead of the Chapter.
|
||||
- fix: HTML::Template::Expr templates would not handle template variables
|
||||
with dots in them. Added a fix to the template plugin so that dots are
|
||||
translated to underscores automatically in submitted template variables.
|
||||
Templates will still need to be manually updated.
|
||||
- Help: Added pluggable docs for template plugins, and added a new tab
|
||||
to the Help that lists template parser docs.
|
||||
|
||||
7.1.3
|
||||
- fix: SQLReport now returns error if can't find DatabaseLink
|
||||
|
|
|
|||
|
|
@ -19,6 +19,25 @@ use base 'WebGUI::Asset::Template::Parser';
|
|||
use HTML::Template::Expr;
|
||||
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
sub _rewriteVars { # replace dots with underscrores in keys (except in keys that aren't usable as variables (URLs etc.))
|
||||
my $vars = shift;
|
||||
foreach my $key (keys %$vars){
|
||||
my $newKey = $key;
|
||||
$newKey =~ s/\./_/g if $newKey !~ /\//;
|
||||
if(ref $vars->{$key} eq 'HASH'){
|
||||
$vars->{$newKey} = _rewriteVars($vars->{$key});
|
||||
delete $vars->{$key} if($key ne $newKey);
|
||||
}else{
|
||||
if($key ne $newKey){
|
||||
$vars->{$newKey} = $vars->{$key};
|
||||
delete $vars->{$key};
|
||||
}
|
||||
}
|
||||
}
|
||||
return $vars;
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 getName ( )
|
||||
|
|
@ -62,7 +81,7 @@ sub process {
|
|||
strict=>0);
|
||||
};
|
||||
unless ($@) {
|
||||
$t->param(%{$vars});
|
||||
$t->param(%{_rewriteVars($vars)});
|
||||
return $t->output;
|
||||
} else {
|
||||
$class->session->errorHandler->error("Error in template. ".$@);
|
||||
|
|
|
|||
|
|
@ -149,6 +149,71 @@ our $HELP = {
|
|||
]
|
||||
},
|
||||
|
||||
'template parsers list' => {
|
||||
title => 'template parsers list title',
|
||||
body => sub {
|
||||
my $session = shift;
|
||||
my $dir = join '/', $session->config->getWebguiRoot,"lib","WebGUI","Asset","Template";
|
||||
opendir (DIR,$dir) or $session->errorHandler->fatal("Can't open Macro directory: $dir!");
|
||||
my @plugins = map { s/\.pm//; $_; }
|
||||
grep { $_ ne "Parser.pm" }
|
||||
grep { /\.pm$/ }
|
||||
readdir(DIR); ##list of namespaces
|
||||
closedir(DIR);
|
||||
|
||||
##Build list of enabled macros, by namespace, by reversing session hash:
|
||||
my @enabledPlugins = map { s/^WebGUI::Asset::Template:://; $_ } @{ $session->config->get("templateParsers") };
|
||||
my $defaultParser = $session->config->get('defaultTemplateParser');
|
||||
$defaultParser =~ s/^WebGUI::Asset::Template:://;
|
||||
my %enabledPlugins = map { $_ => 1 } @enabledPlugins;
|
||||
|
||||
my $i18n = WebGUI::International->new($session, 'Asset_Template');
|
||||
my $yes = $i18n->get(138, 'WebGUI');
|
||||
my $no = $i18n->get(139, 'WebGUI');
|
||||
use Data::Dumper;
|
||||
$session->errorHandler->warn(Dumper \@enabledPlugins);
|
||||
$session->errorHandler->warn(Dumper \@plugins);
|
||||
my $plugin_table =
|
||||
join "\n",
|
||||
map { join '', '<tr><td>', $_,
|
||||
'</td><td>',
|
||||
($enabledPlugins{$_} ? $yes : $no),
|
||||
'</td><td>',
|
||||
($_ eq $defaultParser ? $yes : $no),
|
||||
'</td>',
|
||||
} @plugins;
|
||||
|
||||
$plugin_table =
|
||||
join("\n",
|
||||
$i18n->get('template parsers list body'),
|
||||
'<table border="1" cellpadding="3">',
|
||||
'<tr><th>',$i18n->get('plugin name'),
|
||||
'</th><th>',
|
||||
$i18n->get('plugin enabled header'),
|
||||
'</th><th>',
|
||||
$i18n->get('default parser'),
|
||||
'</th></tr>',$plugin_table,'</table>');
|
||||
},
|
||||
fields => [],
|
||||
related => sub { ##Hey, you gotta pass in the session var, right?
|
||||
my $session = shift;
|
||||
sort { $a->{tag} cmp $b->{tag} }
|
||||
map {
|
||||
s/^WebGUI::Asset::Template:://;
|
||||
$tag = $_;
|
||||
$tag =~ s/^[a-zA-Z]+_//; #Remove initial shortcuts
|
||||
$tag =~ s/([A-Z]+(?![a-z]))/$1 /g; #Separate acronyms
|
||||
$tag =~ s/([a-z])([A-Z])/$1 $2/g; #Separate studly caps
|
||||
$tag =~ s/\s+$//;
|
||||
$tag = lc $tag;
|
||||
$namespace = join '', 'Template_', $_;
|
||||
{ tag => $tag,
|
||||
namespace => $namespace }
|
||||
}
|
||||
@{ $session->config->get("templateParsers") }
|
||||
},
|
||||
,
|
||||
},
|
||||
};
|
||||
|
||||
1;
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ our $HELP = {
|
|||
my $session = shift;
|
||||
my $dir = join '/', $session->config->getWebguiRoot,"lib","WebGUI","Macro";
|
||||
opendir (DIR,$dir) or $session->errorHandler->fatal("Can't open Macro directory: $dir!");
|
||||
my @macros = map { s/Macro_//; s/\.pm//; $_; }
|
||||
my @macros = map { s/\.pm//; $_; }
|
||||
grep { /\.pm$/ }
|
||||
readdir(DIR); ##list of namespaces
|
||||
closedir(DIR);
|
||||
|
|
|
|||
17
lib/WebGUI/Help/Template_HTMLTemplate.pm
Normal file
17
lib/WebGUI/Help/Template_HTMLTemplate.pm
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
package WebGUI::Help::Template_HTMLTemplate;
|
||||
|
||||
our $HELP = { ##hashref of hashes
|
||||
'html template' => {
|
||||
title => 'html template title',
|
||||
body => 'html template body',
|
||||
related => [
|
||||
{
|
||||
tag => 'template language',
|
||||
namespace => 'Asset_Template',
|
||||
},
|
||||
],
|
||||
},
|
||||
|
||||
};
|
||||
|
||||
1; ##All perl modules must return true
|
||||
13
lib/WebGUI/Help/Template_HTMLTemplateExpr.pm
Normal file
13
lib/WebGUI/Help/Template_HTMLTemplateExpr.pm
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
package WebGUI::Help::Template_HTMLTemplateExpr;
|
||||
|
||||
our $HELP = { ##hashref of hashes
|
||||
'html template expr' => {
|
||||
title => 'html template expr title',
|
||||
body => 'html template expr body',
|
||||
related => [
|
||||
],
|
||||
},
|
||||
|
||||
};
|
||||
|
||||
1; ##All perl modules must return true
|
||||
13
lib/WebGUI/Help/Template_TemplateToolkit.pm
Normal file
13
lib/WebGUI/Help/Template_TemplateToolkit.pm
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
package WebGUI::Help::Template_TemplateToolkit;
|
||||
|
||||
our $HELP = { ##hashref of hashes
|
||||
'template toolkit' => {
|
||||
title => 'template toolkit title',
|
||||
body => 'template toolkit body',
|
||||
related => [
|
||||
],
|
||||
},
|
||||
|
||||
};
|
||||
|
||||
1; ##All perl modules must return true
|
||||
|
|
@ -211,6 +211,9 @@ sub _getHelpName {
|
|||
elsif ($file =~ /^Workflow_Activity_/) {
|
||||
$helpName = 'activityName';
|
||||
}
|
||||
elsif ($file =~ /^Template_/) {
|
||||
$helpName = 'templateParserName';
|
||||
}
|
||||
else {
|
||||
$helpName = 'topicName';
|
||||
}
|
||||
|
|
@ -435,6 +438,10 @@ sub www_viewHelpTOC {
|
|||
label => $i18n->get('topicName', 'Workflow'),
|
||||
uiLevel => 1,
|
||||
},
|
||||
templ => {
|
||||
label => $i18n->get('template parsers', 'Asset_Template'),
|
||||
uiLevel => 1,
|
||||
},
|
||||
);
|
||||
|
||||
my @files = _getHelpFilesList($session,);
|
||||
|
|
@ -449,8 +456,6 @@ sub www_viewHelpTOC {
|
|||
my $helpTopic = _loadHelp($session, "WebGUI::Help::".$moduleName);
|
||||
my @helpEntries = keys %{ $helpTopic };
|
||||
my $link;
|
||||
$session->errorHandler->warn("MOD: ". $moduleName. " ".scalar(@helpEntries));
|
||||
$session->errorHandler->warn("MOD: ". $moduleName);
|
||||
if (scalar @helpEntries > 1) {
|
||||
##Chapter
|
||||
$link = _linkTOC($session, $moduleName);
|
||||
|
|
|
|||
|
|
@ -439,6 +439,36 @@ be on the right side of the page.</p>
|
|||
lastUpdated => 1146456174,
|
||||
},
|
||||
|
||||
'plugin name' => {
|
||||
message => q|Parser Name|,
|
||||
lastUpdated => 1162087997,
|
||||
},
|
||||
|
||||
'plugin enabled header' => {
|
||||
message => q|Enabled?|,
|
||||
lastUpdated => 1162088018,
|
||||
},
|
||||
|
||||
'template parsers' => {
|
||||
message => q|Template Parsers|,
|
||||
lastUpdated => 1162088018,
|
||||
},
|
||||
|
||||
'default parser' => {
|
||||
message => q|Default Parser|,
|
||||
lastUpdated => 1162088018,
|
||||
},
|
||||
|
||||
'template parsers list title' => {
|
||||
message => q|List of Template Parsers|,
|
||||
lastUpdated => 1162088018,
|
||||
},
|
||||
|
||||
'template parsers list body' => {
|
||||
message => q|<p>The following template parsers are installed on your site and may be enabled for use.</p>|,
|
||||
lastUpdated => 1162088018,
|
||||
},
|
||||
|
||||
};
|
||||
|
||||
1;
|
||||
|
|
|
|||
23
lib/WebGUI/i18n/English/Template_HTMLTemplate.pm
Normal file
23
lib/WebGUI/i18n/English/Template_HTMLTemplate.pm
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
package WebGUI::i18n::English::Template_HTMLTemplate;
|
||||
|
||||
our $I18N = {
|
||||
'html template title' => {
|
||||
message => q|HTML Template|,
|
||||
lastUpdated => 1162085513,
|
||||
context => q|Name of the HTML::Template module|
|
||||
},
|
||||
|
||||
'html template body' => {
|
||||
message => q|<p>HTML Template is the default template parser inside of WebGUI. All of the template documentation in the online help is written using HTML Template syntax.</p>|,
|
||||
lastUpdated => 1162085513,
|
||||
context => q|Explanation of HTML Template usage in WebGUI.|
|
||||
},
|
||||
|
||||
'templateParserName' => {
|
||||
message => q|HTML Template|,
|
||||
lastUpdated => 1162085447,
|
||||
},
|
||||
|
||||
};
|
||||
|
||||
1;
|
||||
25
lib/WebGUI/i18n/English/Template_HTMLTemplateExpr.pm
Normal file
25
lib/WebGUI/i18n/English/Template_HTMLTemplateExpr.pm
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
package WebGUI::i18n::English::Template_HTMLTemplateExpr;
|
||||
|
||||
our $I18N = {
|
||||
'html template expr title' => {
|
||||
message => q|HTML Template Expr|,
|
||||
lastUpdated => 1162085513,
|
||||
context => q|Name of the HTML::Template::Expr module|
|
||||
},
|
||||
|
||||
'html template expr body' => {
|
||||
message => q|<p>HTML Template Expr is an extension to HTML Template that adds expressions to the language. <a href="http://search.cpan.org/perldoc?HTML%3A%3ATemplate%3A%3AExpr">Documentation for this extension</a> is available online.</p>
|
||||
<p>The syntax of template variables in HTML Template Expr is slightly different from HTML Template. Any WebGUI template variables that contains a dot '.', should be chanaged to use an underscore instead '_'.</p>
|
||||
|,
|
||||
lastUpdated => 1162085513,
|
||||
context => q|Explanation of HTML Template Expr usage in WebGUI.|
|
||||
},
|
||||
|
||||
'templateParserName' => {
|
||||
message => q|HTML Template with expressions|,
|
||||
lastUpdated => 1162085447,
|
||||
},
|
||||
|
||||
};
|
||||
|
||||
1;
|
||||
25
lib/WebGUI/i18n/English/Template_TemplateToolkit.pm
Normal file
25
lib/WebGUI/i18n/English/Template_TemplateToolkit.pm
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
package WebGUI::i18n::English::Template_TemplateToolkit;
|
||||
|
||||
our $I18N = {
|
||||
'template toolkit title' => {
|
||||
message => q|Template Toolkit|,
|
||||
lastUpdated => 1162085513,
|
||||
context => q|Name of the Template::Toolkit module|
|
||||
},
|
||||
|
||||
'template toolkit body' => {
|
||||
message => q|<p>Template Toolkit is is a collection of modules which implement a fast, flexible, powerful and extensible template processing system. <a href="http://search.cpan.org/perldoc?Template%3A%3ATooolkit">Documentation for Template Toolkit</a> is available online.</p>
|
||||
<p>The syntax of template variables in Template Toolkit is slightly different from HTML Template. Any WebGUI template variables that contains a dot '.', should be chanaged to use an underscore instead '_'.</p>
|
||||
|,
|
||||
lastUpdated => 1162085513,
|
||||
context => q|Explanation of Template Toolkit usage in WebGUI.|
|
||||
},
|
||||
|
||||
'templateParserName' => {
|
||||
message => q|Template Toolkit|,
|
||||
lastUpdated => 1162086264,
|
||||
},
|
||||
|
||||
};
|
||||
|
||||
1;
|
||||
|
|
@ -16,6 +16,7 @@ our $I18N = { ##hashref of hashes
|
|||
#If the help file documents an Asset, it must include an assetName key
|
||||
#If the help file documents an Macro, it must include an macroName key
|
||||
#If the help file documents a Workflow Activity, it must include an activityName key
|
||||
#If the help file documents a Template Parser, it must include an templateParserName key
|
||||
#For all other types, use topicName
|
||||
'assetName' => {
|
||||
message => q|My Asset|,
|
||||
|
|
|
|||
73
t/Asset/Template/HTMLTemplateExpr.t
Normal file
73
t/Asset/Template/HTMLTemplateExpr.t
Normal file
|
|
@ -0,0 +1,73 @@
|
|||
#-------------------------------------------------------------------
|
||||
# WebGUI is Copyright 2001-2006 Plain Black Corporation.
|
||||
#-------------------------------------------------------------------
|
||||
# Please read the legal notices (docs/legal.txt) and the license
|
||||
# (docs/license.txt) that came with this distribution before using
|
||||
# this software.
|
||||
#-------------------------------------------------------------------
|
||||
# http://www.plainblack.com info@plainblack.com
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
use FindBin;
|
||||
use strict;
|
||||
use lib "$FindBin::Bin/../../lib";
|
||||
use HTML::TokeParser;
|
||||
|
||||
use WebGUI::Test;
|
||||
use WebGUI::Session;
|
||||
use WebGUI::Asset;
|
||||
use WebGUI::VersionTag;
|
||||
use WebGUI;
|
||||
|
||||
use Test::More;
|
||||
|
||||
my $num_tests = 3;
|
||||
plan tests => 2 + $num_tests;
|
||||
|
||||
my $session = WebGUI::Test->session;
|
||||
|
||||
# put your tests here
|
||||
|
||||
my $module = use_ok('HTML::Template::Expr', 'Loaded HTML::Template::Expr');
|
||||
my $plugin = use_ok('WebGUI::Asset::Template::HTMLTemplateExpr', 'Loaded WebGUI::Asset::Template::HTMLTemplateExpr plugin');
|
||||
|
||||
my ($versionTag, $template);
|
||||
my $originalParsers = $session->config->get('templateParsers');
|
||||
|
||||
SKIP: {
|
||||
skip $num_tests, "HTML::Template::Expr or plugin not loaded" unless $module and $plugin;
|
||||
|
||||
$session->config->set('templateParsers', ['WebGUI::Asset::Template::HTMLTemplate', 'WebGUI::Asset::Template::HTMLTemplateExpr',] );
|
||||
($versionTag, $template) = setup_assets($session);
|
||||
my $templateOutput = $template->process({ "foo.bar" => "baz", "number.value" => 2 });
|
||||
my $companyName = $session->config->get('companyName');
|
||||
like($templateOutput, qr/NAME=$companyName/, "session variable with underscores");
|
||||
like($templateOutput, qr/FOOBAR=baz/, "explicit variable with dots");
|
||||
like($templateOutput, qr/EQN=4/, "explicit variable with dots in expr");
|
||||
}
|
||||
|
||||
sub setup_assets {
|
||||
my $session = shift;
|
||||
my $importNode = WebGUI::Asset->getImportNode($session);
|
||||
my $versionTag = WebGUI::VersionTag->getWorking($session);
|
||||
$versionTag->set({name=>"HTMLTemplateExpr test"});
|
||||
my $properties = {
|
||||
title => 'HTML Template Expr test',
|
||||
className => 'WebGUI::Asset::Template',
|
||||
url => 'dotted',
|
||||
parser => 'WebGUI::Asset::Template::HTMLTemplateExpr',
|
||||
id => 'htmltemplateexpr000001',
|
||||
# '1234567890123456789012'
|
||||
template => q!NAME=<tmpl_var session_setting_companyName>\nFOOBAR=<tmpl_var name="foo_bar">\nEQN=<tmpl_var EXPR="2+number_value">!,
|
||||
};
|
||||
my $template = $importNode->addChild($properties, $properties->{id});
|
||||
$versionTag->commit;
|
||||
return ($versionTag, $template);
|
||||
}
|
||||
|
||||
END {
|
||||
$session->config->set('templateParsers', $originalParsers);
|
||||
if (defined $versionTag and ref $versionTag eq 'WebGUI::VersionTag') {
|
||||
$versionTag->rollback;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue