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
|
|
@ -63,6 +63,7 @@ sub definition {
|
|||
my $session = shift;
|
||||
my $definition = shift;
|
||||
my $i18n = WebGUI::International->new($session,"Asset_Snippet");
|
||||
my $t18n = WebGUI::International->new($session,'Asset_Template');
|
||||
my %properties;
|
||||
tie %properties, 'Tie::IxHash';
|
||||
%properties = (
|
||||
|
|
@ -94,13 +95,14 @@ sub definition {
|
|||
label => $i18n->get("cache timeout"),
|
||||
hoverHelp => $i18n->get("cache timeout help")
|
||||
},
|
||||
processAsTemplate=>{
|
||||
fieldType=>'yesNo',
|
||||
label=>$i18n->get('process as template'),
|
||||
hoverHelp=>$i18n->get('process as template description'),
|
||||
tab=>"properties",
|
||||
defaultValue=>0
|
||||
},
|
||||
templateParser => {
|
||||
fieldType => 'templateParser',
|
||||
allowNone => 1,
|
||||
label => $t18n->get('parser'),
|
||||
hoverHelp => $t18n->get('parser description'),
|
||||
tab => 'properties',
|
||||
defaultValue => '',
|
||||
},
|
||||
mimeType=>{
|
||||
tab=>"properties",
|
||||
hoverHelp=>$i18n->get('mimeType description'),
|
||||
|
|
@ -312,8 +314,10 @@ sub view {
|
|||
: $self->get('snippet')
|
||||
;
|
||||
$output = $self->getToolbar.$output if ($session->var->isAdminOn && !$calledAsWebMethod);
|
||||
if ($self->getValue("processAsTemplate")) {
|
||||
$output = WebGUI::Asset::Template->processRaw($session, $output, $self->get);
|
||||
if (my $parser = $self->getValue('templateParser')) {
|
||||
$output = WebGUI::Asset::Template->processRaw(
|
||||
$session, $output, $self->get, $parser
|
||||
);
|
||||
}
|
||||
WebGUI::Macro::process($session,\$output);
|
||||
unless ($noCache) {
|
||||
|
|
|
|||
|
|
@ -140,9 +140,8 @@ sub definition {
|
|||
defaultValue => 1,
|
||||
},
|
||||
parser => {
|
||||
noFormPost => 1,
|
||||
fieldType => 'selectBox',
|
||||
defaultValue => [$session->config->get("defaultTemplateParser")],
|
||||
fieldType => 'templateParser',
|
||||
defaultValue => $session->config->get('defaultTemplateParser'),
|
||||
},
|
||||
namespace => {
|
||||
fieldType => 'combo',
|
||||
|
|
@ -404,22 +403,12 @@ sub getEditForm {
|
|||
templatePreview.js
|
||||
);
|
||||
|
||||
if($config->get("templateParsers")){
|
||||
my @temparray = @{$config->get("templateParsers")};
|
||||
tie my %parsers, 'Tie::IxHash';
|
||||
while(my $a = shift @temparray){
|
||||
$parsers{$a} = $self->getParser($session, $a)->getName();
|
||||
}
|
||||
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->templateParser(
|
||||
name => 'parser',
|
||||
label => $i18n->get('parser'),
|
||||
hoverHelp => $i18n->get('parser description'),
|
||||
value => $self->getValue('parser'),
|
||||
);
|
||||
|
||||
$properties->jsonTable(
|
||||
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
|
||||
},
|
||||
|
||||
'Template Parser' => {
|
||||
message => q|Template Parser|,
|
||||
lastUpdated => 1301593691
|
||||
},
|
||||
|
||||
'391' => {
|
||||
message => q|Delete attached file.|,
|
||||
lastUpdated => 1031514049
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue