From: Simon Cozens Date: Mon, 22 Mar 2004 16:45:28 +0000 (+0000) Subject: Remove "name" magic, replace with "stringify_column" magic. X-Git-Tag: 2.10~273 X-Git-Url: https://git.decadent.org.uk/gitweb/?a=commitdiff_plain;h=f7e68bd92b9b43454454f9715406b7e0f9b956e1;p=maypole.git Remove "name" magic, replace with "stringify_column" magic. git-svn-id: http://svn.maypole.perl.org/Maypole/trunk@89 48953598-375a-da11-a14b-00016c27c3ee --- diff --git a/lib/Maypole/Model/CDBI.pm b/lib/Maypole/Model/CDBI.pm index b2a79b4..e7330e4 100644 --- a/lib/Maypole/Model/CDBI.pm +++ b/lib/Maypole/Model/CDBI.pm @@ -61,12 +61,20 @@ sub delete :Exported { $r->{template} = "list"; } +sub stringify_column { + my $class = shift; + return ($class->columns("Stringify"), + (grep { $_ ne "id" } $class->primary_columns), + (grep { $_ eq "name" } $class->columns) + )[0]; +} + sub adopt { my ($self, $child) = @_; $child->autoupdate(1); - if (grep { $_ eq "name" } $child->columns) { # Common case - $child->columns( Stringify => qw/ name / ); - } # Otherwise, work it out for yourself. + if (my $col = $child->stringify_column) { + $child->columns( Stringify => $col ); + } } sub search :Exported { diff --git a/templates/factory/macros b/templates/factory/macros index 7e3284c..e142916 100644 --- a/templates/factory/macros +++ b/templates/factory/macros @@ -31,6 +31,7 @@ command for that object. Otherwise, it just displays the data. #%] [% + MACRO maybe_link_view(object) BLOCK; IF object.moniker; # It's an object, i.e. a has-a link(object.moniker, "view", object.id, object); @@ -57,7 +58,7 @@ for some. ""; IF col == "url"; " "; item.url; ""; - ELSIF col == "name"; + ELSIF col == item.stringify_column; maybe_link_view(item); ELSE; maybe_link_view(item.$col); diff --git a/templates/factory/view b/templates/factory/view index 0ea412e..0a0860e 100644 --- a/templates/factory/view +++ b/templates/factory/view @@ -12,15 +12,16 @@ C and displays the object's properties in a table. [% INCLUDE header %] [% FOR item = objects %] -

[% item.name %]

+[% SET string = item.stringify_column %] +

[% item.$string %]

[% INCLUDE navbar %] - + [% FOR col = classmetadata.columns.list; - NEXT IF col == "id" OR col == "name"; + NEXT IF col == "id" OR col == string; NEXT UNLESS item.$col; %] @@ -31,7 +32,7 @@ C and displays the object's properties in a table. It gets the displayable form of a column's name from the hash returned from the C method: -%#] +#%] @@ -48,7 +49,7 @@ from the C method: #One interesting macro used in this template is C: maybe_link_view(item.$col); -%] +%] [%#
Name [% item.name %]
[% classmetadata.colnames.$string %] [% item.$string %]
[% classmetadata.colnames.$col; %]