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 m{\n}, $content;
56 my ($first, @rest) = @lines;
57 return HTML::Zoom->from_events([
58 { type => 'TEXT', raw => $first },
61 ( @{ HTML::Zoom->from_html('<br/>')->to_events },
62 { type => 'TEXT', raw => $string });
68 sub _apply_table_body {
69 my ($self, $markup, $report) = @_;
71 my $rows = $report->{rows};
72 my @cols = map $_->{key}, @{$report->{columns}};
73 return $markup->repeat('.data-row', sub {
74 return HTML::Zoom::CodeStream->new({
76 return if $index > $#$rows;
77 my $row = $rows->[$index++];
79 $_->repeat('td', [ map {
82 my $value = $row->{$col};
84 $_->apply_if($col !~ m{^__}, sub {
85 $_->add_to_attribute('td', class => "si-column-$col");
87 ->replace_content('td', $value->$_prepare_column_content)
88 ->apply_if($col_idx != $#cols, sub {
89 $_->add_after('td', "\n ");
101 $string =~ s{(?:^\s+|\s+$)}{}g;
105 sub _apply_table_head {
106 my ($self, $markup, $report) = @_;
107 my @cols = @{$report->{columns}};
109 ->repeat('th', [map {
112 my $label = $col->{label};
114 $_->apply_if($col->{key} !~ m{^__}, sub {
115 $_->add_to_attribute('th', class => 'si-colhead-' . $col->{key});
117 ->replace_content('th', defined($label) ? $label->$_trim : 'Unnamed')
118 ->apply_if($col_idx != $#cols, sub {
119 $_->add_after('th', "\n ");
132 return HTML::Zoom->from_html($_template);
138 <table class="si-report">
142 <tr class="data-row">