| 1 | package Serge::Pod; | ||||||||||
| 2 | |||||||||||
| 3 | 1 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | |||||||||||
| 5 | 1 | ▶ | use Encode qw(encode_utf8); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 1 | ▶ | use File::Basename; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 1 | ▶ | use File::Path; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | 1 | ▶ | use File::Spec::Functions qw(rel2abs catfile); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | 1 | ▶ | use Pod::Simple::XHTML; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | 1 | ▶ | use Pod::Text; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 11 | 1 | ▶ | use Serge; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 12 | |||||||||||
| 13 | sub new { | ||||||||||
| 14 | 0 | ▶ | my ($class, $self) = @_; | ||||||||
|
Subroutine
new: not called CC=5 SCAR=34.0
Pod
undocumented
| |||||||||||
| 15 | |||||||||||
| 16 | 0 | ▶ | $self = {} unless defined $self; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 17 | |||||||||||
| 18 | 0 | ▶ | $self->{css} = 'media/pod.css' unless exists $self->{css}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 19 | |||||||||||
| 20 | 0 | $self->{root} = _find_doc_root(); | |||||||||
| 21 | 0 | ▶ | $self->{pod_root} = catfile($self->{root}, 'pod') unless exists $self->{pod_root}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 22 | 0 | ▶ | $self->{html_root} = catfile($self->{root}, 'html') unless exists $self->{html_root}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 23 | |||||||||||
| 24 | 0 | bless $self, $class; | |||||||||
| 25 | 0 | return $self; | |||||||||
| 26 | } | ||||||||||
| 27 | |||||||||||
| 28 | sub _find_doc_root { | ||||||||||
| 29 | 0 | ▶ | my @trydirs = ( | ||||||||
|
Subroutine
_find_doc_root: not called CC=2 SCAR=17.9
| |||||||||||
| 30 | catfile(dirname(__FILE__), '../../doc'), | ||||||||||
| 31 | '/usr/local/share/serge/doc', | ||||||||||
| 32 | '/usr/share/serge/doc' | ||||||||||
| 33 | ); | ||||||||||
| 34 | |||||||||||
| 35 | map { | ||||||||||
| 36 | 0 | ▶ | return $_ if -d $_; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 37 | } @trydirs; | ||||||||||
| 38 | |||||||||||
| 39 | 0 | return '.'; | |||||||||
| 40 | } | ||||||||||
| 41 | |||||||||||
| 42 | sub save_html { | ||||||||||
| 43 | 0 | ▶ | my ($self, $command, $podfile) = @_; | ||||||||
|
Subroutine
save_html: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||
| 44 | |||||||||||
| 45 | 0 | my $outfile = $self->get_html_path($command); | |||||||||
| 46 | |||||||||||
| 47 | 0 | my $html; | |||||||||
| 48 | |||||||||||
| 49 | 0 | my $parser = Pod::Simple::XHTML->new(); | |||||||||
| 50 | 0 | $parser->perldoc_url_prefix(''); | |||||||||
| 51 | 0 | $parser->perldoc_url_postfix('.html'); | |||||||||
| 52 | |||||||||||
| 53 | 0 | $parser->html_header( | |||||||||
| 54 | qq|<html> | ||||||||||
| 55 | <head> | ||||||||||
| 56 | <title>$command</title> | ||||||||||
| 57 | <link rel="stylesheet" href="$self->{css}" type="text/css" /> | ||||||||||
| 58 | <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> | ||||||||||
| 59 | <link href="media/favicon.ico" rel="shortcut icon" type="image/x-icon" /> | ||||||||||
| 60 | </head> | ||||||||||
| 61 | <body> | ||||||||||
| 62 | <div class="wrapper"> | ||||||||||
| 63 | <div class="header-bg"></div> | ||||||||||
| 64 | <div class="header"> | ||||||||||
| 65 | <a class="logo" href="serge.html"><img src="media/logo.svg" />Serge</a> | ||||||||||
| 66 | </div> | ||||||||||
| 67 | |||||||||||
| 68 | <h1 class="command"> | ||||||||||
| 69 | <code class="command">$command</code> | ||||||||||
| 70 | </h1> | ||||||||||
| 71 | |||||||||||
| 72 | <div class="content">|); | ||||||||||
| 73 | 0 | $parser->html_footer( | |||||||||
| 74 | qq| | ||||||||||
| 75 | </div> | ||||||||||
| 76 | |||||||||||
| 77 | <div class="footer"> | ||||||||||
| 78 | <div class="copyright"> | ||||||||||
| 79 | © 2014–2018 Evernote Corporation.<br/> | ||||||||||
| 80 | All rights reserved. | ||||||||||
| 81 | </div> | ||||||||||
| 82 | <div class="license"> | ||||||||||
| 83 | Serge is licensed under Standard Perl License (dual <a href="http://dev.perl.org/licenses/gpl1.html">GPL</a> / <a href="http://dev.perl.org/licenses/artistic.html">Artistic License</a>)<br/> | ||||||||||
| 84 | Serge.io website and Serge documentation are licensed under <a href="https://creativecommons.org/licenses/by/4.0/">CC BY 4.0</a> | ||||||||||
| 85 | </div> | ||||||||||
| 86 | </div> | ||||||||||
| 87 | </div> | ||||||||||
| 88 | </body> | ||||||||||
| 89 | </html>|); | ||||||||||
| 90 | 0 | $parser->output_string(\$html); | |||||||||
| 91 | 0 | $parser->parse_file($podfile); | |||||||||
| 92 | |||||||||||
| 93 | 0 | my $dir = dirname($outfile); | |||||||||
| 94 | 0 | ▶ | mkpath($dir) unless -d $dir; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 95 | |||||||||||
| 96 | 0 | ▶ | open HTML, ">$outfile" or die "Can't open file '$outfile': $!\n"; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 97 | 0 | binmode(HTML); | |||||||||
| 98 | 0 | print HTML encode_utf8($html); # encode manually to avoid 'Wide character in print' warnings and force Unix-style endings | |||||||||
| 99 | 0 | close HTML; | |||||||||
| 100 | |||||||||||
| 101 | 0 | return $outfile; | |||||||||
| 102 | } | ||||||||||
| 103 | |||||||||||
| 104 | sub print_as_text { | ||||||||||
| 105 | 0 | ▶ | my ($self, $podfile, $fh) = @_; | ||||||||
|
Subroutine
print_as_text: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||
| 106 | 0 | ▶ | $fh = *STDOUT unless $fh; # otherwise some old version of Pod::Simple won't properly initialize the output | ||||||||
|
Branch: 1 branch
| |||||||||||
| 107 | |||||||||||
| 108 | 0 | my $parser = Pod::Text->new(sentence => 0, width => 78); | |||||||||
| 109 | 0 | $parser->output_fh($fh); | |||||||||
| 110 | 0 | $parser->parse_file($podfile); # this will render the file to the specified file handle | |||||||||
| 111 | } | ||||||||||
| 112 | |||||||||||
| 113 | sub get_pod_path { | ||||||||||
| 114 | 0 | ▶ | my ($self, $command) = @_; | ||||||||
|
Subroutine
get_pod_path: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 115 | |||||||||||
| 116 | 0 | return rel2abs(catfile($self->{pod_root}, "$command.pod")); | |||||||||
| 117 | } | ||||||||||
| 118 | |||||||||||
| 119 | sub get_html_path { | ||||||||||
| 120 | 0 | ▶ | my ($self, $command) = @_; | ||||||||
|
Subroutine
get_html_path: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 121 | |||||||||||
| 122 | 0 | return rel2abs(catfile($self->{html_root}, "$command.html")); | |||||||||
| 123 | } | ||||||||||
| 124 | |||||||||||
| 125 | 1 | 1; | |||||||||