| 1 | # | ||||||||||||||||||||||||||||
| 2 | # Copyright (c) 2014-2015 Christian Jaeger, copying@christianjaeger.ch | ||||||||||||||||||||||||||||
| 3 | # | ||||||||||||||||||||||||||||
| 4 | # This is free software, offered under either the same terms as perl 5 | ||||||||||||||||||||||||||||
| 5 | # or the terms of the Artistic License version 2 or the terms of the | ||||||||||||||||||||||||||||
| 6 | # MIT License (Expat version). See the file COPYING.md that came | ||||||||||||||||||||||||||||
| 7 | # bundled with this file. | ||||||||||||||||||||||||||||
| 8 | # | ||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | =head1 NAME | ||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | FunctionalPerl::Htmlgen::PathTranslate | ||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | Configurable source path (.md suffix) to website path (.xhtml suffix | ||||||||||||||||||||||||||||
| 19 | or similar, index instead of README etc.) mapper. | ||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | =head1 NOTE | ||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | This is alpha software! Read the status section in the package README | ||||||||||||||||||||||||||||
| 24 | or on the L<website|http://functional-perl.org/>. | ||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | =cut | ||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | package FunctionalPerl::Htmlgen::PathTranslate; | ||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 31 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 32 | 2 | ▶ | use warnings FATAL => 'uninitialized'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 33 | 2 | ▶ | use experimental "signatures"; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | 2 | ▶ | use Chj::TEST; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 37 | 2 | ▶ | use FP::Predicates; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 38 | 2 | ▶ | use Chj::xperlfunc qw(dirname basename); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 39 | 2 | ▶ | use FunctionalPerl::Htmlgen::PathUtil qw(path_path0_append); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 40 | 2 | ▶ | use FP::Div qw(identity); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 41 | 2 | ▶ | use FunctionalPerl::Htmlgen::default_config; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 42 | 2 | ▶ | use FP::Show; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 43 | 2 | ▶ | use FP::Predicates 'false'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | our $t = __PACKAGE__->new_( | ||||||||||||||||||||||||||||
| 46 | is_indexpath0 => $$default_config{is_indexpath0}, | ||||||||||||||||||||||||||||
| 47 | 2 | downcaps => 1 | |||||||||||||||||||||||||||
| 48 | ); | ||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | 6 | ▶ | sub t_if_suffix_md_to_html ($in, $for_title = 0) { | ||||||||||||||||||||||||||
|
Subroutine
t_if_suffix_md_to_html: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 51 | $t->if_suffix_md_to_html( | ||||||||||||||||||||||||||||
| 52 | $in, $for_title, | ||||||||||||||||||||||||||||
| 53 | sub { ["then", @_] }, | ||||||||||||||||||||||||||||
| 54 | sub { ["otherwise", @_] } | ||||||||||||||||||||||||||||
| 55 | ) | ||||||||||||||||||||||||||||
| 56 | 6 | } | |||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | 8 | ▶ | sub is_allcaps($str) { | ||||||||||||||||||||||||||
|
Subroutine
is_allcaps: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 59 | 8 | not $str =~ /[a-z]/ | |||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | 6 | ▶ | sub _path0_to_title_mod($str) { | ||||||||||||||||||||||||||
|
Subroutine
_path0_to_title_mod: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 63 | 6 | $str =~ s/_/ /sg; | |||||||||||||||||||||||||||
| 64 | 6 | ucfirst $str | |||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | # ------------------------------------------------------------------ | ||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | 2 | ▶ | use FP::Struct [[\&is_procedure, "is_indexpath0"], [\&is_boolean, "downcaps"],]; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | 0 | ▶ | sub is_md ($self, $path) { | ||||||||||||||||||||||||||
|
Subroutine
is_md: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 72 | 0 | $path =~ /\.md$/s | |||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | 15 | ▶ | sub if_suffix_md_to_html ($self, $path0, $for_title, $then, $otherwise) { | ||||||||||||||||||||||||||
|
Subroutine
if_suffix_md_to_html: called CC=6 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 76 | 15 | ▶ | if (!$for_title and $$self{is_indexpath0}->($path0)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
not $for_title and $self->{"is_indexpath0"}->($path0)
MC/DC100%2/2
not $for_title and $self->{"is_indexpath0"}->($path0)
not $for_title
$self->{"is_indexpath0"}->($path0)
Truth table100%3/3
not(A) and B
A= not $for_titleB= $self->{"is_indexpath0"}->($path0)
| |||||||||||||||||||||||||||||
| 77 | 4 | @_=(path_path0_append(dirname($path0), "index.xhtml")); goto &$then | |||||||||||||||||||||||||||
| 78 | } else { | ||||||||||||||||||||||||||||
| 79 | 11 | ▶ | if ($path0 =~ s/(.*?)([^\/]*)\.md$/$1$2.xhtml/) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 80 | @_=($$self{downcaps} | ||||||||||||||||||||||||||||
| 81 | 8 | ▶ | && is_allcaps($2) ? $1 . lc($2) . ".xhtml" : $path0); goto &$then; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$self->{"downcaps"} and is_allcaps($2)
MC/DC50%1/2
$self->{"downcaps"} and is_allcaps($2)
$self->{"downcaps"}
is_allcaps($2)
Truth table66%2/3
A and B
A= $self->{"downcaps"}B= is_allcaps($2)
| |||||||||||||||||||||||||||||
| 82 | } else { | ||||||||||||||||||||||||||||
| 83 | 3 | @_=($path0); goto &$otherwise | |||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||
| 88 | 1 | ▶ | TEST { t_if_suffix_md_to_html "README.md" }['then', 'index.xhtml']; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 89 | 1 | ▶ | TEST { t_if_suffix_md_to_html "README.md", 1 }['then', 'readme.xhtml']; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | # ^ kinda stupid hack. | ||||||||||||||||||||||||||||
| 92 | 1 | ▶ | TEST { t_if_suffix_md_to_html "Foo/index.md" }['then', 'Foo/index.xhtml']; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 93 | 1 | ▶ | TEST { t_if_suffix_md_to_html "Foo/README.md" }['then', 'Foo/index.xhtml']; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 94 | 1 | ▶ | TEST { t_if_suffix_md_to_html "Foo/READMe.md" }['then', 'Foo/index.xhtml']; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||
| 96 | # ^ XX really? | ||||||||||||||||||||||||||||
| 97 | 1 | ▶ | TEST { t_if_suffix_md_to_html "Foo/MY.css" }['otherwise', 'Foo/MY.css']; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||
| 99 | 2 | ▶ | sub possibly_suffix_md_to_html ($self, $path, $for_title = 0) { | ||||||||||||||||||||||||||
|
Subroutine
possibly_suffix_md_to_html: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 100 | 2 | $self->if_suffix_md_to_html($path, $for_title, \&identity, \&identity) | |||||||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||
| 103 | 7 | ▶ | sub xsuffix_md_to_html ($self, $path0, $for_title) { | ||||||||||||||||||||||||||
|
Subroutine
xsuffix_md_to_html: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 104 | $self->if_suffix_md_to_html($path0, $for_title, \&identity, | ||||||||||||||||||||||||||||
| 105 | 1 | ▶ | sub { die "file does not end in .md: " . show($path0) }) | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 106 | 7 | } | |||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||
| 108 | 1 | ▶ | TEST { $t->possibly_suffix_md_to_html("foo") } "foo"; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 109 | 1 | ▶ | TEST { $t->possibly_suffix_md_to_html("foo.md") } "foo.xhtml"; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 110 | 1 | ▶ | TEST_EXCEPTION { $t->xsuffix_md_to_html("foo", 0) } | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 111 | 2 | "file does not end in .md: 'foo'"; | |||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||
| 113 | 6 | ▶ | sub path0_to_title ($self, $path0) { | ||||||||||||||||||||||||||
|
Subroutine
path0_to_title: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 114 | 6 | my $dn = dirname($path0); | |||||||||||||||||||||||||||
| 115 | 6 | ▶ | if ($dn ne "." and $$self{is_indexpath0}->($path0)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$dn ne "." and $self->{"is_indexpath0"}->($path0)
MC/DC100%2/2
$dn ne "." and $self->{"is_indexpath0"}->($path0)
$dn ne "."
$self->{"is_indexpath0"}->($path0)
Truth table100%3/3
A and B
A= $dn ne "."B= $self->{"is_indexpath0"}->($path0)
| |||||||||||||||||||||||||||||
| 116 | 2 | _path0_to_title_mod basename($self->xsuffix_md_to_html($dn . ".md", 1), | |||||||||||||||||||||||||||
| 117 | ".xhtml"); | ||||||||||||||||||||||||||||
| 118 | } else { | ||||||||||||||||||||||||||||
| 119 | 4 | _path0_to_title_mod basename($self->xsuffix_md_to_html($path0, 1), | |||||||||||||||||||||||||||
| 120 | ".xhtml"); | ||||||||||||||||||||||||||||
| 121 | } | ||||||||||||||||||||||||||||
| 122 | } | ||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||
| 124 | 1 | ▶ | TEST { $t->path0_to_title("README.md") } 'Readme'; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 125 | 1 | ▶ | TEST { $t->path0_to_title("bugs/wishlist/listserv/index.md") } 'Listserv'; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 126 | 1 | ▶ | TEST { $t->path0_to_title("bugs/wishlist/listserv/README.md") } 'Listserv'; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 127 | 1 | ▶ | TEST { $t->path0_to_title("bugs/wishlist/listserv/other.md") } 'Other'; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||
| 129 | 1 | ▶ | TEST { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 130 | 1 | $t->is_indexpath0_set(\&false) | |||||||||||||||||||||||||||
| 131 | ->path0_to_title("bugs/wishlist/listserv/README.md") | ||||||||||||||||||||||||||||
| 132 | } | ||||||||||||||||||||||||||||
| 133 | 2 | 'Readme'; | |||||||||||||||||||||||||||
| 134 | 1 | ▶ | TEST { $t->path0_to_title("bugs/wishlist/line_wrapping_in_pre-MIME_mails.md") } | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||
| 136 | # even with lcfirst | ||||||||||||||||||||||||||||
| 137 | 2 | 'Line wrapping in pre-MIME mails'; | |||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||
| 139 | 0 | ▶ | sub path0_to_bugtype ($self, $path0) { | ||||||||||||||||||||||||||
|
Subroutine
path0_to_bugtype: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 140 | 0 | ▶ | $path0 =~ m|\bbugs/([^/]+)/| or die "no match, '$path0'"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 141 | 0 | ucfirst $1 | |||||||||||||||||||||||||||
| 142 | } | ||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||
| 144 | 2 | _END_ | |||||||||||||||||||||||||||