Skip to content

Commit

Permalink
Item14237: Added macro parameters 'anchor' and 'section'
Browse files Browse the repository at this point in the history
  • Loading branch information
vrurg committed Oct 8, 2017
1 parent 9bfa800 commit afb2394
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
7 changes: 6 additions & 1 deletion core/data/System/VarPERLDOC.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
%META:TOPICINFO{author="ProjectContributor" date="1506731777" format="1.1" version="1"}%
%META:TOPICINFO{author="ProjectContributor" date="1507428457" format="1.1" version="1"}%
%META:TOPICPARENT{name="Macros"}%
---+ PERLDOC -- generate a link to code documentation
Generates a link to in-code documentation. Takes following parameters:
Expand All @@ -8,11 +8,16 @@ Generates a link to in-code documentation. Takes following parameters:
| =method= | Name of a method to point to | |
| =attr= or =attribute= | Name of an attribute to point to | |
| =text= | Text to be displayed instead of default | |
| =anchor= | Link to specific anchor in the documenation | |
| =section= | Link to specific section in the documentation | |

If either =method= or =attr= is used the generated link will contain anchor
pointing to corresponding sub-section in the documentation. Note that if both
parameters are used then =method= has priority over =attr=.

=anchor= and =section= override anchors defined by =attr= or =method= with
=anchor= being the highest priority one.

Default text generated for the link consist of module name followed by a double
colon and the method or attribute name if corresponding parameters are present;
for methods parenthesis are appended at the end. If this representation is not
Expand Down
10 changes: 8 additions & 2 deletions core/lib/Foswiki/Macros/PERLDOC.pm
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package Foswiki::Macros::PERLDOC;

use Try::Tiny;
use Data::Dumper;
use Foswiki::Render::Anchors;

use Foswiki::Class qw(app);
extends qw<Foswiki::Object>;
Expand Down Expand Up @@ -33,8 +34,13 @@ sub expand {
}
}

$linkText = $params->{text} if $params->{text};
$anchor = $params->{anchor} if $params->{anchor};
$linkText = $params->{text} if $params->{text};
if ( $params->{anchor} ) {
$anchor = $params->{anchor};
}
elsif ( $params->{section} ) {
$anchor = Foswiki::Render::Anchors::make( $params->{section} );
}
$anchor = "#$anchor" unless $anchor =~ /^#/;

my $cfgData = $this->app->cfg->data;
Expand Down

0 comments on commit afb2394

Please sign in to comment.