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.table; # It's an object, i.e. a has-a
38 link(object.table, "view", object.id, 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;
60 IF col == "url" AND item.url;
61 '<a href="'; item.url; '"> '; item.url; '</a>';
62 ELSIF col == item.stringify_column;
63 maybe_link_view(item);
65 maybe_link_view(item.$col);
69 '<td class="actions">';
71 button(item, "delete");
78 This is a generic button, which performs an action on an object.
83 [% MACRO button(obj, action) BLOCK; %]
84 <a class="action" href="[% base %]/[% obj.table %]/[% action %]/[% obj.id %]">
91 This takes an object, and looks up the C<related_accessors>; this should
92 give a list of accessors that can be called to get a list of related
93 objects. It then displays a title for that accessor, (i.e. "Beers" for a
94 brewery) calls the accesor, and displays a list of the results.
100 MACRO view_related(object) BLOCK;
101 FOR accessor = classmetadata.related_accessors.list;
102 "<div id=\"subtitle\">"; accessor | ucfirst; "</div>\n";
104 FOR thing = object.$accessor;
105 "<li>"; maybe_link_view(thing); "</li>\n";
111 MACRO test_xxxx(myblock) BLOCK;
112 FOR col = classmetadata.columns;