[MKDoc-dev] patch to add option to automatically link to sibling
documents
Bruno Postle
bruno at mkdoc.com
Thu Aug 17 13:10:56 BST 2006
Currently MKDoc automatically links to child dcouments, this patch
adds the option to link to sibling documents too.
By default it is disabled, it can be enabled by adding this to the
httpd-env.conf file:
SetEnv MKD__LINK_SIBLINGS TRUE
It also adds two more methods available to template writers:
document/siblings
document/siblings_showable
Both return lists of siblings of the current document. They are
different from these methods which also include the current document
in the list:
document/parent/children
document/parent/children_showable
--
Bruno
-------------- next part --------------
Index: flo/Editor.pm
===================================================================
RCS file: /var/spool/cvs/mkd/flo/Editor.pm,v
retrieving revision 1.12.2.50
diff -r1.12.2.50 Editor.pm
223a224,236
> # plus we want to hyperlink all the siblings
> if (MKDoc::Config->LINK_SIBLINGS) {
> foreach my $sibling ($document->siblings_showable)
> {
> push @links, {
> class => "mkdoc-name-". $sibling->name,
> href => $sibling->uri,
> desc => $sibling->description,
> expr => $sibling->title,
> lang => $sibling->lang,
> }
> }
> }
Index: MKDoc/Config.pm
===================================================================
RCS file: /var/spool/cvs/mkd/MKDoc/Config.pm,v
retrieving revision 1.8.2.49
diff -r1.8.2.49 Config.pm
177a178,184
> sub LINK_SIBLINGS
> {
> my $class = shift;
> return get_env ('MKD__LINK_SIBLINGS') || undef;
> }
>
>
Index: MKDoc/Site/ConfigWriter/Httpd_Conf.pm
===================================================================
RCS file: /var/spool/cvs/mkd/MKDoc/Site/ConfigWriter/Httpd_Conf.pm,v
retrieving revision 1.1.2.46
diff -r1.1.2.46 Httpd_Conf.pm
228a229,231
> # uncomment this if you want to automatically link to sibling documents
> # SetEnv MKD__LINK_SIBLINGS TRUE
>
Index: flo/Record/Document.pm
===================================================================
RCS file: /var/spool/cvs/mkd/flo/Record/Document.pm,v
retrieving revision 1.25.2.73
diff -r1.25.2.73 Document.pm
1664a1665,1721
> ##
> # $self->siblings;
> # ----------------
> # Returns a list of all sibling documents of this document
> ##
> sub siblings
> {
> my $self = shift;
> my $args = { @_ };
>
> $self->{'.siblings'} ||= do {
> my $parent = $self->parent();
> if ($parent)
> {
> my @siblings;
> for my $sibling ($parent->children())
> {
> push @siblings, $sibling unless $self->equals ($sibling);
> }
> \@siblings;
> }
> else
> {
> [];
> }
> };
>
> my @res = @{$self->{'.siblings'}};
>
> my $with = $args->{'with'};
> $with and do { @res = map { @{$_->components ($with) } ? $_ : () } @res };
>
> my $without = $args->{'without'};
> $without and do { @res = map { @{$_->components ($without) } ? () : $_ } @res };
>
> return wantarray ? @res : \@res;
> }
>
> ##
> # $self->siblings_showable();
> # ---------------------------
> # Same as siblings(), except returns only showable documents.
> ##
> sub siblings_showable
> {
> my $self = shift;
> my @res;
> if (flo::Standard::current_user && flo::Standard::current_user->is_editor)
> {
> @res = map { $_->is_showable_to_editor() ? $_ : () } $self->siblings;
> }
> else
> {
> @res = map { $_->is_showable() ? $_ : () } $self->siblings;
> }
> return wantarray ? @res : \@res;
> }
More information about the MKDoc-dev
mailing list