-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathpod2onepage
executable file
·102 lines (86 loc) · 3.63 KB
/
pod2onepage
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#! /usr/bin/env perl6
use v6;
use Pod::To::BigPage;
use MONKEY-SEE-NO-EVAL; # To be able to extract pods.
my &verbose = sub (|c) {};
#| Returns the index of the next part to process
sub next-part-index () {
state $lock = Lock.new;
state $global-part-index = -1;
my $clone;
$lock.protect: {
$clone = $global-part-index++;
}
$clone
}
sub MAIN (Bool :v(:verbose($v)), Str :$source-path = ".", Str :$exclude,
Bool :$no-cache = False,
Bool :$html = False,
Str :$title = "Converted POD6 documentation",
Int :$threads = %*ENV<THREADS>.?Int // 1,
Bool :$anchored = True,
Str :$precomp-path = (%*ENV<TEMP> // %*ENV<TMP> // '/tmp') ~ '/PodToBigfile-precomp'
) {
my @exclude = $exclude.defined ?? $exclude.split: ',' !! ();
&verbose = ¬e if $v;
set-verbose(&verbose);
PROCESS::<$SCHEDULER> = ThreadPoolScheduler.new(initial_threads => 0, max_threads => $threads);
my $precomp-store = CompUnit::PrecompilationStore::File.new(prefix => $precomp-path.IO );
my $precomp = CompUnit::PrecompilationRepository::Default.new(store => $precomp-store);
setup();
my @toc;
set-foreign-toc(@toc);
put compose-before-content( $title, $html??''!!'x' );
if $threads > 1 {
put await do start {
.&parse-pod-file( next-part-index, just-the-name($_,$source-path), $precomp, $no-cache, $anchored )
} for sort find-pod-files($source-path, @exclude);
}
else {
put do {
.&parse-pod-file( next-part-index, just-the-name($_, $source-path), $precomp, $no-cache, $anchored )
} for sort find-pod-files($source-path, @exclude);
}
put compose-left-side-menu() ~ compose-after-content();
}
my $precomp-lock = Lock.new;
#! Parses every pod file, using the precomp cache if available and enabled.
sub parse-pod-file ($f, $part-number, $pod-name is copy, $precomp, $disable-cache, $anchored) {
my $io = $f.IO;
my $pod is default(Failure.new("could not compile pod"));
if $disable-cache {
$pod = (EVAL ($io.slurp ~ "\n\$=pod"));
verbose "processed $f";
}
else {
use nqp;
my $id = nqp::sha1(~$f);
$precomp-lock.protect: {
my $handle = $precomp.load($id, :since($io.modified))[0];
my $cached = "(cached)";
without $handle {
$precomp.precompile($io, $id, :force);
$handle = $precomp.load($id)[0] // fail("Could not precompile $f");
$cached = "";
}
verbose "processed $f $cached";
$pod = nqp::atkey($handle.unit,'$=pod')[0];
}
}
$pod-name = $pod-name.subst('/Language/', '/language/').subst('/Type/', '/type/');
my $html = $pod>>.&handle(:$pod-name,
part-number => $part-number,
toc-counter => TOC-Counter.new.set-part-number($part-number),
part-config => { anchored => $anchored,
:head1(:numbered(True)),
:head2(:numbered(True)),
:head3(:numbered(True)),
:head4(:numbered(True))
}
);
return Q:c[<!-- {$pod-name} --><div class="pod-body"><a id="{$pod-name.subst('/', '_', :g)}"></a>{$html}</div>];
}
#! Returns the name of the file, taking into account the document source path
sub just-the-name( $filename, $source-path ) {
return $source-path eq "." ?? $filename !! $filename.substr($source-path.chars);
}