Snippets can now select a template parser
(instead of being restricted to the configured default)
This commit is contained in:
parent
3ad6c4eb3a
commit
3531c4d913
8 changed files with 197 additions and 34 deletions
|
|
@ -4,6 +4,8 @@
|
||||||
- fixed #12084: Greenportal links are sometimes white on white
|
- fixed #12084: Greenportal links are sometimes white on white
|
||||||
- rfe #618: Syndicated Content Asset: Make images in the downloaded RSS-feeds available in the template.
|
- rfe #618: Syndicated Content Asset: Make images in the downloaded RSS-feeds available in the template.
|
||||||
- fixed #12086: Shop Billing Address Unpopulated
|
- fixed #12086: Shop Billing Address Unpopulated
|
||||||
|
- Snippets can now select a template parser (instead of being restricted to
|
||||||
|
the configured default)
|
||||||
|
|
||||||
7.10.12
|
7.10.12
|
||||||
- fixed #12072: Product, related and accessory assets
|
- fixed #12072: Product, related and accessory assets
|
||||||
|
|
|
||||||
|
|
@ -32,6 +32,7 @@ my $session = start(); # this line required
|
||||||
|
|
||||||
# upgrade functions go here
|
# upgrade functions go here
|
||||||
addAutoPlayToCarousel( $session );
|
addAutoPlayToCarousel( $session );
|
||||||
|
addProcessorDropdownToSnippet( $session );
|
||||||
|
|
||||||
finish($session); # this line required
|
finish($session); # this line required
|
||||||
|
|
||||||
|
|
@ -56,6 +57,36 @@ sub addAutoPlayToCarousel {
|
||||||
print "DONE!\n" unless $quiet;
|
print "DONE!\n" unless $quiet;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#----------------------------------------------------------------------------
|
||||||
|
sub addProcessorDropdownToSnippet {
|
||||||
|
my $session = shift;
|
||||||
|
my $db = $session->db;
|
||||||
|
print "\tUpdating the Snippet table to add templateProcessor option..."
|
||||||
|
unless $quiet;
|
||||||
|
|
||||||
|
my $rows = $db->buildArrayRefOfHashRefs(q{
|
||||||
|
select assetId, revisionDate from snippet where processAsTemplate = 1
|
||||||
|
});
|
||||||
|
|
||||||
|
$db->write(q{
|
||||||
|
alter table snippet
|
||||||
|
drop column processAsTemplate,
|
||||||
|
add column templateParser char(255)
|
||||||
|
});
|
||||||
|
|
||||||
|
my $default = $session->config->get('defaultTemplateParser');
|
||||||
|
|
||||||
|
for my $row (@$rows) {
|
||||||
|
$db->write(q{
|
||||||
|
update snippet
|
||||||
|
set templateParser = ?
|
||||||
|
where assetId = ? and revisionDate = ?
|
||||||
|
}, [ $default, $row->{assetId}, $row->{revisionDate} ]);
|
||||||
|
}
|
||||||
|
|
||||||
|
print "Done!\n";
|
||||||
|
}
|
||||||
|
|
||||||
# -------------- DO NOT EDIT BELOW THIS LINE --------------------------------
|
# -------------- DO NOT EDIT BELOW THIS LINE --------------------------------
|
||||||
|
|
||||||
#----------------------------------------------------------------------------
|
#----------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
|
@ -63,6 +63,7 @@ sub definition {
|
||||||
my $session = shift;
|
my $session = shift;
|
||||||
my $definition = shift;
|
my $definition = shift;
|
||||||
my $i18n = WebGUI::International->new($session,"Asset_Snippet");
|
my $i18n = WebGUI::International->new($session,"Asset_Snippet");
|
||||||
|
my $t18n = WebGUI::International->new($session,'Asset_Template');
|
||||||
my %properties;
|
my %properties;
|
||||||
tie %properties, 'Tie::IxHash';
|
tie %properties, 'Tie::IxHash';
|
||||||
%properties = (
|
%properties = (
|
||||||
|
|
@ -94,13 +95,14 @@ sub definition {
|
||||||
label => $i18n->get("cache timeout"),
|
label => $i18n->get("cache timeout"),
|
||||||
hoverHelp => $i18n->get("cache timeout help")
|
hoverHelp => $i18n->get("cache timeout help")
|
||||||
},
|
},
|
||||||
processAsTemplate=>{
|
templateParser => {
|
||||||
fieldType=>'yesNo',
|
fieldType => 'templateParser',
|
||||||
label=>$i18n->get('process as template'),
|
allowNone => 1,
|
||||||
hoverHelp=>$i18n->get('process as template description'),
|
label => $t18n->get('parser'),
|
||||||
tab=>"properties",
|
hoverHelp => $t18n->get('parser description'),
|
||||||
defaultValue=>0
|
tab => 'properties',
|
||||||
},
|
defaultValue => '',
|
||||||
|
},
|
||||||
mimeType=>{
|
mimeType=>{
|
||||||
tab=>"properties",
|
tab=>"properties",
|
||||||
hoverHelp=>$i18n->get('mimeType description'),
|
hoverHelp=>$i18n->get('mimeType description'),
|
||||||
|
|
@ -312,8 +314,10 @@ sub view {
|
||||||
: $self->get('snippet')
|
: $self->get('snippet')
|
||||||
;
|
;
|
||||||
$output = $self->getToolbar.$output if ($session->var->isAdminOn && !$calledAsWebMethod);
|
$output = $self->getToolbar.$output if ($session->var->isAdminOn && !$calledAsWebMethod);
|
||||||
if ($self->getValue("processAsTemplate")) {
|
if (my $parser = $self->getValue('templateParser')) {
|
||||||
$output = WebGUI::Asset::Template->processRaw($session, $output, $self->get);
|
$output = WebGUI::Asset::Template->processRaw(
|
||||||
|
$session, $output, $self->get, $parser
|
||||||
|
);
|
||||||
}
|
}
|
||||||
WebGUI::Macro::process($session,\$output);
|
WebGUI::Macro::process($session,\$output);
|
||||||
unless ($noCache) {
|
unless ($noCache) {
|
||||||
|
|
|
||||||
|
|
@ -140,9 +140,8 @@ sub definition {
|
||||||
defaultValue => 1,
|
defaultValue => 1,
|
||||||
},
|
},
|
||||||
parser => {
|
parser => {
|
||||||
noFormPost => 1,
|
fieldType => 'templateParser',
|
||||||
fieldType => 'selectBox',
|
defaultValue => $session->config->get('defaultTemplateParser'),
|
||||||
defaultValue => [$session->config->get("defaultTemplateParser")],
|
|
||||||
},
|
},
|
||||||
namespace => {
|
namespace => {
|
||||||
fieldType => 'combo',
|
fieldType => 'combo',
|
||||||
|
|
@ -404,22 +403,12 @@ sub getEditForm {
|
||||||
templatePreview.js
|
templatePreview.js
|
||||||
);
|
);
|
||||||
|
|
||||||
if($config->get("templateParsers")){
|
$properties->templateParser(
|
||||||
my @temparray = @{$config->get("templateParsers")};
|
name => 'parser',
|
||||||
tie my %parsers, 'Tie::IxHash';
|
label => $i18n->get('parser'),
|
||||||
while(my $a = shift @temparray){
|
hoverHelp => $i18n->get('parser description'),
|
||||||
$parsers{$a} = $self->getParser($session, $a)->getName();
|
value => $self->getValue('parser'),
|
||||||
}
|
);
|
||||||
my $value = [$self->getValue("parser")];
|
|
||||||
$value = \[$config->get("defaultTemplateParser")] if(!$self->getValue("parser"));
|
|
||||||
$properties->selectBox(
|
|
||||||
-name=>"parser",
|
|
||||||
-options=>\%parsers,
|
|
||||||
-value=>$value,
|
|
||||||
-label=>$i18n->get('parser'),
|
|
||||||
-hoverHelp=>$i18n->get('parser description'),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
$properties->jsonTable(
|
$properties->jsonTable(
|
||||||
name => 'attachmentsJson',
|
name => 'attachmentsJson',
|
||||||
|
|
|
||||||
122
lib/WebGUI/Form/TemplateParser.pm
Normal file
122
lib/WebGUI/Form/TemplateParser.pm
Normal file
|
|
@ -0,0 +1,122 @@
|
||||||
|
package WebGUI::Form::TemplateParser;
|
||||||
|
|
||||||
|
=head1 LEGAL
|
||||||
|
|
||||||
|
-------------------------------------------------------------------
|
||||||
|
WebGUI is Copyright 2001-2009 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
|
||||||
|
-------------------------------------------------------------------
|
||||||
|
|
||||||
|
=cut
|
||||||
|
|
||||||
|
use strict;
|
||||||
|
use base 'WebGUI::Form::SelectBox';
|
||||||
|
use WebGUI::International;
|
||||||
|
use Tie::IxHash;
|
||||||
|
|
||||||
|
=head1 NAME
|
||||||
|
|
||||||
|
Package WebGUI::Form::TemplateParser
|
||||||
|
|
||||||
|
=head1 DESCRIPTION
|
||||||
|
|
||||||
|
A dropdown list for selecting a template parser.
|
||||||
|
|
||||||
|
=head1 SEE ALSO
|
||||||
|
|
||||||
|
This is a subclass of WebGUI::Form::SelectBox.
|
||||||
|
|
||||||
|
=head1 METHODS
|
||||||
|
|
||||||
|
The following methods are specifically available from this class. Check the superclass for additional methods.
|
||||||
|
|
||||||
|
=cut
|
||||||
|
|
||||||
|
#-------------------------------------------------------------------
|
||||||
|
|
||||||
|
=head2 areOptionsSettable
|
||||||
|
|
||||||
|
No, they aren't.
|
||||||
|
|
||||||
|
=cut
|
||||||
|
|
||||||
|
sub areOptionsSettable { 0 }
|
||||||
|
|
||||||
|
#----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
=head2 definition ( [ additionalTerms ] )
|
||||||
|
|
||||||
|
See the super class for additional details.
|
||||||
|
|
||||||
|
=head3 additionalTerms
|
||||||
|
|
||||||
|
The following additional parameters have been added via this sub class.
|
||||||
|
|
||||||
|
=head3 allowNone
|
||||||
|
|
||||||
|
Set to true if "None" is an acceptable option for this dropdown. Defaults to
|
||||||
|
false.
|
||||||
|
|
||||||
|
=head4 defaultValue
|
||||||
|
|
||||||
|
Defaults to the default parser selected in the config file
|
||||||
|
|
||||||
|
=cut
|
||||||
|
|
||||||
|
sub definition {
|
||||||
|
my ($class, $session, $definition) = @_;
|
||||||
|
push @{$definition ||= []}, {
|
||||||
|
allowNone => {
|
||||||
|
defaultValue => 0,
|
||||||
|
},
|
||||||
|
defaultValue => {
|
||||||
|
defaultValue => $session->config->get('defaultTemplateParser')
|
||||||
|
}
|
||||||
|
};
|
||||||
|
return $class->SUPER::definition($session, $definition);
|
||||||
|
}
|
||||||
|
|
||||||
|
#-------------------------------------------------------------------
|
||||||
|
|
||||||
|
=head2 getName ( session )
|
||||||
|
|
||||||
|
Returns the human readable name of this control.
|
||||||
|
|
||||||
|
=cut
|
||||||
|
|
||||||
|
sub getName {
|
||||||
|
my ($self, $session) = @_;
|
||||||
|
return WebGUI::International->new($session, 'WebGUI')->get('Template Parser');
|
||||||
|
}
|
||||||
|
|
||||||
|
#-------------------------------------------------------------------
|
||||||
|
|
||||||
|
=head2 getOptions
|
||||||
|
|
||||||
|
Called by the superclass to determine which options are presented.
|
||||||
|
|
||||||
|
=cut
|
||||||
|
|
||||||
|
sub getOptions {
|
||||||
|
my $self = shift;
|
||||||
|
my $session = $self->session;
|
||||||
|
tie my %o, 'Tie::IxHash';
|
||||||
|
if ($self->get('allowNone')) {
|
||||||
|
$o{''} = WebGUI::International->new($session, 'WebGUI')->get('881');
|
||||||
|
}
|
||||||
|
return \%o unless my $parsers = $session->config->get('templateParsers');
|
||||||
|
|
||||||
|
for my $class (@$parsers) {
|
||||||
|
my $parser = WebGUI::Asset::Template->getParser($session, $class);
|
||||||
|
$o{$class} = $parser->getName;
|
||||||
|
}
|
||||||
|
|
||||||
|
return \%o;
|
||||||
|
}
|
||||||
|
|
||||||
|
1;
|
||||||
|
|
@ -520,6 +520,11 @@ our $I18N = {
|
||||||
lastUpdated => 1133087205
|
lastUpdated => 1133087205
|
||||||
},
|
},
|
||||||
|
|
||||||
|
'Template Parser' => {
|
||||||
|
message => q|Template Parser|,
|
||||||
|
lastUpdated => 1301593691
|
||||||
|
},
|
||||||
|
|
||||||
'391' => {
|
'391' => {
|
||||||
message => q|Delete attached file.|,
|
message => q|Delete attached file.|,
|
||||||
lastUpdated => 1031514049
|
lastUpdated => 1031514049
|
||||||
|
|
|
||||||
|
|
@ -33,7 +33,7 @@ isa_ok($snippet, 'WebGUI::Asset::Snippet');
|
||||||
# Test to see if we can set values
|
# Test to see if we can set values
|
||||||
my $properties = {
|
my $properties = {
|
||||||
cacheTimeout => 124,
|
cacheTimeout => 124,
|
||||||
processAsTemplate => 1,
|
templateParser => 'WebGUI::Asset::Template::HTMLTemplate',
|
||||||
mimeType => 'text/plain',
|
mimeType => 'text/plain',
|
||||||
snippet => "Gooey's milkshake brings all the girls to the yard...",
|
snippet => "Gooey's milkshake brings all the girls to the yard...",
|
||||||
};
|
};
|
||||||
|
|
@ -74,9 +74,9 @@ isnt ($editOutput, undef, 'www_edit returns something');
|
||||||
|
|
||||||
$snippet->update({
|
$snippet->update({
|
||||||
title => "authMethod",
|
title => "authMethod",
|
||||||
processAsTemplate => 1,
|
templateParser => 'WebGUI::Asset::Template::TemplateToolkit',
|
||||||
cacheTimeout => 1,
|
cacheTimeout => 1,
|
||||||
snippet => q|^SQL(select value from settings where name="<tmpl_var title>");|
|
snippet => q|^SQL(select value from settings where name="[% title %]");|
|
||||||
});
|
});
|
||||||
|
|
||||||
WebGUI::Test->originalConfig('macros');
|
WebGUI::Test->originalConfig('macros');
|
||||||
|
|
|
||||||
|
|
@ -23,6 +23,8 @@ use Test::Exception;
|
||||||
use JSON qw{ from_json };
|
use JSON qw{ from_json };
|
||||||
|
|
||||||
my $session = WebGUI::Test->session;
|
my $session = WebGUI::Test->session;
|
||||||
|
my $default = $session->config->get('defaultTemplateParser');
|
||||||
|
my $ht = 'WebGUI::Asset::Template::HTMLTemplate';
|
||||||
|
|
||||||
my $list = WebGUI::Asset::Template->getList($session);
|
my $list = WebGUI::Asset::Template->getList($session);
|
||||||
cmp_deeply($list, {}, 'getList with no classname returns an empty hashref');
|
cmp_deeply($list, {}, 'getList with no classname returns an empty hashref');
|
||||||
|
|
@ -33,16 +35,19 @@ my %var = (
|
||||||
conditional=>1,
|
conditional=>1,
|
||||||
loop=>[{},{},{},{},{}]
|
loop=>[{},{},{},{},{}]
|
||||||
);
|
);
|
||||||
my $output = WebGUI::Asset::Template->processRaw($session,$tmplText,\%var);
|
my $output = WebGUI::Asset::Template->processRaw($session,$tmplText,\%var, $ht);
|
||||||
ok($output =~ m/\bAAAAA\b/, "processRaw() - variables");
|
ok($output =~ m/\bAAAAA\b/, "processRaw() - variables");
|
||||||
ok($output =~ m/true/, "processRaw() - conditionals");
|
ok($output =~ m/true/, "processRaw() - conditionals");
|
||||||
ok($output =~ m/\s(?:XY){5}\s/, "processRaw() - loops");
|
ok($output =~ m/\s(?:XY){5}\s/, "processRaw() - loops");
|
||||||
|
|
||||||
my $importNode = WebGUI::Asset::Template->getImportNode($session);
|
my $importNode = WebGUI::Asset::Template->getImportNode($session);
|
||||||
my $template = $importNode->addChild({className=>"WebGUI::Asset::Template", title=>"test", url=>"testingtemplates", template=>$tmplText, namespace=>'WebGUI Test Template'});
|
|
||||||
|
my $template = $importNode->addChild({className=>"WebGUI::Asset::Template"});
|
||||||
|
is($template->get('parser'), $default, "default parser is $default");
|
||||||
|
|
||||||
|
$template = $importNode->addChild({className=>"WebGUI::Asset::Template", title=>"test", url=>"testingtemplates", template=>$tmplText, namespace=>'WebGUI Test Template',parser=>$ht});
|
||||||
isa_ok($template, 'WebGUI::Asset::Template', "creating a template");
|
isa_ok($template, 'WebGUI::Asset::Template', "creating a template");
|
||||||
|
|
||||||
is($template->get('parser'), 'WebGUI::Asset::Template::HTMLTemplate', 'default parser is HTMLTemplate');
|
|
||||||
|
|
||||||
$var{variable} = "BBBBB";
|
$var{variable} = "BBBBB";
|
||||||
$output = $template->process(\%var);
|
$output = $template->process(\%var);
|
||||||
|
|
@ -111,6 +116,7 @@ my $template3 = $importNode->addChild({
|
||||||
title => 'headBlock test',
|
title => 'headBlock test',
|
||||||
headBlock => "tag1 tag2 tag3",
|
headBlock => "tag1 tag2 tag3",
|
||||||
template => "this is a template",
|
template => "this is a template",
|
||||||
|
parser => $ht,
|
||||||
}, undef, time()-5);
|
}, undef, time()-5);
|
||||||
|
|
||||||
ok(!$template3->get('headBlock'), 'headBlock is empty');
|
ok(!$template3->get('headBlock'), 'headBlock is empty');
|
||||||
|
|
@ -205,6 +211,7 @@ my $trashTemplate = $importNode->addChild({
|
||||||
className => "WebGUI::Asset::Template",
|
className => "WebGUI::Asset::Template",
|
||||||
title => 'Trash template',
|
title => 'Trash template',
|
||||||
template => q|Trash Trash Trash Trash|,
|
template => q|Trash Trash Trash Trash|,
|
||||||
|
parser => $ht,
|
||||||
});
|
});
|
||||||
|
|
||||||
$trashTemplate->trash;
|
$trashTemplate->trash;
|
||||||
|
|
@ -229,6 +236,7 @@ my $brokenTemplate = $importNode->addChild({
|
||||||
className => "WebGUI::Asset::Template",
|
className => "WebGUI::Asset::Template",
|
||||||
title => 'Broken template',
|
title => 'Broken template',
|
||||||
template => q|<tmpl_if unclosedIf>If clause with no ending tag|,
|
template => q|<tmpl_if unclosedIf>If clause with no ending tag|,
|
||||||
|
parser => $ht,
|
||||||
});
|
});
|
||||||
|
|
||||||
WebGUI::Test->interceptLogging;
|
WebGUI::Test->interceptLogging;
|
||||||
|
|
@ -251,6 +259,7 @@ my $userStyleTemplate = $importNode->addChild({
|
||||||
url => "ufs",
|
url => "ufs",
|
||||||
template => "user function style",
|
template => "user function style",
|
||||||
namespace => 'WebGUI Test Template',
|
namespace => 'WebGUI Test Template',
|
||||||
|
parser => $ht,
|
||||||
});
|
});
|
||||||
|
|
||||||
my $someOtherTemplate = $importNode->addChild({
|
my $someOtherTemplate = $importNode->addChild({
|
||||||
|
|
@ -259,6 +268,7 @@ my $someOtherTemplate = $importNode->addChild({
|
||||||
url => "sot",
|
url => "sot",
|
||||||
template => "some other template",
|
template => "some other template",
|
||||||
namespace => 'WebGUI Test Template',
|
namespace => 'WebGUI Test Template',
|
||||||
|
parser => $ht,
|
||||||
});
|
});
|
||||||
|
|
||||||
$session->setting->set('userFunctionStyleId', $userStyleTemplate->getId);
|
$session->setting->set('userFunctionStyleId', $userStyleTemplate->getId);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue