-
Notifications
You must be signed in to change notification settings - Fork 6
/
introspect.mc
307 lines (264 loc) · 8.11 KB
/
introspect.mc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
<%doc>
=head1 Name
introspect.mc - Outputs a graphical representation of a story type element tree
=head1 Version
1.0
=head1 Synopsis
<& /util/xhtml/introspect.mc &>
=head1 Description
This template outputs a graphical representation of the element structure of a
story type element. To see examples of its output, visit
L<http://www.bricolage.cc/about/doc_models/> on the Bricolage Website.
To use this template, simply create a template for your story type element,
have it execute this template, and you're done. Create a new document for the
story type element and preview it.
The output is XHTML 1.1, containing a series of embedded C<< <div> >>s, each
representing a single element in the element tree. Each contains data about
the element, any fields and any subelements, as well as metadata about the
element itself (name, key name, related story, etc.). The story type element
itself also includes a list of associated sites and output channels.
This template is smart enough to correctly handle recursive elements. It also
has embedded CSS to make the whole thing look nice, with colors to distinguish
up to ten levels of the element tree. Patches to make it look even nicer are
warmly welcomed.
=head1 Parameters
=over 4
=item full_page
$m->comp('/util/xhtml/introspect.mc', full_page => 0);
Pass a false value to this parameter to prevent the template from outputting a
complete XHTML page. That is, if you want to handle the output of the
C<< <html> >>, C<< <head> >>, and C<< <body> >> tags yourself, pass a false
value. Defaults to true.
=item include_css
$m->comp('/util/xhtml/introspect.mc', include_css => 0);
Pass a false value to this parameter to prevent the template from outputting
its default CSS. True by default.
=head1 Prerequisites
=over 4
=item Bricolage 1.8
=back
=head1 Author
David Wheeler <[email protected]>
=head1 Copyright and License
Copyright (c) 2004 David Wheeler & Kineticode. All rights reserved.
This library is free software; you can redistribute it and/or modify it under
the terms of the GNU Lesser General Public License as published by the Free
Software Foundation, version 2.1 of the License.
This library is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
details.
You should have received a copy of the GNU Lesser General Public License along
with this library (see the the license.txt file); if not, write to the Free
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
USA.
=cut
</%doc>\
% if ($full_page) {
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
% }
% if ($include_css) {
<style type="text/css">
.element {
font: verdana, arial, sans-serif;
border-top: 1px solid black;
border-left: 1px solid black;
}
.element h1 { font-size: 1.4em; margin: 0; }
.element h2 { font-size: 1.2em; margin: .5em 0 .2em 0; }
.element table {
border-spacing: 0;
border-left: 1px solid black;
border-top: 1px solid black;
}
.element, .fields tr, .fields td, .fields th, .sites tr, .sites td, .sites th {
border-bottom: 1px solid black;
border-right: 1px solid black;
margin: 0;
padding: .2em;
vertical-align: top;
}
.fields { width: 100%; }
.element {
padding: 1em;
margin-bottom: 1em;
}
.element dt {
font-weight: bold;
float: left;
padding-right: .5em;
}
.element td ul {
list-style: square;
margin: 0 0 0 1.5em;
padding: 0;
}
.sites td ul {
list-style: none;
padding: 0;
margin: 0;
}
li.primary {
font-weight: bold;
}
li.primary:after { content: " \2714"; }
.element dt:after { content: ":" }
/* Colors */
.level1 { background: #fbfbd8; }
.level2 { background: #eed2ee; }
.level3 { background: #add8e6; }
.level4 { background: #e1f5ba; }
.level5 { background: #ffe4e1; }
.level5 { background: #7fffd4; }
.level6 { background: #ffec8b; }
.level7 { background: #ffc1c1; }
.level8 { background: #87ceeb; }
.level9 { background: #deb887; }
.level10 { background: #ff6347; }
</style>
% }
% if ($full_page) {
<title><% $element->get_name %></title>
<meta name="generator" content="Bricolage <% Bric->VERSION %>" />
</head>
<body>
% }
% $m->comp('.element', elem => $element->get_element);
% if ($full_page) {
</body>
</html>
% }
<%args>
$include_css => 1
$full_page => 1
</%args>
<%once>;
my $meta = 'html_info';
</%once>\
<%shared>
my %seen;
</%shared>\
<%def .element>
<%args>
$elem
$level => 1
$no_nest => 0
</%args>\
% my $kn = $elem->get_key_name;
% $seen{$kn}++;
% my @keys = qw(type value length size);
<div class="element level<% $level %>">
<h1><% $elem->get_name %></h1>
<dl>
<dt>Key Name</dt>
<dd><% $kn %></dd>
<dt>Type</dt>
<dd><% $elem->get_type_name %></dd>
<dt>Paginated</dt>
<dd><% $elem->get_paginated ? 'Yes' : 'No' %></dd>
<dt>Related Media</dt>
<dd><% $elem->is_related_media ? 'Yes' : 'No' %></dd>
<dt>Related Story</dt>
<dd><% $elem->is_related_story ? 'Yes' : 'No' %></dd>
% if ($elem->get_top_level) {
<dt>Fixed URL</dt>
<dd><% $elem->get_fixed_url ? 'Yes' : 'No' %></dd>
% }
<dt>Description</dt>
<dd><% $elem->get_description || ' ' %></dd>
</dl>
% if ($elem->get_top_level) {
<h2>Sites & Output Channels</h2>
<table class="sites">
<tr>
<th>Site</th>
<th>Output Channels</th>
</tr>
% my %ocs; push @{$ocs{$_->get_site_id}}, $_ for $elem->get_output_channels;
% for my $site ($elem->get_sites) {
% my $prim = $elem->get_primary_oc_id($site->get_id);
<tr>
<td><% $site->get_name %></td>
<td>
<ul>
% for my $oc (@{$ocs{$site->get_id}}) {
% my $attr = $oc->get_id == $prim
% ? ' class="primary" title="Primary Output Channel"'
% : '';
<li<% $attr %>><% $oc->get_name %></li>
% }
</ul>
</td>
</tr>
% }
</table>
% }
% if (my @fields = $elem->get_data) {
<h2>Fields</h2>
<table class="fields">
<tr>
<th>Place</th>
<th>Key Name</th>
<th>Label</th>
% for my $key (@keys) {
<th><% $key eq 'value' ? 'Default' : ucfirst $key %></th>
% }
<th>Max Length</th>
<th>Required</th>
<th>Values</th>
</tr>
% for my $field (@fields) {
% my $vals = $field->get_meta($meta, 'vals');
<tr>
<td><% $field->get_place %></td>
<td><% $field->get_key_name %></td>
<td><% $field->get_meta($meta, 'disp') %></td>
% for my $key (@keys) {
% my $val = $field->get_meta($meta, $key);
% $val = ucfirst $val if $key eq 'type';
% $val = ' ' unless defined $val && $val ne '';
<td><% $val %></td>
% }
<td><% $field->get_max_length %></td>
<td><% $field->get_required ? 'Yes' : 'No' %></td>
% if ($vals) {
<td>
<ul>
% for my $line (split /\n/, $vals) {
% my ($val, $label) = split /,/, $line; $label ||= $val;
<li><% "$val => $label" %></li>
% }
</ul>
</td>
% } else {
<td> </td>
% }
</tr>
% }
</table>
% }
<%perl>;
if (my @subs = $elem->get_containers) {
my $kn1 = $subs[0]->get_key_name;
unless ($seen{$kn} > 1 || (@subs == 1 && $no_nest && $kn1 eq $kn)) {
$m->print(" <h2>Subelements</h2>\n");
for my $sub (@subs) {
my $subkn = $sub->get_key_name;
my $nest = $subkn eq $kn;
next if $seen{$subkn} > 1 || ($nest && $no_nest);
$m->comp('.element',
elem => $sub,
level => $level + 1,
no_nest => $nest
);
}
}
}
$seen{$kn}--;
</%perl>\
</div>
</%def>\