| 1 | package Kwiki::TableOfContents::Print; | ||||||||||
| 2 | |||||||||||
| 3 | 1 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 1 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 1 | ▶ | use Kwiki::Plugin '-Base'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 1 | ▶ | use mixin 'Kwiki::Installer'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 1 | ▶ | use IO::All; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | 1 | ▶ | use JSON; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | 1 | ▶ | use Data::Dumper; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | 1 | our $VERSION = '0.02'; | |||||||||
| 11 | |||||||||||
| 12 | 1 | const class_title => 'Table of Contents Print'; | |||||||||
| 13 | 1 | const class_id => 'toc_print'; | |||||||||
| 14 | |||||||||||
| 15 | 0 | ▶ | sub register { | ||||||||
|
Subroutine
register: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 16 | 0 | my $registry = shift; | |||||||||
| 17 | 0 | $registry->add(prerequisite => 'toc'); | |||||||||
| 18 | 0 | $registry->add(preload => 'toc_print'); | |||||||||
| 19 | 0 | $registry->add(action => 'print_toc'); | |||||||||
| 20 | } | ||||||||||
| 21 | |||||||||||
| 22 | 0 | ▶ | sub print_toc { | ||||||||
|
Subroutine
print_toc: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||
| 23 | 0 | my $print_page = CGI::param('page_name'); | |||||||||
| 24 | my $content = join('', map({ | ||||||||||
| 25 | 0 | my $page_key = $_->[0]; | |||||||||
| 26 | 0 | my $page_name = $_->[1]; | |||||||||
| 27 | 0 | my $level = $_->[2]; | |||||||||
| 28 | 0 | my $html = $self->hub->pages->new_page($page_key)->to_html; | |||||||||
| 29 | 0 | ▶ | $html =~ s|attachments/$print_page/|attachments/$page_key/|gi | ||||||||
|
Branch: 1 branch
| |||||||||||
| 30 | unless $page_key eq $print_page; | ||||||||||
| 31 | 0 | ('<h', $level, ' class="toc_header">', | |||||||||
| 32 | $page_name, | ||||||||||
| 33 | '</h', $level, '>', | ||||||||||
| 34 | $html) | ||||||||||
| 35 | } $self->print_pages)); | ||||||||||
| 36 | 0 | $self->hub->css->add_file('jstree_print.css'); | |||||||||
| 37 | 0 | $self->render_screen( | |||||||||
| 38 | page_html => $content, | ||||||||||
| 39 | ); | ||||||||||
| 40 | } | ||||||||||
| 41 | |||||||||||
| 42 | 0 | ▶ | sub print_pages { | ||||||||
|
Subroutine
print_pages: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||
| 43 | 0 | my $page_name = CGI::param('page_name'); | |||||||||
| 44 | 0 | my $structure = jsonToObj(io->catfile($self->plugin_base_directory, | |||||||||
| 45 | 'toc', 'structure')->slurp); | ||||||||||
| 46 | |||||||||||
| 47 | 0 | ▶ | return $page_name eq $self->config->main_page | ||||||||
|
Branch: 1 branch
| |||||||||||
| 48 | ? (['HomePage', 'Home Page', 1], $self->tree_to_list($structure, 0)) | ||||||||||
| 49 | : $self->tree_to_list($self->find_node($page_name, $structure), 1); | ||||||||||
| 50 | } | ||||||||||
| 51 | |||||||||||
| 52 | 0 | ▶ | sub tree_to_list { | ||||||||
|
Subroutine
tree_to_list: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||
| 53 | 0 | my ( $structure, $level, @list ) = @_; | |||||||||
| 54 | 0 | ▶ | if( ref($structure) eq 'HASH' ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 55 | my $page_name = $self->link_to_pagename( | ||||||||||
| 56 | 0 | $structure->{data}->{href}); | |||||||||
| 57 | push( @list, [ | ||||||||||
| 58 | $page_name, | ||||||||||
| 59 | $structure->{data}->{text}, | ||||||||||
| 60 | 0 | ▶ | $level, | ||||||||
|
Branch: 1 branch
| |||||||||||
| 61 | ]) if defined $page_name; | ||||||||||
| 62 | 0 | $structure = $structure->{subtree}; | |||||||||
| 63 | } | ||||||||||
| 64 | 0 | $level++; | |||||||||
| 65 | 0 | foreach ( @$structure ) { | |||||||||
| 66 | 0 | @list = $self->tree_to_list($_, $level, @list); | |||||||||
| 67 | } | ||||||||||
| 68 | 0 | return @list; | |||||||||
| 69 | } | ||||||||||
| 70 | |||||||||||
| 71 | 0 | ▶ | sub find_node { | ||||||||
|
Subroutine
find_node: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||
| 72 | 0 | my ( $page_name, $structure ) = @_; | |||||||||
| 73 | 0 | foreach ( @$structure ) { | |||||||||
| 74 | 0 | my $cur = $self->link_to_pagename($_->{data}->{href}); | |||||||||
| 75 | 0 | ▶ | return $_ if $page_name eq $cur; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 76 | 0 | my $next = $self->find_node($page_name, $_->{subtree}); | |||||||||
| 77 | 0 | ▶ | return $next if defined $next; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 78 | } | ||||||||||
| 79 | 0 | return undef; | |||||||||
| 80 | } | ||||||||||
| 81 | |||||||||||
| 82 | 0 | ▶ | sub link_to_pagename { | ||||||||
|
Subroutine
link_to_pagename: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||
| 83 | 0 | my ( $link ) = @_; | |||||||||
| 84 | 0 | ▶ | return $link =~ /\?(.+)$/ ? $1 : undef; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 85 | } | ||||||||||
| 86 | |||||||||||
| 87 | 1 | 1; # End of Kwiki::TableOfContents::Print | |||||||||
| 88 | 1 | __DATA__ | |||||||||