From 6a0129601964cb110f9119032d95b6cd58f62a7f Mon Sep 17 00:00:00 2001 From: Paul Driver Date: Wed, 11 May 2011 09:30:36 -0500 Subject: [PATCH] rfe #12127: AssetProperty macro --- docs/changelog/7.x.x.txt | 1 + docs/upgrades/upgrade_7.10.15-7.10.16.pl | 12 +++++++ etc/WebGUI.conf.original | 1 + lib/WebGUI/Macro/AssetProperty.pm | 43 ++++++++++++++++++++++++ t/Macro/AssetProperty.t | 25 ++++++++++++++ 5 files changed, 82 insertions(+) create mode 100644 lib/WebGUI/Macro/AssetProperty.pm create mode 100644 t/Macro/AssetProperty.t diff --git a/docs/changelog/7.x.x.txt b/docs/changelog/7.x.x.txt index d0a358244..439abe5c4 100644 --- a/docs/changelog/7.x.x.txt +++ b/docs/changelog/7.x.x.txt @@ -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 diff --git a/docs/upgrades/upgrade_7.10.15-7.10.16.pl b/docs/upgrades/upgrade_7.10.15-7.10.16.pl index 2310a95f0..819a0511d 100644 --- a/docs/upgrades/upgrade_7.10.15-7.10.16.pl +++ b/docs/upgrades/upgrade_7.10.15-7.10.16.pl @@ -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 -------------------------------- diff --git a/etc/WebGUI.conf.original b/etc/WebGUI.conf.original index f85220d79..2a9c48b41 100644 --- a/etc/WebGUI.conf.original +++ b/etc/WebGUI.conf.original @@ -817,6 +817,7 @@ "AdSpace" : "AdSpace", "AOIHits" : "AOIHits", "AOIRank" : "AOIRank", + "AssetProperty" : "AssetProperty", "AssetProxy" : "AssetProxy", "BackToSite" : "BackToSite", "CanEditText" : "CanEditText", diff --git a/lib/WebGUI/Macro/AssetProperty.pm b/lib/WebGUI/Macro/AssetProperty.pm new file mode 100644 index 000000000..75c14a73b --- /dev/null +++ b/lib/WebGUI/Macro/AssetProperty.pm @@ -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; diff --git a/t/Macro/AssetProperty.t b/t/Macro/AssetProperty.t new file mode 100644 index 000000000..30fc25eac --- /dev/null +++ b/t/Macro/AssetProperty.t @@ -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"; +}