Skip to content
Permalink
Browse files

Add a method that returns either the standard style template or the m…

…obile style template based on the Session.
  • Loading branch information...
perlDreamer committed Aug 1, 2011
1 parent aabb464 commit 4ac894d98174959ff476fdb53ae47756993e0a84
Showing with 31 additions and 4 deletions.
  1. +15 −4 lib/WebGUI/Asset/Wobject.pm
  2. +16 −0 t/tests/Test/WebGUI/Asset/Wobject.pm
@@ -226,6 +226,20 @@ sub getCollateral {
}


#-------------------------------------------------------------------

=head2 getStyleTemplateId
This returns the correct style to use, either a regular style or a mobile style,
based on $session->style->useMobileStyle.
=cut

sub getStyleTemplateId {
my $self = shift;
return $self->session->style->useMobileStyle ? $self->mobileStyleTemplateId : $self->styleTemplateId;
}

#-------------------------------------------------------------------

=head2 moveCollateralDown ( tableName, keyName, keyValue [ , setName, setValue ] )
@@ -345,10 +359,7 @@ override processStyle => sub {
my ($self, $output, $options) = @_;
$output = super();
my $style = $self->session->style;
if ($style->useMobileStyle) {
return $style->process($output,$self->get("mobileStyleTemplateId"));
}
return $style->process($output,$self->get("styleTemplateId"));
return $style->process($output,$self->getStyleTemplateId);
};


@@ -21,4 +21,20 @@ sub list_of_tables {
return [qw/assetData wobject/];
}

sub t_15_getStyleTemplateId : Test(2) {
note "getStyleTemplateId";
my ( $test ) = @_;
my $session = $test->session;
$session->style->setMobileStyle(0);
$session->setting->set('useMobileStyle', 1);
my ( $tag, $asset, @parents ) = $test->getAnchoredAsset();
$asset->styleTemplateId('Style');
$asset->mobileStyleTemplateId('Mobile');
is $asset->getStyleTemplateId, 'Style', 'returns Style since mobile was not requested';
$session->style->setMobileStyle(1);
is $asset->getStyleTemplateId, 'Mobile', 'returns Mobile since mobile was set';
$session->style->setMobileStyle(0);
$session->setting->set('useMobileStyle', 0);
}

1;

0 comments on commit 4ac894d

Please sign in to comment.
You can’t perform that action at this time.