Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 124 lines (111 sloc) 3.424 kb
626ef2a8 » tadzik
2012-04-21 Make perl6 --doc=HTML etc do what it should.
1 class Pod::To::Text;
2
3 method render($pod) {
4 pod2text($pod)
5 }
8797ffa0 » tadzik
2011-07-31 Implement DOC phasers. Fix compilation options. Add a simple Pod::To:…
6
7 sub pod2text($pod) is export {
4472ab81 » tadzik
2011-08-06 Add declarator blocks support to Pod::To::Text
8 my @declarators;
8797ffa0 » tadzik
2011-07-31 Implement DOC phasers. Fix compilation options. Add a simple Pod::To:…
9 given $pod {
10 when Pod::Heading { heading2text($pod) }
083287a0 » tadzik
2011-08-09 Small tunes in Pod::To::Text, sanitize newline handling, interpret pa…
11 when Pod::Block::Code { code2text($pod) }
12 when Pod::Block::Named { named2text($pod) }
13 when Pod::Block::Para { para2text($pod) }
77c62ce5 » tadzik
2011-08-09 [Pod::To::Text] Generate proper output for Tables and Comments, fix o…
14 when Pod::Block::Table { table2text($pod) }
4472ab81 » tadzik
2011-08-06 Add declarator blocks support to Pod::To::Text
15 when Pod::Block::Declarator { declarator2text($pod) }
083287a0 » tadzik
2011-08-09 Small tunes in Pod::To::Text, sanitize newline handling, interpret pa…
16 when Pod::Item { item2text($pod) }
5f145c64 » tadzik
2011-08-14 Implement simple FormattinCode handling in Pod::To::Text
17 when Pod::FormattingCode { formatting2text($pod) }
083287a0 » tadzik
2011-08-09 Small tunes in Pod::To::Text, sanitize newline handling, interpret pa…
18 when Positional { $pod.map({pod2text($_)}).join("\n\n")}
77c62ce5 » tadzik
2011-08-09 [Pod::To::Text] Generate proper output for Tables and Comments, fix o…
19 when Pod::Block::Comment { }
16833977 » tadzik
2012-06-07 [Pod::To::Text] Avoid stringifying Pod::Config blocks
20 when Pod::Config { }
585cd06c » tadzik
2011-07-31 The Pod tree should not contain bare strings. Use Pod::Block::Para, a…
21 default { $pod.Str }
8797ffa0 » tadzik
2011-07-31 Implement DOC phasers. Fix compilation options. Add a simple Pod::To:…
22 }
23 }
24
25 sub heading2text($pod) {
26 given $pod.level {
585cd06c » tadzik
2011-07-31 The Pod tree should not contain bare strings. Use Pod::Block::Para, a…
27 when 1 { pod2text($pod.content) }
28 when 2 { ' ' ~ pod2text($pod.content) }
29 default { ' ' ~ pod2text($pod.content) }
8797ffa0 » tadzik
2011-07-31 Implement DOC phasers. Fix compilation options. Add a simple Pod::To:…
30 }
31 }
32
33 sub code2text($pod) {
585cd06c » tadzik
2011-07-31 The Pod tree should not contain bare strings. Use Pod::Block::Para, a…
34 " " ~ $pod.content.subst(/\n/, "\n ", :g)
8797ffa0 » tadzik
2011-07-31 Implement DOC phasers. Fix compilation options. Add a simple Pod::To:…
35 }
36
37 sub item2text($pod) {
585cd06c » tadzik
2011-07-31 The Pod tree should not contain bare strings. Use Pod::Block::Para, a…
38 ' * ' ~ pod2text($pod.content).chomp.chomp
8797ffa0 » tadzik
2011-07-31 Implement DOC phasers. Fix compilation options. Add a simple Pod::To:…
39 }
40
41 sub named2text($pod) {
90e9c387 » tadzik
2011-08-09 Couple of more fixes to make the output generated from S26 more pleas…
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 }
585cd06c » tadzik
2011-07-31 The Pod tree should not contain bare strings. Use Pod::Block::Para, a…
51 }
52
53 sub para2text($pod) {
5f145c64 » tadzik
2011-08-14 Implement simple FormattinCode handling in Pod::To::Text
54 twine2text($pod.content)
8797ffa0 » tadzik
2011-07-31 Implement DOC phasers. Fix compilation options. Add a simple Pod::To:…
55 }
56
77c62ce5 » tadzik
2011-08-09 [Pod::To::Text] Generate proper output for Tables and Comments, fix o…
57 sub table2text($pod) {
f147bf84 » tadzik
2011-08-18 [Pod::To::Text] Align table columns
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 }
18d51bac » tadzik
2012-06-07 [Pod::To::Text] Avoid uninitialized variable warnings
64 my $ret;
65 if $pod.config<caption> {
66 $ret = $pod.config<caption> ~ "\n"
67 }
f147bf84 » tadzik
2011-08-18 [Pod::To::Text] Align table columns
68 for @rows -> $row {
69 for 0..($row.elems - 1) -> $i {
89353cb7 » tadzik
2011-12-22 [Pod::To::Text] Make tables a bit more pleasant to look at
70 $ret ~= $row[$i].fmt("%-{@maxes[$i]}s") ~ " ";
f147bf84 » tadzik
2011-08-18 [Pod::To::Text] Align table columns
71 }
72 $ret ~= "\n";
73 }
74 return $ret;
77c62ce5 » tadzik
2011-08-09 [Pod::To::Text] Generate proper output for Tables and Comments, fix o…
75 }
76
4472ab81 » tadzik
2011-08-06 Add declarator blocks support to Pod::To::Text
77 sub declarator2text($pod) {
78 next unless $pod.WHEREFORE.WHY;
b3e3008a » tadzik
2011-10-22 [Pod::To::Text] Make object stringification in declarator2text less i…
79 my $what = do given $pod.WHEREFORE {
4472ab81 » tadzik
2011-08-06 Add declarator blocks support to Pod::To::Text
80 when Method {
43445e51 » marcusramberg
2012-04-21 Fix method stringification in Pod::To::Text, fix slurpy star in Param…
81 my @params=$_.signature.params[1..*];
82 @params.pop if @params[*-1].name eq '%_';
83 'method ' ~ $_.name ~ signature2text(@params)
4472ab81 » tadzik
2011-08-06 Add declarator blocks support to Pod::To::Text
84 }
85 when Sub {
43445e51 » marcusramberg
2012-04-21 Fix method stringification in Pod::To::Text, fix slurpy star in Param…
86 'sub ' ~ $_.name ~ signature2text($_.signature.params)
4472ab81 » tadzik
2011-08-06 Add declarator blocks support to Pod::To::Text
87 }
88 when nqp::p6bool(nqp::istype($_.HOW, Metamodel::ClassHOW)) {
b3e3008a » tadzik
2011-10-22 [Pod::To::Text] Make object stringification in declarator2text less i…
89 'class ' ~ $_.perl
4472ab81 » tadzik
2011-08-06 Add declarator blocks support to Pod::To::Text
90 }
91 when nqp::p6bool(nqp::istype($_.HOW, Metamodel::ModuleHOW)) {
b3e3008a » tadzik
2011-10-22 [Pod::To::Text] Make object stringification in declarator2text less i…
92 'module ' ~ $_.perl
4472ab81 » tadzik
2011-08-06 Add declarator blocks support to Pod::To::Text
93 }
083287a0 » tadzik
2011-08-09 Small tunes in Pod::To::Text, sanitize newline handling, interpret pa…
94 when nqp::p6bool(nqp::istype($_.HOW, Metamodel::PackageHOW)) {
b3e3008a » tadzik
2011-10-22 [Pod::To::Text] Make object stringification in declarator2text less i…
95 'package ' ~ $_.perl
083287a0 » tadzik
2011-08-09 Small tunes in Pod::To::Text, sanitize newline handling, interpret pa…
96 }
ada28b6d » tadzik
2011-08-13 [Pod::To::Text] Tune and clarify declarator2text() a bit
97 default {
98 ''
99 }
100 }
9b161509 » marcusramberg
2012-04-21 Reformat --doc output
101 return "$what\n{$pod.WHEREFORE.WHY.content}"
102 }
103
43445e51 » marcusramberg
2012-04-21 Fix method stringification in Pod::To::Text, fix slurpy star in Param…
104 sub signature2text($params) {
105 $params.elems ??
106 "(\n\t" ~ $params.map({ $_.perl }).join(", \n\t") ~ "\n)"
9b161509 » marcusramberg
2012-04-21 Reformat --doc output
107 !! "()";
4472ab81 » tadzik
2011-08-06 Add declarator blocks support to Pod::To::Text
108 }
109
5f145c64 » tadzik
2011-08-14 Implement simple FormattinCode handling in Pod::To::Text
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
8797ffa0 » tadzik
2011-07-31 Implement DOC phasers. Fix compilation options. Add a simple Pod::To:…
124 # vim: ft=perl6
Something went wrong with that request. Please try again.