Skip to content
Newer
Older
100644 83 lines (73 sloc) 2.29 KB
8797ffa @tadzik Implement DOC phasers. Fix compilation options. Add a simple Pod::To:…
tadzik authored Jul 31, 2011
1 module Pod::To::Text;
2
3 sub pod2text($pod) is export {
4472ab8 @tadzik Add declarator blocks support to Pod::To::Text
tadzik authored Aug 6, 2011
4 my @declarators;
8797ffa @tadzik Implement DOC phasers. Fix compilation options. Add a simple Pod::To:…
tadzik authored Jul 31, 2011
5 given $pod {
6 when Pod::Heading { heading2text($pod) }
083287a @tadzik Small tunes in Pod::To::Text, sanitize newline handling, interpret pa…
tadzik authored Aug 9, 2011
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 Aug 9, 2011
10 when Pod::Block::Table { table2text($pod) }
4472ab8 @tadzik Add declarator blocks support to Pod::To::Text
tadzik authored Aug 5, 2011
11 when Pod::Block::Declarator { declarator2text($pod) }
083287a @tadzik Small tunes in Pod::To::Text, sanitize newline handling, interpret pa…
tadzik authored Aug 9, 2011
12 when Pod::Item { item2text($pod) }
13 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
14 when Pod::Block::Comment { }
585cd06 @tadzik The Pod tree should not contain bare strings. Use Pod::Block::Para, a…
tadzik authored Jul 31, 2011
15 default { $pod.Str }
8797ffa @tadzik Implement DOC phasers. Fix compilation options. Add a simple Pod::To:…
tadzik authored Jul 31, 2011
16 }
17 }
18
19 sub heading2text($pod) {
20 given $pod.level {
585cd06 @tadzik The Pod tree should not contain bare strings. Use Pod::Block::Para, a…
tadzik authored Jul 31, 2011
21 when 1 { pod2text($pod.content) }
22 when 2 { ' ' ~ pod2text($pod.content) }
23 default { ' ' ~ pod2text($pod.content) }
8797ffa @tadzik Implement DOC phasers. Fix compilation options. Add a simple Pod::To:…
tadzik authored Jul 31, 2011
24 }
25 }
26
27 sub code2text($pod) {
585cd06 @tadzik The Pod tree should not contain bare strings. Use Pod::Block::Para, a…
tadzik authored Jul 31, 2011
28 " " ~ $pod.content.subst(/\n/, "\n ", :g)
8797ffa @tadzik Implement DOC phasers. Fix compilation options. Add a simple Pod::To:…
tadzik authored Jul 31, 2011
29 }
30
31 sub item2text($pod) {
585cd06 @tadzik The Pod tree should not contain bare strings. Use Pod::Block::Para, a…
tadzik authored Jul 31, 2011
32 ' * ' ~ pod2text($pod.content).chomp.chomp
8797ffa @tadzik Implement DOC phasers. Fix compilation options. Add a simple Pod::To:…
tadzik authored Jul 31, 2011
33 }
34
35 sub named2text($pod) {
90e9c38 @tadzik Couple of more fixes to make the output generated from S26 more pleas…
tadzik authored Aug 9, 2011
36 given $pod.name {
37 when 'pod' { pod2text($pod.content) }
38 when 'para' { para2text($pod.content[0]) }
39 when 'defn' { pod2text($pod.content[0]) ~ "\n"
40 ~ pod2text($pod.content[1..*-1]) }
41 when 'config' { }
42 when 'nested' { }
43 default { $pod.name ~ "\n" ~ pod2text($pod.content) }
44 }
585cd06 @tadzik The Pod tree should not contain bare strings. Use Pod::Block::Para, a…
tadzik authored Jul 31, 2011
45 }
46
47 sub para2text($pod) {
48 $pod.content.join("\n")
8797ffa @tadzik Implement DOC phasers. Fix compilation options. Add a simple Pod::To:…
tadzik authored Jul 31, 2011
49 }
50
77c62ce @tadzik [Pod::To::Text] Generate proper output for Tables and Comments, fix o…
tadzik authored Aug 9, 2011
51 sub table2text($pod) {
52 ($pod.caption // '')
53 ~ ($pod.headers ?? $pod.headers.join("\t") ~ "\n" !! '')
54 ~ ($pod.content.map({ $_.join("\t") }).join("\n"))
55 }
56
4472ab8 @tadzik Add declarator blocks support to Pod::To::Text
tadzik authored Aug 5, 2011
57 sub declarator2text($pod) {
58 next unless $pod.WHEREFORE.WHY;
ada28b6 @tadzik [Pod::To::Text] Tune and clarify declarator2text() a bit
tadzik authored Aug 13, 2011
59 my $type = do given $pod.WHEREFORE {
4472ab8 @tadzik Add declarator blocks support to Pod::To::Text
tadzik authored Aug 5, 2011
60 when Method {
61 'method'
62 }
63 when Sub {
64 'sub'
65 }
66 when nqp::p6bool(nqp::istype($_.HOW, Metamodel::ClassHOW)) {
67 'class'
68 }
69 when nqp::p6bool(nqp::istype($_.HOW, Metamodel::ModuleHOW)) {
70 'module'
71 }
083287a @tadzik Small tunes in Pod::To::Text, sanitize newline handling, interpret pa…
tadzik authored Aug 9, 2011
72 when nqp::p6bool(nqp::istype($_.HOW, Metamodel::PackageHOW)) {
73 'package'
74 }
ada28b6 @tadzik [Pod::To::Text] Tune and clarify declarator2text() a bit
tadzik authored Aug 13, 2011
75 default {
76 ''
77 }
78 }
79 return "$type {$pod.WHEREFORE.perl}: {$pod.WHEREFORE.WHY}"
4472ab8 @tadzik Add declarator blocks support to Pod::To::Text
tadzik authored Aug 5, 2011
80 }
81
8797ffa @tadzik Implement DOC phasers. Fix compilation options. Add a simple Pod::To:…
tadzik authored Jul 31, 2011
82 # vim: ft=perl6
Something went wrong with that request. Please try again.