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";
59 col_obj = item.find_column(col);
61 IF col == "url" AND item.url;
62 '<a href="'; item.url | html ; '"> '; item.url; '</a>';
63 ELSIF col == classmetadata.stringify_column;
64 maybe_link_view(item);
65 ELSIF col_obj; # its a real column
66 accessor = item.accessor_name_for(col_obj) ||
67 item.accessor_name(col_obj); # deprecated in cdbi
68 maybe_link_view(item.$accessor);
75 '<td class="actions">';
77 button(item, "delete");
84 This is a generic button, which performs an action on an object.
89 [% MACRO button(obj, action) BLOCK; %]
90 [% IF obj.is_public(action) %]
91 <form class="actionform" action="[% base %]/[% obj.table %]/[% action %]/[% obj.id.join('/') %]" method="post">
92 <div class="field"><input class="actionbutton" type="submit" value="[% action %]" /></div></form>
99 This takes an object, and looks up the C<related_accessors>; this should
100 give a list of accessors that can be called to get a list of related
101 objects. It then displays a title for that accessor, (i.e. "Beers" for a
102 brewery) calls the accesor, and displays a list of the results.
108 MACRO view_related(object) BLOCK;
109 FOR accessor = classmetadata.related_accessors.list;
110 "<div id=\"subtitle\">"; accessor | ucfirst; "</div>\n";
112 FOR thing = object.$accessor;
113 "<li>"; maybe_link_view(thing); "</li>\n";
119 MACRO test_xxxx(myblock) BLOCK;
120 FOR col = classmetadata.columns;
130 This takes an object and and displays its properties in a table.
135 [% MACRO view_item(item) BLOCK; %]
136 [% SET string = classmetadata.stringify_column %]
137 <div id="title"> [% item.$string | html %]</div>
141 <td class="field">[% classmetadata.colnames.$string %]</td>
142 <td>[% item.$string | html %]</td>
144 [% FOR col = classmetadata.columns.list;
145 NEXT IF col == "id" OR col == string OR col == classmetadata.table _ "_id";;
146 NEXT UNLESS item.$col;
152 It gets the displayable form of a column's name from the hash returned
153 from the C<column_names> method:
157 <td class="field">[% classmetadata.colnames.$col ||
158 col | ucfirst | replace('_',' '); %]</td>
160 [% IF col == "url" && item.url; # Possibly too much magic.
161 '<a href="'; item.url | html ; '"> '; item.url; '</a>';
162 ELSIF item.$col.size > 1; # has_many column
163 FOR thing IN item.$col;
164 maybe_link_view(thing);", ";
168 maybe_link_view(item.$col);
172 This tests whether or not the returned value is an object, and if so,
173 creates a link to a page viewing that object; if not, it just displays
174 the text as normal. The object is linked using its stringified name;
175 by default this calls the C<name> method, or returns the object's ID
176 if there is no C<name> method or other stringification method defined.