<%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 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<<
>>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<< >>, C<< >>, and C<< >> 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 =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 \ % if ($full_page) { % } % if ($include_css) { % } % if ($full_page) { <% $element->get_name %> % } % $m->comp('.element', elem => $element->get_element); % if ($full_page) { % } <%args> $include_css => 1 $full_page => 1 <%once>; my $meta = 'html_info'; \ <%shared> my %seen; \ <%def .element> <%args> $elem $level => 1 $no_nest => 0 \ % my $kn = $elem->get_key_name; % $seen{$kn}++; % my @keys = qw(type value length size);

<% $elem->get_name %>

Key Name
<% $kn %>
Type
<% $elem->get_type_name %>
Paginated
<% $elem->get_paginated ? 'Yes' : 'No' %>
Related Media
<% $elem->is_related_media ? 'Yes' : 'No' %>
Related Story
<% $elem->is_related_story ? 'Yes' : 'No' %>
% if ($elem->get_top_level) {
Fixed URL
<% $elem->get_fixed_url ? 'Yes' : 'No' %>
% }
Description
<% $elem->get_description || ' ' %>
% if ($elem->get_top_level) {

Sites & Output Channels

% 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); % }
Site Output Channels
<% $site->get_name %>
    % for my $oc (@{$ocs{$site->get_id}}) { % my $attr = $oc->get_id == $prim % ? ' class="primary" title="Primary Output Channel"' % : ''; ><% $oc->get_name %> % }
% } % if (my @fields = $elem->get_data) {

Fields

% for my $key (@keys) { % } % for my $field (@fields) { % my $vals = $field->get_meta($meta, 'vals'); % for my $key (@keys) { % my $val = $field->get_meta($meta, $key); % $val = ucfirst $val if $key eq 'type'; % $val = ' ' unless defined $val && $val ne ''; % } % if ($vals) { % } else { % } % }
Place Key Name Label<% $key eq 'value' ? 'Default' : ucfirst $key %>Max Length Required Values
<% $field->get_place %> <% $field->get_key_name %> <% $field->get_meta($meta, 'disp') %><% $val %><% $field->get_max_length %> <% $field->get_required ? 'Yes' : 'No' %>
    % for my $line (split /\n/, $vals) { % my ($val, $label) = split /,/, $line; $label ||= $val;
  • <% "$val => $label" %>
  • % }
 
% } <%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("

Subelements

\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}--; \
\