Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 109 lines (97 sloc) 2.981 kb
8797ffa @tadzik Implement DOC phasers. Fix compilation options. Add a simple Pod::To:…
tadzik authored
1 module Pod::To::Text;
2
3 sub pod2text($pod) is export {
4472ab8 @tadzik Add declarator blocks support to Pod::To::Text
tadzik authored
4 my @declarators;
8797ffa @tadzik Implement DOC phasers. Fix compilation options. Add a simple Pod::To:…
tadzik authored
5 given $pod {
6 when Pod::Heading { heading2text($pod) }
083287a @tadzik Small tunes in Pod::To::Text, sanitize newline handling, interpret pa…
tadzik authored
7 when Pod::Block::Code { code2text($pod) }
8 when Pod::Block::Named { named2text($pod) }
9 when Pod::Block::Para { para2text($pod) }
77c62ce @tadzik [Pod::To::Text] Generate proper output for Tables and Comments, fix o…
tadzik authored
10 when Pod::Block::Table { table2text($pod) }
4472ab8 @tadzik Add declarator blocks support to Pod::To::Text
tadzik authored
11 when Pod::Block::Declarator { declarator2text($pod) }
083287a @tadzik Small tunes in Pod::To::Text, sanitize newline handling, interpret pa…
tadzik authored
12 when Pod::Item { item2text($pod) }
5f145c6 @tadzik Implement simple FormattinCode handling in Pod::To::Text
tadzik authored
13 when Pod::FormattingCode { formatting2text($pod) }
083287a @tadzik Small tunes in Pod::To::Text, sanitize newline handling, interpret pa…
tadzik authored
14 when Positional { $pod.map({pod2text($_)}).join("\n\n")}
77c62ce @tadzik [Pod::To::Text] Generate proper output for Tables and Comments, fix o…
tadzik authored
15 when Pod::Block::Comment { }
585cd06 @tadzik The Pod tree should not contain bare strings. Use Pod::Block::Para, a…
tadzik authored
16 default { $pod.Str }
8797ffa @tadzik Implement DOC phasers. Fix compilation options. Add a simple Pod::To:…
tadzik authored
17 }
18 }
19
20 sub heading2text($pod) {
21 given $pod.level {
585cd06 @tadzik The Pod tree should not contain bare strings. Use Pod::Block::Para, a…
tadzik authored
22 when 1 { pod2text($pod.content) }
23 when 2 { ' ' ~ pod2text($pod.content) }
24 default { ' ' ~ pod2text($pod.content) }
8797ffa @tadzik Implement DOC phasers. Fix compilation options. Add a simple Pod::To:…
tadzik authored
25 }
26 }
27
28 sub code2text($pod) {
585cd06 @tadzik The Pod tree should not contain bare strings. Use Pod::Block::Para, a…
tadzik authored
29 " " ~ $pod.content.subst(/\n/, "\n ", :g)
8797ffa @tadzik Implement DOC phasers. Fix compilation options. Add a simple Pod::To:…
tadzik authored
30 }
31
32 sub item2text($pod) {
585cd06 @tadzik The Pod tree should not contain bare strings. Use Pod::Block::Para, a…
tadzik authored
33 ' * ' ~ pod2text($pod.content).chomp.chomp
8797ffa @tadzik Implement DOC phasers. Fix compilation options. Add a simple Pod::To:…
tadzik authored
34 }
35
36 sub named2text($pod) {
90e9c38 @tadzik Couple of more fixes to make the output generated from S26 more pleas…
tadzik authored
37 given $pod.name {
38 when 'pod' { pod2text($pod.content) }
39 when 'para' { para2text($pod.content[0]) }
40 when 'defn' { pod2text($pod.content[0]) ~ "\n"
41 ~ pod2text($pod.content[1..*-1]) }
42 when 'config' { }
43 when 'nested' { }
44 default { $pod.name ~ "\n" ~ pod2text($pod.content) }
45 }
585cd06 @tadzik The Pod tree should not contain bare strings. Use Pod::Block::Para, a…
tadzik authored
46 }
47
48 sub para2text($pod) {
5f145c6 @tadzik Implement simple FormattinCode handling in Pod::To::Text
tadzik authored
49 twine2text($pod.content)
8797ffa @tadzik Implement DOC phasers. Fix compilation options. Add a simple Pod::To:…
tadzik authored
50 }
51
77c62ce @tadzik [Pod::To::Text] Generate proper output for Tables and Comments, fix o…
tadzik authored
52 sub table2text($pod) {
f147bf8 @tadzik [Pod::To::Text] Align table columns
tadzik authored
53 my @rows = $pod.content;
54 @rows.unshift($pod.headers.item) if $pod.headers;
55 my @maxes;
56 for 0..(@rows[1].elems - 1) -> $i {
57 @maxes.push([max] @rows.map({ $_[$i].chars }));
58 }
59 my $ret = $pod.caption // '';
60 for @rows -> $row {
61 for 0..($row.elems - 1) -> $i {
62 $ret ~= $row[$i].fmt("%{@maxes[$i]}s") ~ " ";
63 }
64 $ret ~= "\n";
65 }
66 return $ret;
77c62ce @tadzik [Pod::To::Text] Generate proper output for Tables and Comments, fix o…
tadzik authored
67 }
68
4472ab8 @tadzik Add declarator blocks support to Pod::To::Text
tadzik authored
69 sub declarator2text($pod) {
70 next unless $pod.WHEREFORE.WHY;
b3e3008 @tadzik [Pod::To::Text] Make object stringification in declarator2text less i…
tadzik authored
71 my $what = do given $pod.WHEREFORE {
4472ab8 @tadzik Add declarator blocks support to Pod::To::Text
tadzik authored
72 when Method {
b3e3008 @tadzik [Pod::To::Text] Make object stringification in declarator2text less i…
tadzik authored
73 'method ' ~ $_.name
4472ab8 @tadzik Add declarator blocks support to Pod::To::Text
tadzik authored
74 }
75 when Sub {
b3e3008 @tadzik [Pod::To::Text] Make object stringification in declarator2text less i…
tadzik authored
76 'sub ' ~ $_.name
4472ab8 @tadzik Add declarator blocks support to Pod::To::Text
tadzik authored
77 }
78 when nqp::p6bool(nqp::istype($_.HOW, Metamodel::ClassHOW)) {
b3e3008 @tadzik [Pod::To::Text] Make object stringification in declarator2text less i…
tadzik authored
79 'class ' ~ $_.perl
4472ab8 @tadzik Add declarator blocks support to Pod::To::Text
tadzik authored
80 }
81 when nqp::p6bool(nqp::istype($_.HOW, Metamodel::ModuleHOW)) {
b3e3008 @tadzik [Pod::To::Text] Make object stringification in declarator2text less i…
tadzik authored
82 'module ' ~ $_.perl
4472ab8 @tadzik Add declarator blocks support to Pod::To::Text
tadzik authored
83 }
083287a @tadzik Small tunes in Pod::To::Text, sanitize newline handling, interpret pa…
tadzik authored
84 when nqp::p6bool(nqp::istype($_.HOW, Metamodel::PackageHOW)) {
b3e3008 @tadzik [Pod::To::Text] Make object stringification in declarator2text less i…
tadzik authored
85 'package ' ~ $_.perl
083287a @tadzik Small tunes in Pod::To::Text, sanitize newline handling, interpret pa…
tadzik authored
86 }
ada28b6 @tadzik [Pod::To::Text] Tune and clarify declarator2text() a bit
tadzik authored
87 default {
88 ''
89 }
90 }
b3e3008 @tadzik [Pod::To::Text] Make object stringification in declarator2text less i…
tadzik authored
91 return "$what: {$pod.WHEREFORE.WHY.content}"
4472ab8 @tadzik Add declarator blocks support to Pod::To::Text
tadzik authored
92 }
93
5f145c6 @tadzik Implement simple FormattinCode handling in Pod::To::Text
tadzik authored
94 sub formatting2text($pod) {
95 twine2text($pod.content)
96 }
97
98 sub twine2text($twine) {
99 return '' unless $twine.elems;
100 my $r = $twine[0];
101 for $twine[1..*] -> $f, $s {
102 $r ~= twine2text($f.content);
103 $r ~= $s;
104 }
105 return $r;
106 }
107
8797ffa @tadzik Implement DOC phasers. Fix compilation options. Add a simple Pod::To:…
tadzik authored
108 # vim: ft=perl6
Something went wrong with that request. Please try again.