Skip to content

Commit bb2165a

Browse files
committed
Work in progress on using my new version of Pod::To::HTML
1 parent 98deab8 commit bb2165a

File tree

6 files changed

+124
-93
lines changed

6 files changed

+124
-93
lines changed

htmlify.p6

Lines changed: 13 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -21,69 +21,26 @@ use MONKEY-SEE-NO-EVAL;
2121

2222
BEGIN say 'Initializing ...';
2323

24-
use Pod::To::HTML;
2524
use URI::Escape;
26-
use lib 'lib';
27-
use Perl6::TypeGraph;
28-
use Perl6::TypeGraph::Viz;
25+
26+
use lib 'lib', '../Pod-TreeWalker/lib';
27+
use DocSite::Pod::To::HTML;
2928
use Perl6::Documentable::Registry;
29+
use Perl6::TypeGraph::Viz;
30+
use Perl6::TypeGraph;
3031
use Pod::Convenience;
3132
use Pod::Htmlify;
3233

33-
use experimental :cached;
34-
3534
my $type-graph;
3635
my %routines-by-type;
3736
my %*POD2HTML-CALLBACKS;
3837

39-
# TODO: Generate menulist automatically
40-
my @menu =
41-
('language','' ) => (),
42-
('type', 'Types' ) => <basic composite domain-specific exceptions>,
43-
('routine', 'Routines' ) => <sub method term operator>,
44-
# ('module', 'Modules' ) => (),
45-
# ('formalities','' ) => ();
46-
;
47-
48-
my $head = slurp 'template/head.html';
49-
sub header-html ($current-selection = 'nothing selected') is cached {
50-
state $header = slurp 'template/header.html';
51-
52-
my $menu-items = [~]
53-
q[<div class="menu-items dark-green">],
54-
@menu>>.key.map(-> ($dir, $name) {qq[
55-
<a class="menu-item {$dir eq $current-selection ?? "selected darker-green" !! ""}"
56-
href="/$dir.html">
57-
{ $name || $dir.wordcase }
58-
</a>
59-
]}), #"
60-
q[</div>];
61-
62-
my $sub-menu-items = '';
63-
state %sub-menus = @menu>>.key>>[0] Z=> @menu>>.value;
64-
if %sub-menus{$current-selection} -> $_ {
65-
$sub-menu-items = [~]
66-
q[<div class="menu-items darker-green">],
67-
qq[<a class="menu-item" href="/$current-selection.html">All</a>],
68-
.map({qq[
69-
<a class="menu-item" href="/$current-selection\-$_.html">
70-
{.wordcase}
71-
</a>
72-
]}),
73-
q[</div>]
74-
}
75-
76-
state $menu-pos = ($header ~~ /MENU/).from;
77-
$header.subst('MENU', :p($menu-pos), $menu-items ~ $sub-menu-items);
78-
}
79-
8038
sub p2h($pod, $selection = 'nothing selected', :$pod-path = 'unknown') {
81-
pod2html $pod,
82-
:url(&url-munge),
83-
:$head,
84-
:header(header-html $selection),
85-
:footer(footer-html($pod-path)),
86-
:default-title("Perl 6 Documentation"),
39+
return DocSite::Pod::To::HTML.new(
40+
:selection($selection),
41+
:pod-path($pod-path),
42+
:title('Perl 6 Documentation'),
43+
).pod-to-html($pod);
8744
}
8845

