Pdoc::Html::Converters::Modules
Url
Pdoc::Html::Converters::Modules::Url - converter module of type 'url'.
|
| Globals (from use vars definitions) |
| $_urlStart |
| $VERSION = do { my @r = (q$$Revision: 1.1.1.1 $ =~ /\d+/g); sprintf "%d."."%02d" x $ |
| $_urlEnd |
use Pdoc::Html::Converters::Modules::Url; # Creates new documentation object my $converter = Pdoc::Html::Converters::Modules::Url->new(); # Get an Pdoc::DocEntry object of type 'url' my $docEntry = Get_url_obj(); # Render the object $docEntry = $converter->convert($docEntry); if ($docEntry) { print $docEntry->name(), "\n", $docEntry->converted(); }
|
Pdoc::Html::Converters::Modules::Url is an HTML converter for objects (Pdoc::DocEntryI) of type 'url'. The converter will convert the 'url' entry as an HTML hyper link (<A HREF></A>) with the object content as url value and the object name as url name. Some parameters can be defined for the convertion as follow:
'target' Define a link target (TARGET) for the link, default to undef.
|
Methods description
Pdoc::Html::Converters::Modules::Url::_init is a private method used to define internal parameters.
my $conf = Pdoc::Config->new();
$conf->setVal('HTML', 'URL', 'start', '<b>');
$conf->setVal('HTML', 'URL', 'end', '</b>');
$converter->config($conf);
Pdoc::Html::Converters::Modules::Text::config gets a Pdoc::Config object as argument. This method will extract from the Config object the parameters related to this module convertion.
The parameters used by this module are:
'HTML' for the HTML convertion.
URL
Main config parameter identifier for url format.
start
Defines the HTML tag(s) to assign before the url content.
Default to ''.
end
Defines the HTML tag(s) to assign after the url content.
Default to ''.
# Render the object
$docEntry = $converter->convert($docEntry);
if ($docEntry) {
print $docEntry->name(), "\n", $docEntry->converted();
}
Pdoc::Html::Converters::Modules::Url::convert takes an object (Pdoc::DocEntryI) of type 'url' and set the converted content as an <A HREF></A> HTML link. If the object has its name defined, it will be used as the url visible text. The method returns the object on success or 0 on failure.
my $docEntry = Pdoc::Html::Converters::Modules::Url->new();
Pdoc::Html::Converters::Modules::Url::new method creates a new 'url' converter object.
Pdoc::Html::Converters::Modules::Url::type returns the type of object converted.
Methods code
BEGIN
{ $_urlStart = '';
$_urlEnd = '';}
sub _init
{ my $self = shift;
return 1;}
sub config
{ my $self = shift;
my $config = shift;
if (defined $config) {
my $val = $config->getVal('HTML', 'Url', 'start');
$_urlStart = $val if defined $val;
$val = $config->getVal('HTML', 'Url', 'end');
$_urlEnd = $val if defined $val;
}}
sub convert
{ my $self = shift;
my $obj = shift;
my $doc = shift;
return 0 if ($obj->type() ne $self->type());
return 0 if (! defined $obj->content());
my $str = $_urlStart . '<a href="' . $obj->content() . '"';
$str .= ' target="' . $self->get('target') . '"' if (defined $self->get('target'));
$str .= '>';
## Set url name
if (defined $obj->name()) {
$str .= $obj->name();
} else {
$str .= $obj->content(); }
$str .= '</a>' . $_urlEnd;
## Assign converted part to object
$obj->converted($str);
return $obj;}
sub new
{ my $class = shift;
my $self = {};
bless $self, $class;
$self->_init();
return $self;}
sub type
{ my $self = shift;
return 'url';}
General documentation
| AUTHOR |
top |
Copyright (c) 2000 by Raphael Leplae (lp1@sanger.ac.uk). All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
|