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.
13 arguments are table, command, additional, label, target.
15 target specifies a target for the link if provided.
19 MACRO link(table, command, additional, label, target) BLOCK;
20 SET lnk = base _ "/" _ table _ "/" _ command _ "/" _ additional;
23 '<a href="' _ lnk _ '" target="' _ target _'">';
25 '<a href="' _ lnk _ '">';
34 =head2 maybe_link_view
36 C<maybe_link_view> takes something returned from the database - either
37 some ordinary data, or an object in a related class expanded by a
38 has-a relationship. If it is an object, it constructs a link to the view
39 command for that object. Otherwise, it just displays the data.
44 MACRO maybe_link_view(object) BLOCK;
45 IF object.isa('Maypole::Model::Base');
46 link(object.table, "view", object.id.join('/'), object);
57 C<display_line> is used in the list template to display a row from the
58 database, by iterating over the columns and displaying the data for each
59 column. It misses out the C<id> column by default, and magically
60 URLifies columns called C<url>. This may be considered too much magic
64 [% MACRO display_line(item) BLOCK;
65 FOR col = classmetadata.list_columns;
66 NEXT IF col == "id" OR col == classmetadata.table _ "_id";
67 col_obj = item.find_column(col);
69 IF col == "url" AND item.url;
70 '<a href="'; item.url | html ; '"> '; item.url; '</a>';
71 ELSIF col == classmetadata.stringify_column;
72 maybe_link_view(item);
73 ELSIF col_obj; # its a real column
74 accessor = item.accessor_name_for(col_obj) || item.accessor_name(col_obj); # deprecated in cdbi
75 maybe_link_view(item.$accessor);
82 '<td class="actions">';
84 button(item, "delete");
91 This is a generic button, which performs an action on an object.
96 [% MACRO button(obj, action) BLOCK; %]
97 [% IF obj.is_public(action) %]
98 <form class="actionform" action="[% base %]/[% obj.table %]/[% action %]/[% obj.id.join('/') %]" method="post">
99 <div class="field"><input class="actionbutton" type="submit" value="[% action %]" /></div></form>
106 This takes an object, and looks up the C<related_accessors>; this should
107 give a list of accessors that can be called to get a list of related
108 objects. It then displays a title for that accessor, (i.e. "Beers" for a
109 brewery) calls the accesor, and displays a list of the results.
115 MACRO view_related(object) BLOCK;
116 FOR accessor = classmetadata.related_accessors.list;
117 "<div id=\"subtitle\">"; accessor | ucfirst; "</div>\n";
119 FOR thing = object.$accessor;
120 "<li>"; maybe_link_view(thing); "</li>\n";
126 MACRO test_xxxx(myblock) BLOCK;
127 FOR col = classmetadata.columns;
137 This takes an object and and displays its properties in a table.
142 [% MACRO view_item(item) BLOCK; %]
143 [% SET string = classmetadata.stringify_column %]
144 <div id="title"> [% item.$string | html %]</div>
148 <td class="field">[% classmetadata.colnames.$string %]</td>
149 <td>[% item.$string | html %]</td>
151 [% FOR col = classmetadata.columns.list;
152 NEXT IF col == "id" OR col == string OR col == classmetadata.table _ "_id";;
153 NEXT UNLESS item.$col;
159 It gets the displayable form of a column's name from the hash returned
160 from the C<column_names> method:
164 <td class="field">[% classmetadata.colnames.$col ||
165 col | ucfirst | replace('_',' '); %]</td>
167 [% IF col == "url" && item.url; # Possibly too much magic.
168 '<a href="'; item.url | html ; '"> '; item.url; '</a>';
169 ELSIF item.$col.size > 1; # has_many column
170 FOR thing IN item.$col;
171 maybe_link_view(thing);", ";
176 maybe_link_view(item.$col);
180 This tests whether or not the returned value is an object, and if so,
181 creates a link to a page viewing that object; if not, it just displays
182 the text as normal. The object is linked using its stringified name;
183 by default this calls the C<name> method, or returns the object's ID
184 if there is no C<name> method or other stringification method defined.