8946
sub recursive-dir($dir) {
@@ -243,9 +200,9 @@ multi write-type-source($doc) {
243200
to the documentation pages for the related types. If not, try the
244201
<a href="/images/type-graph-{uri_escape $podname}.png">PNG
245202
version</a> instead.</p>];
246-
$pod.contents.append: Pod::Raw.new(
247-
target => 'html',
248-
contents => $tg-preamble ~ svg-for-file("html/images/type-graph-$podname.svg"),
203+
$pod.contents.append: Pod::Block::Named.new(
204+
name => 'html',
205+
contents => [$tg-preamble ~ svg-for-file("html/images/type-graph-$podname.svg")],
249206

250207
);
251208

lib/DocSite/Pod/To/HTML.pm

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
use v6;
2+
use Pod::To::HTML::Renderer;
3+
4+
unit class DocSite::Pod::To::HTML is Pod::To::HTML::Renderer;
5+
6+
use URI::Escape;
7+
8+
has $!selection;
9+
has $!pod-path;
10+
11+
submethod BUILD (Str:D :$!selection, Str:D :$!pod-path) { }
12+
13+
method prelude-template {
14+
state $head = slurp 'template/head.html';
15+
16+
my $default = callsame;
17+
return
18+
$default.subst( rx{ '</head>' }, $head ~ '</head>' )
19+
~ self!header-for-selection($!selection);
20+
}
21+
22+
method !header-for-selection ($current-selection) {
23+
state %header-for-selection = ();
24+
return %header-for-selection{$current-selection}
25+
//= self!make-header-for($current-selection);
26+
}
27+
28+
method !make-header-for ($current-selection) {
29+
state $header = slurp 'template/header.html';
30+
31+
# TODO: Generate menulist automatically
32+
state @menu =
33+
('language', q{} ) => (),
34+
('type', 'Types' ) => <basic composite domain-specific exceptions>,
35+
('routine', 'Routines' ) => <sub method term operator>,
36+
# ('module', 'Modules' ) => (),
37+
# ('formalities', q{} ) => ()
38+
;
39+
40+
my $menu-items = [~]
41+
q[<div class="menu-items dark-green">],
42+
@menu>>.key.map(-> ($dir, $name) {qq[
43+
<a class="menu-item {$dir eq $current-selection ?? "selected darker-green" !! ""}"
44+
href="/$dir.html">
45+
{ $name || $dir.wordcase }
46+
</a>
47+
]}), #"
48+
q[</div>];
49+
50+
my $sub-menu-items = '';
51+
state %sub-menus = @menu>>.key>>[0] Z=> @menu>>.value;
52+
if %sub-menus{$current-selection} -> $_ {
53+
$sub-menu-items = [~]
54+
q[<div class="menu-items darker-green">],
55+
qq[<a class="menu-item" href="/$current-selection.html">All</a>],
56+
.map({qq[
57+
<a class="menu-item" href="/$current-selection\-$_.html">
58+
{.wordcase}
59+
</a>
60+
]}),
61+
q[</div>]
62+
}
63+
64+
state $menu-pos = ($header ~~ /MENU/).from;
65+
66+
return $header.subst('MENU', :p($menu-pos), $menu-items ~ $sub-menu-items);
67+
}
68+
69+
method render-postlude {
70+
my $footer = slurp 'template/footer.html';
71+
$footer.subst-mutate(/DATETIME/, ~DateTime.now);
72+
my $pod-url;
73+
my $gh-link = q[<a href='https://github.com/perl6/doc'>perl6/doc on GitHub</a>];
74+
if $!pod-path eq "unknown" {
75+
$pod-url = "the sources at $gh-link";
76+
}
77+
else {
78+
$pod-url = "<a href='https://github.com/perl6/doc/raw/master/doc/$!pod-path'>$!pod-path\</a\> from $gh-link";
79+
}
80+
$footer.subst-mutate(/SOURCEURL/, $pod-url);
81+
82+
return $footer;
83+
}
84+
85+
#| Find links like L<die> and L<Str> and give them the proper path
86+
method url-and-text-for (Str:D $thing) {
87+
given $thing {
88+
when /^ <[A..Z]>/ {
89+
return ( '/type/' ~ uri_escape($thing), $thing );
90+
}
91+
when /^ <[a..z]> | ^ <-alpha>* $/ {
92+
return ( '/routine/' ~ uri_escape($thing), $thing );
93+
}
94+
when / ^ '&'( \w <[[\w'-]>* ) $/ {
95+
return ( '/routine/' ~ uri_escape($0), $0 );
96+
}
97+
}
98+
99+
callsame;
100+
}

lib/Pod/Htmlify.pm6

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2,35 +2,6 @@ unit module Pod::Htmlify;
22

33
use URI::Escape;
44

5-
#| Escape special characters in URLs if necessary
6-
sub url-munge($_) is export {
7-
return $_ if m{^ <[a..z]>+ '://'};
8-
return "/type/{uri_escape $_}" if m/^<[A..Z]>/;
9-
return "/routine/{uri_escape $_}" if m/^<[a..z]>|^<-alpha>*$/;
10-
# poor man's <identifier>
11-
if m/ ^ '&'( \w <[[\w'-]>* ) $/ {
12-
return "/routine/{uri_escape $0}";
13-
}
14-
return $_;
15-
}
16-
17-
#| Return the footer HTML for each page
18-
sub footer-html($pod-path) is export {
19-
my $footer = slurp 'template/footer.html';
20-
$footer.subst-mutate(/DATETIME/, ~DateTime.now);
21-
my $pod-url;
22-
my $gh-link = q[<a href='https://github.com/perl6/doc'>perl6/doc on GitHub</a>];
23-
if $pod-path eq "unknown" {
24-
$pod-url = "the sources at $gh-link";
25-
}
26-
else {
27-
$pod-url = "<a href='https://github.com/perl6/doc/raw/master/doc/$pod-path'>$pod-path\</a\> from $gh-link";
28-
}
29-
$footer.subst-mutate(/SOURCEURL/, $pod-url);
30-
31-
return $footer;
32-
}
33-
345
#| Return the SVG for the given file, without its XML header
356
sub svg-for-file($file) is export {
367
join "\n", grep { /^'<svg'/ ff False }, $file.IO.lines;

template/footer.html

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
</div>
1+
</div>
22
</div>
33
<div id="footer-wrapper">
44
<div id="footer" class="pretty-box yellow">
@@ -19,3 +19,6 @@
1919
<script type="text/javascript" src="/js/jquery-ui.min.js"></script>
2020
<script type="text/javascript" src="/js/search.js"></script>
2121
<script type="text/javascript" src="/js/main.js"></script>
22+
23+
</body>
24+
</html>

template/head.html

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
<meta name=viewport content="width=device-width, initial-scale=1">
2-
<link rel="icon" href="/favicon.ico" type="image/x-icon" />
3-
<link rel="stylesheet" type="text/css" href="/css/style.css" media="screen" title="default" />
4-
<link type="text/css" href="/css/custom-theme/jquery-ui.css" rel="stylesheet" />
5-
<link type="text/css" href="/css/pygments.css" rel="stylesheet" />
6-
<noscript> <style> #search { visibility: hidden; } </style> </noscript>
1+
<meta name=viewport content="width=device-width, initial-scale=1">
2+
<link rel="icon" href="/favicon.ico" type="image/x-icon" />
3+
<link rel="stylesheet" type="text/css" href="/css/style.css" media="screen" title="default" />
4+
<link type="text/css" href="/css/custom-theme/jquery-ui.css" rel="stylesheet" />
5+
<link type="text/css" href="/css/pygments.css" rel="stylesheet" />
6+
<noscript> <style> #search { visibility: hidden; } </style> </noscript>

template/header.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@
1111
</div>
1212
</div>
1313
<div id="content-wrapper">
14-
<div id="content" class="pretty-box yellow">
14+
<div id="content" class="pretty-box yellow">

0 commit comments

Comments
 (0)