Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 120 lines (107 sloc) 3.346 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 { }
585cd06c » tadzik
2011-07-31 The Pod tree should not contain bare strings. Use Pod::Block::Para, a…
20 default { $pod.Str }
8797ffa0 » tadzik
2011-07-31 Implement DOC phasers. Fix compilation options. Add a simple Pod::To:…
21 }
22 }
23
24 sub heading2text($pod) {
25 given $pod.level {
585cd06c » tadzik
2011-07-31 The Pod tree should not contain bare strings. Use Pod::Block::Para, a…
26 when 1 { pod2text($pod.content) }
27 when 2 { ' ' ~ pod2text($pod.content) }
28 default { ' ' ~ pod2text($pod.content) }
8797ffa0 » tadzik
2011-07-31 Implement DOC phasers. Fix compilation options. Add a simple Pod::To:…
29 }
30 }
31
32 sub code2text($pod) {
585cd06c » tadzik
2011-07-31 The Pod tree should not contain bare strings. Use Pod::Block::Para, a…
33 " " ~ $pod.content.subst(/\n/, "\n ", :g)
8797ffa0 » tadzik
2011-07-31 Implement DOC phasers. Fix compilation options. Add a simple Pod::To:…
34 }
35
36 sub item2text($pod) {
585cd06c » tadzik
2011-07-31 The Pod tree should not contain bare strings. Use Pod::Block::Para, a…
37 ' * ' ~ pod2text($pod.content).chomp.chomp
8797ffa0 » tadzik
2011-07-31 Implement DOC phasers. Fix compilation options. Add a simple Pod::To:…
38 }
39
40 sub named2text($pod) {
90e9c387 » tadzik
2011-08-09 Couple of more fixes to make the output generated from S26 more pleas…
41 given $pod.name {
42 when 'pod' { pod2text($pod.content) }
43 when 'para' { para2text($pod.content[0]) }
44 when 'defn' { pod2text($pod.content[0]) ~ "\n"
45 ~ pod2text($pod.content[1..*-1]) }
46 when 'config' { }
47 when 'nested' { }
48 default { $pod.name ~ "\n" ~ pod2text($pod.content) }
49 }
585cd06c » tadzik
2011-07-31 The Pod tree should not contain bare strings. Use Pod::Block::Para, a…
50 }
51
52 sub para2text($pod) {
5f145c64 » tadzik
2011-08-14 Implement simple FormattinCode handling in Pod::To::Text
53 twine2text($pod.content)
8797ffa0 » tadzik
2011-07-31 Implement DOC phasers. Fix compilation options. Add a simple Pod::To:…
54 }
55
77c62ce5 » tadzik
2011-08-09 [Pod::To::Text] Generate proper output for Tables and Comments, fix o…
56 sub table2text($pod) {
f147bf84 » tadzik
2011-08-18 [Pod::To::Text] Align table columns
57 my @rows = $pod.content;
58 @rows.unshift($pod.headers.item) if $pod.headers;
59 my @maxes;
60 for 0..(@rows[1].elems - 1) -> $i {
61 @maxes.push([max] @rows.map({ $_[$i].chars }));
62 }
f5ef031e » tadzik
2011-12-22 [Pod::To::Text] Fix handling of table caption
63 my $ret = $pod.config<caption> ~ "\n" // '';
f147bf84 » tadzik
2011-08-18 [Pod::To::Text] Align table columns
64 for @rows -> $row {
65 for 0..($row.elems - 1) -> $i {
89353cb7 » tadzik
2011-12-22 [Pod::To::Text] Make tables a bit more pleasant to look at
66 $ret ~= $row[$i].fmt("%-{@maxes[$i]}s") ~ " ";
f147bf84 » tadzik
2011-08-18 [Pod::To::Text] Align table columns
67 }
68 $ret ~= "\n";
69 }
70 return $ret;
77c62ce5 » tadzik
2011-08-09 [Pod::To::Text] Generate proper output for Tables and Comments, fix o…
71 }
72
4472ab81 » tadzik
2011-08-06 Add declarator blocks support to Pod::To::Text
73 sub declarator2text($pod) {
74 next unless $pod.WHEREFORE.WHY;
b3e3008a » tadzik
2011-10-22 [Pod::To::Text] Make object stringification in declarator2text less i…
75 my $what = do given $pod.WHEREFORE {
4472ab81 » tadzik
2011-08-06 Add declarator blocks support to Pod::To::Text
76 when Method {
43445e51 » marcusramberg
2012-04-21 Fix method stringification in Pod::To::Text, fix slurpy star in Param…
77 my @params=$_.signature.params[1..*];
78 @params.pop if @params[*-1].name eq '%_';
79 'method ' ~ $_.name ~ signature2text(@params)
4472ab81 » tadzik
2011-08-06 Add declarator blocks support to Pod::To::Text
80 }
81 when Sub {
43445e51 » marcusramberg
2012-04-21 Fix method stringification in Pod::To::Text, fix slurpy star in Param…
82 'sub ' ~ $_.name ~ signature2text($_.signature.params)
4472ab81 » tadzik
2011-08-06 Add declarator blocks support to Pod::To::Text
83 }
84 when nqp::p6bool(nqp::istype($_.HOW, Metamodel::ClassHOW)) {
b3e3008a » tadzik
2011-10-22 [Pod::To::Text] Make object stringification in declarator2text less i…
85 'class ' ~ $_.perl
4472ab81 » tadzik
2011-08-06 Add declarator blocks support to Pod::To::Text
86 }
87 when nqp::p6bool(nqp::istype($_.HOW, Metamodel::ModuleHOW)) {
b3e3008a » tadzik
2011-10-22 [Pod::To::Text] Make object stringification in declarator2text less i…
88 'module ' ~ $_.perl
4472ab81 » tadzik
2011-08-06 Add declarator blocks support to Pod::To::Text
89 }
083287a0 » tadzik
2011-08-09 Small tunes in Pod::To::Text, sanitize newline handling, interpret pa…
90 when nqp::p6bool(nqp::istype($_.HOW, Metamodel::PackageHOW)) {
b3e3008a » tadzik
2011-10-22 [Pod::To::Text] Make object stringification in declarator2text less i…
91 'package ' ~ $_.perl
083287a0 » tadzik
2011-08-09 Small tunes in Pod::To::Text, sanitize newline handling, interpret pa…
92 }
ada28b6d » tadzik
2011-08-13 [Pod::To::Text] Tune and clarify declarator2text() a bit
93 default {
94 ''
95 }
96 }
9b161509 » marcusramberg
2012-04-21 Reformat --doc output
97 return "$what\n{$pod.WHEREFORE.WHY.content}"
98 }
99
43445e51 » marcusramberg
2012-04-21 Fix method stringification in Pod::To::Text, fix slurpy star in Param…
100 sub signature2text($params) {
101 $params.elems ??
102 "(\n\t" ~ $params.map({ $_.perl }).join(", \n\t") ~ "\n)"
9b161509 » marcusramberg
2012-04-21 Reformat --doc output
103 !! "()";
4472ab81 » tadzik
2011-08-06 Add declarator blocks support to Pod::To::Text
104 }
105
5f145c64 » tadzik
2011-08-14 Implement simple FormattinCode handling in Pod::To::Text
106 sub formatting2text($pod) {
107 twine2text($pod.content)
108 }
109
110 sub twine2text($twine) {
111 return '' unless $twine.elems;
112 my $r = $twine[0];
113 for $twine[1..*] -> $f, $s {
114 $r ~= twine2text($f.content);
115 $r ~= $s;
116 }
117 return $r;
118 }
119
8797ffa0 » tadzik
2011-07-31 Implement DOC phasers. Fix compilation options. Add a simple Pod::To:…
120 # vim: ft=perl6
Something went wrong with that request. Please try again.