1 package System::Introspector::Report::Publish::MediaWiki::Producer;
6 my ($self, $stream) = @_;
7 return $self->_clear_body(join "\n", map {
8 ref($_) ? $self->_render_table($_) : $_;
13 my ($self, $string) = @_;
14 $string =~ s{\n\n+}{\n\n}g;
19 my ($self, $type, $id, $body) = @_;
22 sprintf('<!-- SI:%s begin %s -->', uc($type), $id),
24 sprintf('<!-- SI:%s end %s -->', uc($type), $id),
28 my ($self, $report) = @_;
29 my $id = $report->{id};
30 my $str_id = ref($id) ? join(':', @$id) : $id;
31 my $markup = $self->_load_markup;
32 $markup = $self->_apply_table_head($markup, $report);
33 $markup = $self->_apply_table_body($markup, $report);
34 my $description = $report->{description} || [''];
36 $self->_wrap('title', $str_id, $self->_render_title($report)),
38 $self->_wrap('table', $str_id, $markup->to_html),
43 my ($self, $report) = @_;
44 return sprintf '== %s ==', $report->{title};
47 my $_prepare_column_content = sub {
50 unless defined $content;
51 my @lines = split qr{\n}, $content;
58 my ($first, @rest) = @lines;
59 return HTML::Zoom->from_events([
60 { type => 'TEXT', raw => $first },
63 ( @{ HTML::Zoom->from_html('<br/>')->to_events },
64 { type => 'TEXT', raw => $string });
70 sub _apply_table_body {
71 my ($self, $markup, $report) = @_;
73 my $rows = $report->{rows};
74 my @cols = map $_->{key}, @{$report->{columns}};
75 return $markup->repeat('.data-row', sub {
76 return HTML::Zoom::CodeStream->new({
78 return if $index > $#$rows;
79 my $row = $rows->[$index++];
81 $_->repeat('td', [ map {
84 my $value = $row->{$col};
86 $_->apply_if($col !~ m{^__}, sub {
87 $_->add_to_attribute('td', class => "si-column-$col");
89 ->replace_content('td', $value->$_prepare_column_content)
90 ->apply_if($col_idx != $#cols, sub {
91 $_->add_after('td', "\n ");
103 $string =~ s{(?:^\s+|\s+$)}{}g;
107 sub _apply_table_head {
108 my ($self, $markup, $report) = @_;
109 my @cols = @{$report->{columns}};
111 ->repeat('th', [map {
114 my $label = $col->{label};
116 $_->apply_if($col->{key} !~ m{^__}, sub {
117 $_->add_to_attribute('th', class => 'si-colhead-' . $col->{key});
119 ->replace_content('th', defined($label) ? $label->$_trim : 'Unnamed')
120 ->apply_if($col_idx != $#cols, sub {
121 $_->add_after('th', "\n ");
134 return HTML::Zoom->from_html($_template);
140 <table class="si-report">
144 <tr class="data-row">