5 These are some default macros which are used by various templates in the
10 This creates an <A HREF="..."> to a command in the Apache::MVC system by
11 catenating the base URL, table, command, and any arguments.
15 MACRO link(table, command, additional, label) BLOCK;
16 SET lnk = base _ "/" _ table _ "/" _ command _ "/" _ additional;
17 lnk = lnk | uri | html;
18 '<a href="' _ lnk _ '">';
26 =head2 maybe_link_view
28 C<maybe_link_view> takes something returned from the database - either
29 some ordinary data, or an object in a related class expanded by a
30 has-a relationship. If it is an object, it constructs a link to the view
31 command for that object. Otherwise, it just displays the data.
36 MACRO maybe_link_view(object) BLOCK;
37 IF object.isa('Maypole::Model::Base');
38 link(object.table, "view", object.id.join('/'), object);
49 C<display_line> is used in the list template to display a row from the
50 database, by iterating over the columns and displaying the data for each
51 column. It misses out the C<id> column by default, and magically
52 URLifies columns called C<url>. This may be considered too much magic
56 [% MACRO display_line(item) BLOCK;
57 FOR col = classmetadata.list_columns;
58 NEXT IF col == "id" OR col == classmetadata.table _ "_id";
60 IF col == "url" AND item.url;
61 '<a href="'; item.url | html ; '"> '; item.url; '</a>';
62 ELSIF col == classmetadata.stringify_column;
63 maybe_link_view(item);
65 accessor = item.accessor_name(col);
66 maybe_link_view(item.$accessor);
70 '<td class="actions">';
72 button(item, "delete");
79 This is a generic button, which performs an action on an object.
84 [% MACRO button(obj, action) BLOCK; %]
85 [% IF obj.is_public(action) %]
86 <form class="actionform" action="[% base %]/[% obj.table %]/[% action %]/[% obj.id.join('/') %]" method="post">
87 <div class="field"><input class="actionbutton" type="submit" value="[% action %]" /></div></form>
94 This takes an object, and looks up the C<related_accessors>; this should
95 give a list of accessors that can be called to get a list of related
96 objects. It then displays a title for that accessor, (i.e. "Beers" for a
97 brewery) calls the accesor, and displays a list of the results.
103 MACRO view_related(object) BLOCK;
104 FOR accessor = classmetadata.related_accessors.list;
105 "<div id=\"subtitle\">"; accessor | ucfirst; "</div>\n";
107 FOR thing = object.$accessor;
108 "<li>"; maybe_link_view(thing); "</li>\n";
114 MACRO test_xxxx(myblock) BLOCK;
115 FOR col = classmetadata.columns;
125 This takes an object and and displays its properties in a table.
130 [% MACRO view_item(item) BLOCK; %]
131 [% SET string = classmetadata.stringify_column %]
132 <div id="title"> [% item.$string | html %]</div>
136 <td class="field">[% classmetadata.colnames.$string %]</td>
137 <td>[% item.$string | html %]</td>
139 [% FOR col = classmetadata.columns.list;
140 NEXT IF col == "id" OR col == string OR col == classmetadata.table _ "_id";;
141 NEXT UNLESS item.$col;
147 It gets the displayable form of a column's name from the hash returned
148 from the C<column_names> method:
152 <td class="field">[% classmetadata.colnames.$col; %]</td>
154 [% IF col == "url" && item.url; # Possibly too much magic.
155 '<a href="'; item.url | html ; '"> '; item.url; '</a>';
157 maybe_link_view(item.$col);
161 This tests whether or not the returned value is an object, and if so,
162 creates a link to a page viewing that object; if not, it just displays
163 the text as normal. The object is linked using its stringified name;
164 by default this calls the C<name> method, or returns the object's ID
165 if there is no C<name> method or other stringification method defined.