Author: mcbrown
Date: 2007-10-29 12:49:56 +0100 (Mon, 29 Oct 2007)
New Revision: 8381
Log:
Moving the URL remapping content to the module so that we can use it from other tools
Modified:
trunk/tools/MySQL/IDMap.pm
trunk/tools/idremap.pl
Modified: trunk/tools/MySQL/IDMap.pm
===================================================================
--- trunk/tools/MySQL/IDMap.pm 2007-10-29 09:21:19 UTC (rev 8380)
+++ trunk/tools/MySQL/IDMap.pm 2007-10-29 11:49:56 UTC (rev 8381)
Changed blocks: 4, Lines Added: 100, Lines Deleted: 1; 4401 bytes
@@ -42,7 +42,10 @@
}
$object->{_opts} = $opts;
+ $object->{_appliedopts} = {};
+ $object->{_urlcore} = 'http://dev.mysql.com/doc/';
+
bless $object, $class;
return $object if (exists($opts->{skiploading}) &&
($opts->{skiploading} == 1));
@@ -184,7 +187,8 @@
{
my ($self) = @_;
- # Now calculate the depth of each item
+ return if (exists($self->{_appliedopts}->{builddepth}) &&
+ $self->{_appliedopts}->{builddepth} == 1);
foreach my $id (keys %{$self->{byid}})
{
@@ -192,6 +196,8 @@
next unless ($self->{byid}->{$id}->{idmapversion} >= 2);
$self->walktree($id);
}
+ $self->{_appliedopts}->{builddepth} = 1;
+
}
sub walktree
@@ -754,4 +760,97 @@
}
+sub remap_id_to_url
+{
+ my ($self,$idref,$prefix,$base_prefix,$warnings) = @_;
+
+ $self->builddepth();
+
+ my ($url,$title) = (undef,undef);
+
+ if (($self->{byid}->{$idref}->{type} =~ m/^book$/i) &&
+ ($self->{byid}->{$idref}->{parent} eq $idref))
+ {
+ if (defined($prefix))
+ {
+ $url =
sprintf('%s%s/index.html',$self->{_urlcore},$self->{byprefixid}->{$prefix}->{$idref}->{urlbase});
+ }
+ else
+ {
+ if
(exists($self->{byprefixid}->{$base_prefix}->{$idref}->{urlbase}))
+ {
+ $url =
sprintf('%s%s/index.html',$self->{_urlcore},$self->{byprefixid}->{$base_prefix}->{$idref}->{urlbase});
+ }
+ else
+ {
+ $url =
sprintf('%s%s/index.html',$self->{_urlcore},$self->{byid}->{$idref}->{urlbase});
+ }
+ }
+ $title = $self->{byid}->{$idref}->{title} || $idref;
+ print STDERR "$0: INFO: Replacing (toplevel) $idref with $url [$title]\n"
+ if ($warnings);
+ }
+ elsif (($self->{byid}->{$idref}->{type} =~
+
m/^(appendix|article|part|chapter|example|glossary|glossentry|preface|refentry|refsection|section)$/i)
&&
+ (exists($self->{byid}->{$idref}->{depth}) &&
+ ($self->{byid}->{$idref}->{depth} <= 3)))
+ {
+ if (defined($prefix))
+ {
+ $url =
sprintf('%s%s/%s.html',$self->{_urlcore},$self->{byprefixid}->{$prefix}->{$idref}->{urlbase},$idref);
+ }
+ else
+ {
+ if
(exists($self->{byprefixid}->{$base_prefix}->{$idref}->{urlbase}))
+ {
+ $url =
sprintf('%s%s/%s.html',$self->{_urlcore},$self->{byprefixid}->{$base_prefix}->{$idref}->{urlbase},$idref);
+ }
+ else
+ {
+ $url =
sprintf('%s%s/%s.html',$self->{_urlcore},$self->{byid}->{$idref}->{urlbase},$idref);
+ }
+ }
+ $title = $self->{byid}->{$idref}->{title} || $idref;
+
+ print STDERR "$0: INFO: Replacing (section) $idref with $url [$title]\n"
+ if ($warnings);
+ }
+ else
+ {
+ if (defined($prefix))
+ {
+ $url = sprintf('%s%s/%s.html#%s',
+ $self->{_urlcore},
+
$self->{byprefixid}->{$prefix}->{$idref}->{urlbase},
+
$self->{byprefixid}->{$prefix}->{$idref}->{parent},
+ $idref);
+ }
+ else
+ {
+ if
(exists($self->{byprefixid}->{$base_prefix}->{$idref}->{urlbase}))
+ {
+ $url = sprintf('%s%s/%s.html#%s',
+ $self->{_urlcore},
+
$self->{byprefixid}->{$base_prefix}->{$idref}->{urlbase},
+ $self->{byid}->{$idref}->{parent},
+ $idref);
+ }
+ else
+ {
+ $url = sprintf('%s%s/%s.html#%s',
+ $self->{_urlcore},
+ $self->{byid}->{$idref}->{urlbase},
+ $self->{byid}->{$idref}->{parent},
+ $idref);
+ }
+ }
+ $title =
$self->{byid}->{$self->{byid}->{$idref}->{parent}}->{title} || $idref;
+ print STDERR "$0: INFO: Replacing (para within page) $idref with $url [$title]\n"
+ if ($warnings);
+ }
+
+ return($url,$title);
+
+}
+
1;
Modified: trunk/tools/idremap.pl
===================================================================
--- trunk/tools/idremap.pl 2007-10-29 09:21:19 UTC (rev 8380)
+++ trunk/tools/idremap.pl 2007-10-29 11:49:56 UTC (rev 8381)
Changed blocks: 2, Lines Added: 1, Lines Deleted: 80; 4520 bytes
@@ -49,7 +49,6 @@
}
my $url = '';
-my $urlcore = 'http://dev.mysql.com/doc/';
my $source = IO::File->new($file,'r');
binmode($source,':utf8');
@@ -123,86 +122,8 @@
print STDERR "$0: WARNING: Link text would be blank (???) because title
text for $idref is not defined\n";
}
- if (($idmap->{byid}->{$idref}->{type} =~ m/^book$/i) &&
- ($idmap->{byid}->{$idref}->{parent} eq $idref))
- {
- if (defined($prefix))
- {
- $url =
sprintf('%s%s/index.html',$urlcore,$idmap->{byprefixid}->{$prefix}->{$idref}->{urlbase});
- }
- else
- {
- if
(exists($idmap->{byprefixid}->{$base_prefix}->{$idref}->{urlbase}))
- {
- $url =
sprintf('%s%s/index.html',$urlcore,$idmap->{byprefixid}->{$base_prefix}->{$idref}->{urlbase});
- }
- else
- {
- $url =
sprintf('%s%s/index.html',$urlcore,$idmap->{byid}->{$idref}->{urlbase});
- }
- }
- $title = $idmap->{byid}->{$idref}->{title} || $idref;
- print STDERR "$0: INFO: Replacing (toplevel) $idref with $url [$title]\n"
- if ($warnings);
- }
- elsif (($idmap->{byid}->{$idref}->{type} =~
-
m/^(appendix|article|part|chapter|example|glossary|glossentry|preface|refentry|refsection|section)$/i)
&&
- (exists($idmap->{byid}->{$idref}->{depth}) &&
- ($idmap->{byid}->{$idref}->{depth} <= 3)))
- {
- if (defined($prefix))
- {
- $url =
sprintf('%s%s/%s.html',$urlcore,$idmap->{byprefixid}->{$prefix}->{$idref}->{urlbase},$idref);
- }
- else
- {
- if
(exists($idmap->{byprefixid}->{$base_prefix}->{$idref}->{urlbase}))
- {
- $url =
sprintf('%s%s/%s.html',$urlcore,$idmap->{byprefixid}->{$base_prefix}->{$idref}->{urlbase},$idref);
- }
- else
- {
- $url =
sprintf('%s%s/%s.html',$urlcore,$idmap->{byid}->{$idref}->{urlbase},$idref);
- }
- }
- $title = $idmap->{byid}->{$idref}->{title} || $idref;
+ ($url,$title) =
$idmap->remap_id_to_url($idref,$prefix,$base_prefix,$warnings);
- print STDERR "$0: INFO: Replacing (section) $idref with $url [$title]\n"
- if ($warnings);
- }
- else
- {
- if (defined($prefix))
- {
- $url = sprintf('%s%s/%s.html#%s',
- $urlcore,
-
$idmap->{byprefixid}->{$prefix}->{$idref}->{urlbase},
-
$idmap->{byprefixid}->{$prefix}->{$idref}->{parent},
- $idref);
- }
- else
- {
- if
(exists($idmap->{byprefixid}->{$base_prefix}->{$idref}->{urlbase}))
- {
- $url = sprintf('%s%s/%s.html#%s',
- $urlcore,
-
$idmap->{byprefixid}->{$base_prefix}->{$idref}->{urlbase},
- $idmap->{byid}->{$idref}->{parent},
- $idref);
- }
- else
- {
- $url = sprintf('%s%s/%s.html#%s',
- $urlcore,
- $idmap->{byid}->{$idref}->{urlbase},
- $idmap->{byid}->{$idref}->{parent},
- $idref);
- }
- }
- $title =
$idmap->{byid}->{$idmap->{byid}->{$idref}->{parent}}->{title} ||
$idref;
- print STDERR "$0: INFO: Replacing (para within page) $idref with $url
[$title]\n"
- if ($warnings);
- }
my $destrepl = '';
if ($type eq 'xref')
{
| Thread |
|---|
| • svn commit - mysqldoc@docsrva: r8381 - in trunk/tools: . MySQL | mcbrown | 29 Oct |