rfe #12127: AssetProperty macro

This commit is contained in:
Paul Driver 2011-05-11 09:30:36 -05:00
parent 34eda690ee
commit 6a01296019
5 changed files with 82 additions and 0 deletions

View file

@ -2,6 +2,7 @@
- fixed #12121: typ-o Asset_Map.templateIdEditPoint
- rfe #2123: Layouts related for export purposes
- fixed #12125: Recaptcha API url
- rfe #12127: AssetProperty macro
7.10.15
- fixed #12117: Thingy - www_searchViaAjax broken

View file

@ -31,6 +31,7 @@ my $quiet; # this line required
my $session = start(); # this line required
# upgrade functions go here
addAssetPropertyMacro($session);
finish($session); # this line required
@ -44,6 +45,17 @@ finish($session); # this line required
# print "DONE!\n" unless $quiet;
#}
#----------------------------------------------------------------------------
sub addAssetPropertyMacro {
my $session = shift;
my $c = $session->config;
my $hash = $c->get('macros');
unless (grep { $_ eq 'AssetProperty' } values %$hash) {
print "\tAdding AssetProperty macro... " unless $quiet;
$c->set('macros/AssetProperty' => 'AssetProperty');
print "DONE!\n" unless $quiet;
}
}
# -------------- DO NOT EDIT BELOW THIS LINE --------------------------------

View file

@ -817,6 +817,7 @@
"AdSpace" : "AdSpace",
"AOIHits" : "AOIHits",
"AOIRank" : "AOIRank",
"AssetProperty" : "AssetProperty",
"AssetProxy" : "AssetProxy",
"BackToSite" : "BackToSite",
"CanEditText" : "CanEditText",

View file

@ -0,0 +1,43 @@
package WebGUI::Macro::AssetProperty;
#-------------------------------------------------------------------
# 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
#-------------------------------------------------------------------
use warnings;
use strict;
=head1 NAME
WebGUI::Macro::AssetProperty
=head1 SYNOPSIS
^AssetProperty(sf76sd8f5s7f5s7618, title);
^AssetProperty(root/import, assetId);
=head2 process( $session, $url_or_assetId, $propertyName )
Equivalent to calling $asset->get($propertyName)
=cut
#-------------------------------------------------------------------
sub process {
my ($session, $id, $name) = @_;
my $asset = WebGUI::Asset->new($session, $id) if $session->id->valid($id);
$asset ||= WebGUI::Asset->newByUrl($session, $id);
return $asset->get($name) if $asset;
$session->log->error("Invalid assetId or URL in AssetProperty: $id");
return '';
}
1;

25
t/Macro/AssetProperty.t Normal file
View file

@ -0,0 +1,25 @@
use warnings;
use strict;
use Test::More tests => 8;
use FindBin;
use lib "$FindBin::Bin/../lib";
use WebGUI::Test;
use WebGUI::Asset;
use WebGUI::Macro::AssetProperty;
my $session = WebGUI::Test->session;
my $temp = WebGUI::Asset->getTempspace($session);
my $props = $temp->get;
my ($url, $id) = @{$props}{qw(url assetId)};
sub proc { WebGUI::Macro::AssetProperty::process($session, @_) }
is proc($id, 'url'), $url, 'assetId';
is proc($url, 'assetId'), $id, 'url';
for my $name (qw(url assetId parentId lineage title menuTitle)) {
is proc($id, $name), $props->{$name}, "get $name";
}