[Rt-commit] rt branch, 4.0/linkify-filenames-in-doc, created. rt-4.0.10-40-g75da47f
Thomas Sibley
trs at bestpractical.com
Mon Feb 11 22:14:21 EST 2013
The branch, 4.0/linkify-filenames-in-doc has been created
at 75da47f1a434ccd6d3d023c39156d0cccf93cc35 (commit)
- Log -----------------------------------------------------------------
commit 99e4df46ef7ea535f5f4bdd3d424eb61394479f2
Author: Thomas Sibley <trs at bestpractical.com>
Date: Mon Feb 11 19:00:04 2013 -0800
Fix incorrect parent directory parts which were missing slashes
This resulted in "...." instead of "../.." for documentation more than
one level deep. Rather than adjust the repetition operator to enclose
the left side in parens, guaranteeing list context, merely simplify the
expression by removing the join all together.
diff --git a/lib/RT/Pod/HTML.pm b/lib/RT/Pod/HTML.pm
index 366adb8..f5aadfd 100644
--- a/lib/RT/Pod/HTML.pm
+++ b/lib/RT/Pod/HTML.pm
@@ -103,9 +103,7 @@ sub resolve_pod_page_link {
if ($local) {
# Resolve links correctly by going up
my $depth = $self->batch_mode_current_level - 1;
- return join "/",
- ($depth ? ".." x $depth : ()),
- "$local.html$section";
+ return ($depth ? "../" x $depth : "") . "$local.html$section";
} else {
return $self->SUPER::resolve_pod_page_link(@_)
}
commit 75da47f1a434ccd6d3d023c39156d0cccf93cc35
Author: Thomas Sibley <trs at bestpractical.com>
Date: Mon Feb 11 19:08:43 2013 -0800
Linkify filenames in POD (F<...>) which point to documentation
Now POD expressions such as F<docs/full_text_indexing.pod> will generate
an HTML link to the correct doc with the filename as the link text. The
following are examples that now produce links:
F<docs/full_text_indexing.pod>
F<lib/RT/Date.pm>
F<RT/Date.pm>
F<rt-email-group-admin>
F<RT_Config.pm>
This behaviour is particularly useful when referring to documentation
that isn't a Perl package file (.pm).
diff --git a/lib/RT/Pod/HTML.pm b/lib/RT/Pod/HTML.pm
index f5aadfd..42df4f1 100644
--- a/lib/RT/Pod/HTML.pm
+++ b/lib/RT/Pod/HTML.pm
@@ -52,6 +52,8 @@ use warnings;
package RT::Pod::HTML;
use base 'Pod::Simple::XHTML';
+use HTML::Entities qw//;
+
sub new {
my $self = shift->SUPER::new(@_);
$self->index(1);
@@ -59,6 +61,11 @@ sub new {
return $self;
}
+sub decode_entities {
+ my $self = shift;
+ return HTML::Entities::decode_entities($_[0]);
+}
+
sub perldoc_url_prefix { "http://metacpan.org/module/" }
sub html_header { '' }
@@ -71,6 +78,23 @@ sub html_footer {
sub start_Verbatim { $_[0]{'scratch'} = "<pre>" }
sub end_Verbatim { $_[0]{'scratch'} .= "</pre>"; $_[0]->emit; }
+sub start_F {
+ $_[0]{'scratch_F'} = $_[0]{'scratch'};
+ $_[0]{'scratch'} = "";
+}
+sub end_F {
+ my $self = shift;
+ my $text = $self->{scratch};
+ my $file = $self->decode_entities($text);
+
+ if (my $local = $self->resolve_local_link($file)) {
+ $text = qq[<a href="$local">$text</a>];
+ }
+
+ $self->{'scratch'} = delete $self->{scratch_F};
+ $self->{'scratch'} .= "<i>$text</i>";
+}
+
sub _end_head {
my $self = shift;
$self->{scratch} = '<a href="#___top">' . $self->{scratch} . '</a>';
@@ -86,6 +110,17 @@ sub resolve_pod_page_link {
return $self->SUPER::resolve_pod_page_link(@_)
unless $self->batch_mode and $name;
+ my $local = $self->resolve_local_link($name, $section);
+
+ return $local
+ ? $local
+ : $self->SUPER::resolve_pod_page_link(@_);
+}
+
+sub resolve_local_link {
+ my $self = shift;
+ my ($name, $section) = @_;
+
$section = defined $section
? '#' . $self->idify($section, 1)
: '';
@@ -96,16 +131,28 @@ sub resolve_pod_page_link {
map { $self->encode_entities($_) }
split /::/, $name;
}
- elsif ($name =~ /^rt[-_]/i) {
+ elsif ($name =~ /^rt[-_]/) {
$local = $self->encode_entities($name);
}
+ elsif ($name eq "RT_Config" or $name eq "RT_Config.pm") {
+ $local = "RT_Config";
+ }
+ # These matches handle links that look like filenames, such as those we
+ # parse out of F<> tags.
+ elsif ( $name =~ m{^(?:lib/)(RT/[\w/]+?)\.pm$}
+ or $name =~ m{^(?:docs/)(.+?)\.pod$})
+ {
+ $local = join "/",
+ map { $self->encode_entities($_) }
+ split /\//, $1;
+ }
if ($local) {
# Resolve links correctly by going up
my $depth = $self->batch_mode_current_level - 1;
return ($depth ? "../" x $depth : "") . "$local.html$section";
} else {
- return $self->SUPER::resolve_pod_page_link(@_)
+ return;
}
}
-----------------------------------------------------------------------
More information about the Rt-commit
mailing list