Conversion from static to Moose for Snippet.
This commit is contained in:
parent
22ff856027
commit
1af2acbc9d
1 changed files with 85 additions and 82 deletions
|
|
@ -15,60 +15,87 @@ package WebGUI::Asset::Snippet;
|
||||||
=cut
|
=cut
|
||||||
|
|
||||||
use strict;
|
use strict;
|
||||||
use base 'WebGUI::Asset';
|
use WebGUI::Definition::Asset;
|
||||||
|
extends 'WebGUI::Asset';
|
||||||
use WebGUI::Asset::Template;
|
use WebGUI::Asset::Template;
|
||||||
use WebGUI::Macro;
|
use WebGUI::Macro;
|
||||||
use HTML::Packer;
|
use HTML::Packer;
|
||||||
use JavaScript::Packer;
|
use JavaScript::Packer;
|
||||||
use CSS::Packer;
|
use CSS::Packer;
|
||||||
use WebGUI::Definition::Asset (
|
|
||||||
properties => [
|
attribute assetName => ['assetName','Asset_Snippet'],
|
||||||
snippet=>{
|
attribute uiLevel => 5,
|
||||||
fieldType =>'codearea',
|
attribute icon => 'snippet.gif',
|
||||||
tab =>"properties",
|
attribute tableName => 'snippet',
|
||||||
label =>['assetName','Asset_Snippet'],
|
|
||||||
hoverHelp =>['snippet description','Asset_Snippet'],
|
property snippet => (
|
||||||
defaultValue =>undef,
|
fieldType => 'codearea',
|
||||||
},
|
tab => "properties",
|
||||||
snippetPacked => {
|
label => ['assetName','Asset_Snippet'],
|
||||||
fieldType => "hidden",
|
hoverHelp => ['snippet description','Asset_Snippet'],
|
||||||
defaultValue => undef,
|
defaultValue => undef,
|
||||||
noFormPost => 1,
|
);
|
||||||
},
|
around snippet => sub {
|
||||||
usePacked => {
|
my $orig = shift;
|
||||||
tab => 'properties',
|
my $self = shift;
|
||||||
fieldType => 'yesNo',
|
if (@_ > 1) {
|
||||||
label => ['usePacked label','Asset_Snippet'],
|
my $packed = $_[0];
|
||||||
hoverHelp => ['usePacked description','Asset_Snippet'],
|
if ( $self->mimeType eq "text/html" ) {
|
||||||
defaultValue => 0,
|
HTML::Packer::minify( \$packed, {
|
||||||
},
|
remove_comments => 1,
|
||||||
cacheTimeout => {
|
remove_newlines => 1,
|
||||||
tab => "display",
|
do_javascript => "shrink",
|
||||||
fieldType => "interval",
|
do_stylesheet => "minify",
|
||||||
defaultValue => 3600,
|
} );
|
||||||
uiLevel => 8,
|
}
|
||||||
label => ["cache timeout",'Asset_Snippet'],
|
elsif ( $self->mimeType eq "text/css" ) {
|
||||||
hoverHelp => ["cache timeout help",'Asset_Snippet'],
|
CSS::Packer::minify( \$packed, {
|
||||||
},
|
compress => 'minify',
|
||||||
processAsTemplate=>{
|
});
|
||||||
fieldType =>'yesNo',
|
}
|
||||||
label =>['process as template','Asset_Snippet'],
|
elsif ( $self->mimeType eq 'text/javascript' ) {
|
||||||
hoverHelp =>['process as template description','Asset_Snippet'],
|
JavaScript::Packer::minify( \$packed, {
|
||||||
tab =>"properties",
|
compress => "shrink",
|
||||||
defaultValue =>0
|
});
|
||||||
},
|
}
|
||||||
mimeType=>{
|
$self->snippetPacked($packed);
|
||||||
tab =>"properties",
|
}
|
||||||
hoverHelp =>['mimeType description','Asset_Snippet'],
|
$self->$orig(@_);
|
||||||
label =>['mimeType','Asset_Snippet'],
|
};
|
||||||
fieldType =>'mimeType',
|
|
||||||
defaultValue =>'text/html'
|
property snippetPacked => (
|
||||||
},
|
fieldType => "hidden",
|
||||||
],
|
defaultValue => undef,
|
||||||
assetName =>['assetName','Asset_Snippet'],
|
noFormPost => 1,
|
||||||
uiLevel => 5,
|
);
|
||||||
icon =>'snippet.gif',
|
property usePacked => (
|
||||||
tableName =>'snippet',
|
tab => 'properties',
|
||||||
|
fieldType => 'yesNo',
|
||||||
|
label => ['usePacked label','Asset_Snippet'],
|
||||||
|
hoverHelp => ['usePacked description','Asset_Snippet'],
|
||||||
|
defaultValue => 0,
|
||||||
|
);
|
||||||
|
property cacheTimeout => (
|
||||||
|
tab => "display",
|
||||||
|
fieldType => "interval",
|
||||||
|
defaultValue => 3600,
|
||||||
|
uiLevel => 8,
|
||||||
|
label => ["cache timeout",'Asset_Snippet'],
|
||||||
|
hoverHelp => ["cache timeout help",'Asset_Snippet'],
|
||||||
|
);
|
||||||
|
property processAsTemplate => (
|
||||||
|
fieldType => 'yesNo',
|
||||||
|
label => ['process as template','Asset_Snippet'],
|
||||||
|
hoverHelp => ['process as template description','Asset_Snippet'],
|
||||||
|
tab => "properties",
|
||||||
|
defaultValue => 0,
|
||||||
|
);
|
||||||
|
property mimeType => (
|
||||||
|
tab => "properties",
|
||||||
|
hoverHelp => ['mimeType description','Asset_Snippet'],
|
||||||
|
label => ['mimeType','Asset_Snippet'],
|
||||||
|
fieldType => 'mimeType',
|
||||||
|
defaultValue => 'text/html',
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -78,13 +105,16 @@ Package WebGUI::Asset::Snippet
|
||||||
|
|
||||||
=head1 DESCRIPTION
|
=head1 DESCRIPTION
|
||||||
|
|
||||||
Provides a mechanism to publish arbitrary code snippets to WebGUI for reuse in other pages. Can be used for things like HTML segments, javascript, and cascading style sheets. You can also specify the MIME type of the snippet, allowing you to serve XML, CSS and other text files directly from the WebGUI asset system and have browsers recognize them correctly.
|
Provides a mechanism to publish arbitrary code snippets to WebGUI for reuse
|
||||||
|
in other pages. Can be used for things like HTML segments, javascript, and
|
||||||
|
cascading style sheets. You can also specify the MIME type of the snippet,
|
||||||
|
allowing you to serve XML, CSS and other text files directly from the WebGUI
|
||||||
|
asset system and have browsers recognize them correctly.
|
||||||
|
|
||||||
=head1 SYNOPSIS
|
=head1 SYNOPSIS
|
||||||
|
|
||||||
use WebGUI::Asset::Snippet;
|
use WebGUI::Asset::Snippet;
|
||||||
|
|
||||||
|
|
||||||
=head1 METHODS
|
=head1 METHODS
|
||||||
|
|
||||||
These methods are available from this class:
|
These methods are available from this class:
|
||||||
|
|
@ -204,33 +234,6 @@ If specified, sets the value, and also packs the content and inserts it into pac
|
||||||
|
|
||||||
=cut
|
=cut
|
||||||
|
|
||||||
sub snippet {
|
|
||||||
my ( $self, $unpacked ) = @_;
|
|
||||||
if (@_ > 1) {
|
|
||||||
my $packed = $unpacked;
|
|
||||||
if ( $self->mimeType eq "text/html" ) {
|
|
||||||
HTML::Packer::minify( \$packed, {
|
|
||||||
remove_comments => 1,
|
|
||||||
remove_newlines => 1,
|
|
||||||
do_javascript => "shrink",
|
|
||||||
do_stylesheet => "minify",
|
|
||||||
} );
|
|
||||||
}
|
|
||||||
elsif ( $self->mimeType eq "text/css" ) {
|
|
||||||
CSS::Packer::minify( \$packed, {
|
|
||||||
compress => 'minify',
|
|
||||||
});
|
|
||||||
}
|
|
||||||
elsif ( $self->mimeType eq 'text/javascript' ) {
|
|
||||||
JavaScript::Packer::minify( \$packed, {
|
|
||||||
compress => "shrink",
|
|
||||||
});
|
|
||||||
}
|
|
||||||
$self->snippetPacked($packed);
|
|
||||||
}
|
|
||||||
return $self->next::method($unpacked);
|
|
||||||
}
|
|
||||||
|
|
||||||
#-------------------------------------------------------------------
|
#-------------------------------------------------------------------
|
||||||
|
|
||||||
=head2 view ( $calledAsWebMethod )
|
=head2 view ( $calledAsWebMethod )
|
||||||
|
|
@ -257,10 +260,10 @@ sub view {
|
||||||
my $out = eval{$session->cache->get("view_".$calledAsWebMethod."_".$self->getId)};
|
my $out = eval{$session->cache->get("view_".$calledAsWebMethod."_".$self->getId)};
|
||||||
return $out if $out;
|
return $out if $out;
|
||||||
}
|
}
|
||||||
my $output = $self->get('usePacked')
|
my $output = $self->usePacked
|
||||||
? $self->get("snippetPacked")
|
? $self->snippetPacked
|
||||||
: $self->get('snippet')
|
: $self->snippet
|
||||||
;
|
;
|
||||||
$output = $self->getToolbar.$output if ($session->var->isAdminOn && !$calledAsWebMethod);
|
$output = $self->getToolbar.$output if ($session->var->isAdminOn && !$calledAsWebMethod);
|
||||||
if ($self->processAsTemplate) {
|
if ($self->processAsTemplate) {
|
||||||
$output = WebGUI::Asset::Template->processRaw($session, $output, $self->get);
|
$output = WebGUI::Asset::Template->processRaw($session, $output, $self->get);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue