| 1 | package DocLife::Markdown; | ||||||||||||
| 2 | |||||||||||||
| 3 | 1 | ▶ | use strict; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 4 | 1 | ▶ | use warnings; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 5 | 1 | ▶ | use parent 'DocLife'; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 6 | 1 | ▶ | use Plack::Util::Accessor qw(tm); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 7 | 1 | ▶ | use Text::Markdown; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 8 | |||||||||||||
| 9 | 5 | ▶ | sub prepare_app { | ||||||||||
|
Subroutine
prepare_app: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 10 | 5 | my ($self, $env) = @_; | |||||||||||
| 11 | 5 | $self->SUPER::prepare_app($env); | |||||||||||
| 12 | 5 | my $tm = Text::Markdown->new; | |||||||||||
| 13 | 5 | $self->tm($tm); | |||||||||||
| 14 | } | ||||||||||||
| 15 | |||||||||||||
| 16 | 3 | ▶ | sub format { | ||||||||||
|
Subroutine
format: called CC=2 SCAR=7.5
Pod
undocumented
| |||||||||||||
| 17 | 3 | my ($self, $req, $res, $file) = @_; | |||||||||||
| 18 | 3 | my $text = $file->slurp; | |||||||||||
| 19 | 3 | my ($title) = $text=~m|^#\s(.*)|; | |||||||||||
| 20 | 3 | ▶ | unless ($title) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 21 | 0 | $title = $file->basename; | |||||||||||
| 22 | 0 | my $suffix = $self->suffix; | |||||||||||
| 23 | 0 | $title=~s|\Q$suffix\E$||; | |||||||||||
| 24 | } | ||||||||||||
| 25 | 3 | my $body = $self->html_header($title,$req); | |||||||||||
| 26 | 3 | $body.= $self->tm->markdown($text); | |||||||||||
| 27 | 3 | $body.= $self->html_footer; | |||||||||||
| 28 | 3 | $res->body($body); | |||||||||||
| 29 | } | ||||||||||||
| 30 | |||||||||||||
| 31 | 3 | ▶ | sub script { | ||||||||||
|
Subroutine
script: called CC=3 SCAR=12.0
Pod
undocumented
| |||||||||||||
| 32 | 3 | my ($self,$req) = @_; | |||||||||||
| 33 | 3 | ▶ | return unless $req; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 34 | |||||||||||||
| 35 | 3 | my $int = $req->param('refresh'); | |||||||||||
| 36 | 3 | ▶ | return '' unless $int; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 37 | <<"EOF" | ||||||||||||
| 38 | window.setInterval( function() { | ||||||||||||
| 39 | window.location.reload(); | ||||||||||||
| 40 | }, $int ); | ||||||||||||
| 41 | EOF | ||||||||||||
| 42 | 0 | } | |||||||||||
| 43 | |||||||||||||
| 44 | 3 | ▶ | sub style { | ||||||||||
|
Subroutine
style: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||
| 45 | <<"EOF" | ||||||||||||
| 46 | *{ margin:0; padding:0; font-family: arial,sans-serif; } | ||||||||||||
| 47 | body{ margin: 0 auto; width: 920px; padding: 0 0 30px; font-size: 14px; line-height: 23px; overflow-y: scroll; } | ||||||||||||
| 48 | a{ color: #4183C4; text-decoration: none; } | ||||||||||||
| 49 | header {margin: 15px 0 15px;} | ||||||||||||
| 50 | header nav{text-align: center;} | ||||||||||||
| 51 | article{padding: .7em;border: 1px solid #E9E9E9;background-color: #F8F8F8;} | ||||||||||||
| 52 | article h1,article h2,article h3,article h4,article h5,article h6{border:0!important;} | ||||||||||||
| 53 | article h1{font-size:170%!important;border-top:4px solid #aaa!important;padding-top:.5em!important;margin-top:1.5em!important;} | ||||||||||||
| 54 | article h1:first-child{margin-top:0!important;padding-top:.25em!important;border-top:none!important;} | ||||||||||||
| 55 | article h2{font-size:150%!important;margin-top:1.5em!important;border-top:4px solid #e0e0e0!important;padding-top:.5em!important;} | ||||||||||||
| 56 | article h3{margin-top:1em!important;} | ||||||||||||
| 57 | article hr{border:1px solid #ddd;} | ||||||||||||
| 58 | article p{margin:1em 0!important;line-height:1.5em!important;} | ||||||||||||
| 59 | article a.absent{color:#a00;} | ||||||||||||
| 60 | article ul{margin:1em 0 1em 2em!important;} | ||||||||||||
| 61 | article ol{margin:1em 0 1em 2em!important;} | ||||||||||||
| 62 | article ul li{margin-top:.5em;margin-bottom:.5em;} | ||||||||||||
| 63 | article ul ul,article ul ol,article ol ol,article ol ul{margin-top:0!important;margin-bottom:0!important;} | ||||||||||||
| 64 | article blockquote{margin:1em 0!important;border-left:5px solid #ddd!important;padding-left:.6em!important;color:#555!important;} | ||||||||||||
| 65 | article dt{font-weight:bold!important;margin-left:1em!important;} | ||||||||||||
| 66 | article dd{margin-left:2em!important;margin-bottom:1em!important;} | ||||||||||||
| 67 | article table{margin:1em 0!important;} | ||||||||||||
| 68 | article table th{border-bottom:1px solid #bbb!important;padding:.2em 1em!important;} | ||||||||||||
| 69 | article table td{border-bottom:1px solid #ddd!important;padding:.2em 1em!important;} | ||||||||||||
| 70 | article pre{margin:1em 0;font-size:12px;background-color:#eee;border:1px solid #ddd;padding:5px;line-height:1.5em;color:#444;overflow:auto;-webkit-box-shadow:rgba(0,0,0,0.07) 0 1px 2px inset;-webkit-border-radius:3px;-moz-border-radius:3px;border-radius:3px;} | ||||||||||||
| 71 | article pre::-webkit-scrollbar{height:8px;width:8px;} | ||||||||||||
| 72 | article pre::-webkit-scrollbar-track-piece{margin-bottom:10px;background-color:#e5e5e5;border-bottom-left-radius:4px 4px;border-bottom-right-radius:4px 4px;border-top-left-radius:4px 4px;border-top-right-radius:4px 4px;} | ||||||||||||
| 73 | article pre::-webkit-scrollbar-thumb:vertical{height:25px;background-color:#ccc;-webkit-border-radius:4px;-webkit-box-shadow:0 1px 1px rgba(255,255,255,1);} | ||||||||||||
| 74 | article pre::-webkit-scrollbar-thumb:horizontal{width:25px;background-color:#ccc;-webkit-border-radius:4px;} | ||||||||||||
| 75 | article pre code{ | ||||||||||||
| 76 | font-family: Monaco, Monospace; | ||||||||||||
| 77 | padding:0!important;font-size:12px!important;background-color:#eee!important;border:none!important; | ||||||||||||
| 78 | } | ||||||||||||
| 79 | article code{ | ||||||||||||
| 80 | font-size:12px!important;background-color:#f8f8ff!important;color:#444!important;padding:0 .2em!important;border:1px solid #dedede!important; | ||||||||||||
| 81 | } | ||||||||||||
| 82 | article a code,article a:link code,article a:visited code{color:#4183c4!important;} | ||||||||||||
| 83 | article img{max-width:100%;} | ||||||||||||
| 84 | EOF | ||||||||||||
| 85 | 3 | } | |||||||||||
| 86 | |||||||||||||
| 87 | 3 | ▶ | sub html_header { | ||||||||||
|
Subroutine
html_header: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||||
| 88 | 3 | my ($self, $title, $req) = @_; | |||||||||||
| 89 | 3 | ▶ | $title ||= 'Index'; | ||||||||||
|
Condition50%1/2
$title ||= "Index"
MC/DC0%0/1
$title ||= "Index"
$title
Truth table50%1/2
A
A= $title
| |||||||||||||
| 90 | |||||||||||||
| 91 | 3 | my $style = $self->style; | |||||||||||
| 92 | 3 | my $script = $self->script( $req ); | |||||||||||
| 93 | |||||||||||||
| 94 | 3 | my $top = $self->base_url; | |||||||||||
| 95 | <<"EOF" | ||||||||||||
| 96 | <!DOCTYPE html> | ||||||||||||
| 97 | <html> | ||||||||||||
| 98 | <head> | ||||||||||||
| 99 | <title>$title</title> | ||||||||||||
| 100 | <style>$style</style> | ||||||||||||
| 101 | <script>$script</script> | ||||||||||||
| 102 | </head> | ||||||||||||
| 103 | <body> | ||||||||||||
| 104 | <header><nav> | ||||||||||||
| 105 | <a href="$top">TOP</a> | ||||||||||||
| 106 | <a href="?refresh=800">Auto Refresh</a> | ||||||||||||
| 107 | </nav></header> | ||||||||||||
| 108 | <article> | ||||||||||||
| 109 | EOF | ||||||||||||
| 110 | 3 | } | |||||||||||
| 111 | |||||||||||||
| 112 | 3 | ▶ | sub html_footer { | ||||||||||
|
Subroutine
html_footer: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||
| 113 | <<"EOF" | ||||||||||||
| 114 | </article> | ||||||||||||
| 115 | </body> | ||||||||||||
| 116 | </html> | ||||||||||||
| 117 | EOF | ||||||||||||
| 118 | 3 | } | |||||||||||
| 119 | |||||||||||||
| 120 | =head1 NAME | ||||||||||||
| 121 | |||||||||||||
| 122 | DocLife::Markdown - Markdown Viewer. | ||||||||||||
| 123 | |||||||||||||
| 124 | =head1 SYNOPSIS | ||||||||||||
| 125 | |||||||||||||
| 126 | # app.psgi | ||||||||||||
| 127 | use DocLife::Markdown; | ||||||||||||
| 128 | DocLife::Markdown->new( root => "./doc", suffix => ".md" ); | ||||||||||||
| 129 | |||||||||||||
| 130 | # one-liner | ||||||||||||
| 131 | plackup -MDocLife::Markdown -e 'DocLife::Markdown->new( root => "./doc" )->to_app' | ||||||||||||
| 132 | |||||||||||||
| 133 | =head1 SEE ALSO | ||||||||||||
| 134 | |||||||||||||
| 135 | L<DocLife>, L<Text::Markdown> | ||||||||||||
| 136 | |||||||||||||
| 137 | =cut | ||||||||||||
| 138 | |||||||||||||
| 139 | 1 | 1; | |||||||||||