[Maypole-dev] [PATCH] Split the guts of the view template into a macro

From: Dagfinn Ilmari Mannsåker (ilmari at ilmari.org)
Date: Wed Dec 08 2004 - 14:20:35 GMT


It's me again :)

I needed to replace just the related part of the view template for some
of my tables, so instead of duplicating most of it, I split the guts off
into a view_item macro.

Index: templates/factory/macros
===================================================================
--- templates/factory/macros (revision 304)
+++ templates/factory/macros (working copy)
@@ -117,3 +117,57 @@
     END;
 END;
 %]
+[%#
+
+=head2 view_item
+
+This takes an object and and displays its properties in a table.
+
+=cut
+
+#%]
+[% MACRO view_item(item) BLOCK; %]
+ [% SET string = item.stringify_column %]
+ <div id="title"> [% item.$string %]</div>
+ [% INCLUDE navbar %]
+ <table class="view">
+ <tr>
+ <td class="field">[% classmetadata.colnames.$string %]</td>
+ <td>[% item.$string %]</td>
+ </tr>
+ [% FOR col = classmetadata.columns.list;
+ NEXT IF col == "id" OR col == string;
+ NEXT UNLESS item.$col;
+ %]
+[%#
+
+=for doc
+
+It gets the displayable form of a column's name from the hash returned
+from the C<column_names> method:
+
+#%]
+ <tr>
+ <td class="field">[% classmetadata.colnames.$col; %]</td>
+ <td>
+ [% IF col == "url" && item.url; # Possibly too much magic.
+ ' '; item.url; '';
+ ELSE;
+ maybe_link_view(item.$col);
+ END; %]
+[%#
+
+This tests whether or not the returned value is an object, and if so,
+creates a link to a page viewing that object; if not, it just displays
+the text as normal. The object is linked using its stringified name;
+by default this calls the C<name> method, or returns the object's ID
+if there is no C<name> method or other stringification method defined.
+
+=cut
+
+#%]
+ </td>
+ </tr>
+ [% END; %]
+ </table>
+[% END %]
Index: templates/factory/view
===================================================================
--- templates/factory/view (revision 303)
+++ templates/factory/view (working copy)
@@ -11,51 +11,9 @@
 [% PROCESS macros %]
 [% INCLUDE header %]
 [% FOR item = objects %]
- [% SET string = item.stringify_column %]
- <div id="title"> [% item.$string %]</div>
- [% INCLUDE navbar %]
- <table class="view">
- <tr>
- <td class="field">[% classmetadata.colnames.$string %]</td>
- <td>[% item.$string %]</td>
- </tr>
- [% FOR col = classmetadata.columns.list;
- NEXT IF col == "id" OR col == string;
- NEXT UNLESS item.$col;
- %]
-[%#
-
-=for doc
-
-It gets the displayable form of a column's name from the hash returned
-from the C<column_names> method:
-
-#%]
- <tr>
- <td class="field">[% classmetadata.colnames.$col; %]</td>
- <td>
- [% IF col == "url" && item.url; # Possibly too much magic.
- ' '; item.url; '';
- ELSE;
- maybe_link_view(item.$col);
- END; %]
+[% view_item(item); %]
 [%#
 
-This tests whether or not the returned value is an object, and if so,
-creates a link to a page viewing that object; if not, it just displays
-the text as normal. The object is linked using its stringified name;
-by default this calls the C<name> method, or returns the object's ID
-if there is no C<name> method or other stringification method defined.
-
-=cut
-
-#%]
- </td>
- </tr>
- [% END; %]
- </table>
-[%#
-
 =for doc
 
 The C<view> template also displays a list of other objects related to the first

-- 
ilmari

_______________________________________________ maypole-dev mailing list maypole-dev at lists.netthink.co.uk http://lists.netthink.co.uk/listinfo/maypole-dev



This archive was generated by hypermail 2.1.3 : Thu Feb 24 2005 - 22:25:57 GMT