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