| 1 | # PurpleWiki::View::text.pm | ||
| 2 | # | ||
| 3 | # $Id: text.pm 426 2004-07-25 23:44:24Z cdent $ | ||
| 4 | # | ||
| 5 | # Copyright (c) Blue Oxen Associates 2002-2004. All rights reserved. | ||
| 6 | # | ||
| 7 | # This file is part of PurpleWiki. PurpleWiki is derived from: | ||
| 8 | # | ||
| 9 | # UseModWiki v0.92 (c) Clifford A. Adams 2000-2001 | ||
| 10 | # AtisWiki v0.3 (c) Markus Denker 1998 | ||
| 11 | # CVWiki CVS-patches (c) Peter Merel 1997 | ||
| 12 | # The Original WikiWikiWeb (c) Ward Cunningham | ||
| 13 | # | ||
| 14 | # PurpleWiki is free software; you can redistribute it and/or modify | ||
| 15 | # it under the terms of the GNU General Public License as published by | ||
| 16 | # the Free Software Foundation; either version 2 of the License, or | ||
| 17 | # (at your option) any later version. | ||
| 18 | # | ||
| 19 | # This program is distributed in the hope that it will be useful, | ||
| 20 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 21 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 22 | # GNU General Public License for more details. | ||
| 23 | # | ||
| 24 | # You should have received a copy of the GNU General Public License | ||
| 25 | # along with this program; if not, write to the | ||
| 26 | # Free Software Foundation, Inc. | ||
| 27 | # 59 Temple Place, Suite 330 | ||
| 28 | # Boston, MA 02111-1307 USA | ||
| 29 | |||
| 30 | package PurpleWiki::View::text; | ||
| 31 | use 5.005; | ||
| 32 | use strict; | ||
| 33 | use warnings; | ||
| 34 | use Text::Wrap; | ||
| 35 | use PurpleWiki::View::rawtext; | ||
| 36 | |||
| 37 | ############### Package Globals ############### | ||
| 38 | |||
| 39 | our $VERSION; | ||
| 40 | $VERSION = sprintf("%d", q$Id: text.pm 426 2004-07-25 23:44:24Z cdent $ =~ /\s(\d+)\s/); | ||
| 41 | |||
| 42 | our @ISA = qw(PurpleWiki::View::rawtext); | ||
| 43 | |||
| 44 | |||
| 45 | ############### Overloaded Methods ############### | ||
| 46 | |||
| 47 | sub new { | ||
| 48 | my $proto = shift; | ||
| 49 | my $class = ref($proto) || $proto; | ||
| 50 | my $self = $class->SUPER::new(@_); | ||
| 51 | |||
| 52 | # Object State | ||
| 53 | $self->{linksIndex} = 1; | ||
| 54 | $self->{showLinks} = 1; | ||
| 55 | |||
| 56 | bless($self, $class); | ||
| 57 | return $self; | ||
| 58 | } | ||
| 59 | |||
| 60 | sub view { | ||
| 61 | my ($self, $wikiTree) = @_; | ||
| 62 | |||
| 63 | if (!defined($self->{columns}) || $self->{columns} !~ /^\d+$/ | ||
| 64 | || $self->{columns} < 10) { | ||
| 65 | $self->{columns} = 72; | ||
| 66 | } | ||
| 67 | if (defined $self->{show_links} && $self->{show_links} == 0) { | ||
| 68 | $self->{showLinks} = 0; | ||
| 69 | } | ||
| 70 | |||
| 71 | $Text::Wrap::columns = $self->{columns}; | ||
| 72 | $Text::Wrap::huge = 'overflow'; | ||
| 73 | |||
| 74 | $self->SUPER::view($wikiTree); | ||
| 75 | |||
| 76 | $self->{outputString} = $self->_header($wikiTree) . | ||
| 77 | $self->{outputString} . $self->_footer; | ||
| 78 | |||
| 79 | return $self->{outputString}; | ||
| 80 | } | ||
| 81 | |||
| 82 | sub linkPost { | ||
| 83 | my ($self, $nodeRef) = @_; | ||
| 84 | if ($self->{showLinks}) { | ||
| 85 | push @{$self->{links}}, $nodeRef->href; | ||
| 86 | $self->{linksIndex}++; | ||
| 87 | $self->{outputString} .= '[' . ($self->{linksIndex} - 1) . ']'; | ||
| 88 | } | ||
| 89 | } | ||
| 90 | |||
| 91 | |||
| 92 | ############### Private Methods ############### | ||
| 93 | |||
| 94 | sub _structuralContent { | ||
| 95 | my ($self, $nodeRef) = @_; | ||
| 96 | |||
| 97 | if ($nodeRef->content) { | ||
| 98 | my $tmp = $self->{outputString}; | ||
| 99 | $self->{outputString} = ""; | ||
| 100 | $self->traverse($nodeRef->content); | ||
| 101 | my $nodeString = $self->{outputString}; | ||
| 102 | $self->{outputString} = $tmp; | ||
| 103 | if ($nodeRef->type eq 'li') { | ||
| 104 | if ($self->{listType} eq 'ul') { | ||
| 105 | $nodeString = "* $nodeString"; | ||
| 106 | } | ||
| 107 | elsif ($self->{listType} eq 'ol') { | ||
| 108 | $nodeString = $self->{listNumber}.". $nodeString"; | ||
| 109 | $self->{listNumber}++; | ||
| 110 | } | ||
| 111 | } | ||
| 112 | if ($nodeRef->type eq 'pre') { | ||
| 113 | $self->{outputString} .= Text::Wrap::wrap($self->{initialIndent}, | ||
| 114 | $self->{subsequentIndent}, | ||
| 115 | $nodeString); | ||
| 116 | } else { | ||
| 117 | $self->{outputString} .= Text::Wrap::fill($self->{initialIndent}, | ||
| 118 | $self->{subsequentIndent}, | ||
| 119 | $nodeString); | ||
| 120 | } | ||
| 121 | } | ||
| 122 | } | ||
| 123 | |||
| 124 | sub _header { | ||
| 125 | my ($self, $wikiTree) = @_; | ||
| 126 | my $header = ""; | ||
| 127 | |||
| 128 | $header .= $self->_center($wikiTree->title, $self->{columns}); | ||
| 129 | $header .= $self->_center($wikiTree->subtitle, $self->{columns}); | ||
| 130 | $header .= $self->_center($wikiTree->id, $self->{columns}); | ||
| 131 | $header .= $self->_center($wikiTree->date, $self->{columns}); | ||
| 132 | $header .= $self->_center($wikiTree->version, $self->{columns}); | ||
| 133 | |||
| 134 | return $header."\n"; | ||
| 135 | } | ||
| 136 | |||
| 137 | sub _footer { | ||
| 138 | my $self = shift; | ||
| 139 | my $footer = ""; | ||
| 140 | |||
| 141 | if ($self->{showLinks}) { # check for links | ||
| 142 | if (scalar @{$self->{links}} > 0) { | ||
| 143 | $footer = "\n\n"; | ||
| 144 | $footer .= "LINK REFERENCES\n\n"; | ||
| 145 | $self->{linksIndex} = 1; | ||
| 146 | foreach my $link (@{$self->{links}}) { | ||
| 147 | $footer .= " [".$self->{linksIndex}."] $link\n"; | ||
| 148 | $self->{linksIndex}++; | ||
| 149 | } | ||
| 150 | } | ||
| 151 | } | ||
| 152 | |||
| 153 | return $footer; | ||
| 154 | } | ||
| 155 | |||
| 156 | sub _center { | ||
| 157 | my ($self, $string, $columns) = @_; | ||
| 158 | my $padding; | ||
| 159 | |||
| 160 | return "" if not $string; | ||
| 161 | |||
| 162 | if (length $string > $columns) { | ||
| 163 | return $string . "\n"; | ||
| 164 | } | ||
| 165 | |||
| 166 | $padding = ($columns - length $string) / 2; | ||
| 167 | return ' 'x$padding . $string. "\n"; | ||
| 168 | } | ||
| 169 | 1; | ||
| 170 | __END__ |