2015-09-03 00:55:04 +02:00
|
|
|
####################################################################################################################################
|
|
|
|
# DOC RENDER MODULE
|
|
|
|
####################################################################################################################################
|
2015-10-28 11:10:36 +02:00
|
|
|
package BackRestDoc::Common::DocRender;
|
2015-09-03 00:55:04 +02:00
|
|
|
|
|
|
|
use strict;
|
|
|
|
use warnings FATAL => qw(all);
|
|
|
|
use Carp qw(confess);
|
|
|
|
|
|
|
|
use Exporter qw(import);
|
|
|
|
our @EXPORT = qw();
|
|
|
|
|
2016-04-14 15:30:54 +02:00
|
|
|
use pgBackRest::Common::Log;
|
|
|
|
use pgBackRest::Common::String;
|
2015-09-03 00:55:04 +02:00
|
|
|
|
2015-11-22 23:44:01 +02:00
|
|
|
use BackRestDoc::Common::DocManifest;
|
2016-05-26 16:34:10 +02:00
|
|
|
|
|
|
|
####################################################################################################################################
|
|
|
|
# XML tag/param constants
|
|
|
|
####################################################################################################################################
|
|
|
|
use constant XML_SECTION_PARAM_ANCHOR => 'anchor';
|
|
|
|
push @EXPORT, qw(XML_SECTION_PARAM_ANCHOR);
|
|
|
|
use constant XML_SECTION_PARAM_ANCHOR_VALUE_NOINHERIT => 'no-inherit';
|
|
|
|
push @EXPORT, qw(XML_SECTION_PARAM_ANCHOR_VALUE_NOINHERIT);
|
2015-11-22 23:44:01 +02:00
|
|
|
|
2015-09-03 00:55:04 +02:00
|
|
|
####################################################################################################################################
|
|
|
|
# Render tags for various output types
|
|
|
|
####################################################################################################################################
|
|
|
|
my $oRenderTag =
|
|
|
|
{
|
|
|
|
'markdown' =>
|
|
|
|
{
|
2015-11-22 23:44:01 +02:00
|
|
|
'quote' => ['"', '"'],
|
2015-09-03 00:55:04 +02:00
|
|
|
'b' => ['**', '**'],
|
|
|
|
'i' => ['_', '_'],
|
2015-11-22 23:44:01 +02:00
|
|
|
# 'bi' => ['_**', '**_'],
|
2016-04-16 17:55:23 +02:00
|
|
|
'ul' => ["\n", ""],
|
2015-10-28 11:10:36 +02:00
|
|
|
'ol' => ["\n", "\n"],
|
2015-09-03 00:55:04 +02:00
|
|
|
'li' => ['- ', "\n"],
|
|
|
|
'id' => ['`', '`'],
|
|
|
|
'file' => ['`', '`'],
|
|
|
|
'path' => ['`', '`'],
|
|
|
|
'cmd' => ['`', '`'],
|
|
|
|
'param' => ['`', '`'],
|
|
|
|
'setting' => ['`', '`'],
|
2016-11-17 23:35:11 +02:00
|
|
|
'pg-setting' => ['`', '`'],
|
2015-09-03 00:55:04 +02:00
|
|
|
'code' => ['`', '`'],
|
2015-11-22 23:44:01 +02:00
|
|
|
# 'code-block' => ['```', '```'],
|
|
|
|
# 'exe' => [undef, ''],
|
2015-09-03 00:55:04 +02:00
|
|
|
'backrest' => [undef, ''],
|
|
|
|
'postgres' => ['PostgreSQL', '']
|
|
|
|
},
|
|
|
|
|
2015-09-08 13:31:24 +02:00
|
|
|
'text' =>
|
|
|
|
{
|
2015-11-22 23:44:01 +02:00
|
|
|
'quote' => ['"', '"'],
|
2015-09-08 13:31:24 +02:00
|
|
|
'b' => ['', ''],
|
|
|
|
'i' => ['', ''],
|
2015-11-22 23:44:01 +02:00
|
|
|
# 'bi' => ['', ''],
|
2015-10-28 11:10:36 +02:00
|
|
|
'ul' => ["\n", "\n"],
|
|
|
|
'ol' => ["\n", "\n"],
|
2015-09-08 13:31:24 +02:00
|
|
|
'li' => ['* ', "\n"],
|
|
|
|
'id' => ['', ''],
|
2016-08-25 16:04:46 +02:00
|
|
|
'host' => ['', ''],
|
2015-09-08 13:31:24 +02:00
|
|
|
'file' => ['', ''],
|
|
|
|
'path' => ['', ''],
|
|
|
|
'cmd' => ['', ''],
|
2015-10-28 11:10:36 +02:00
|
|
|
'br-option' => ['', ''],
|
2016-06-12 15:13:46 +02:00
|
|
|
'pg-setting' => ['', ''],
|
2015-09-08 13:31:24 +02:00
|
|
|
'param' => ['', ''],
|
|
|
|
'setting' => ['', ''],
|
|
|
|
'code' => ['', ''],
|
|
|
|
'code-block' => ['', ''],
|
|
|
|
'exe' => [undef, ''],
|
|
|
|
'backrest' => [undef, ''],
|
|
|
|
'postgres' => ['PostgreSQL', '']
|
|
|
|
},
|
|
|
|
|
2015-11-22 23:44:01 +02:00
|
|
|
'latex' =>
|
|
|
|
{
|
|
|
|
'quote' => ['``', '"'],
|
|
|
|
'b' => ['\textbf{', '}'],
|
|
|
|
'i' => ['\textit{', '}'],
|
|
|
|
# 'bi' => ['', ''],
|
|
|
|
# 'ul' => ["\n", "\n"],
|
|
|
|
# 'ol' => ["\n", "\n"],
|
|
|
|
# 'li' => ['* ', "\n"],
|
|
|
|
'id' => ['\textnormal{\texttt{', '}}'],
|
|
|
|
'host' => ['\textnormal{\textbf{', '}}'],
|
|
|
|
'file' => ['\textnormal{\texttt{', '}}'],
|
|
|
|
'path' => ['\textnormal{\texttt{', '}}'],
|
|
|
|
'cmd' => ['\textnormal{\texttt{', "}}"],
|
|
|
|
'user' => ['\textnormal{\texttt{', '}}'],
|
|
|
|
'br-option' => ['', ''],
|
|
|
|
# 'param' => ['\texttt{', '}'],
|
|
|
|
# 'setting' => ['\texttt{', '}'],
|
|
|
|
'br-option' => ['\textnormal{\texttt{', '}}'],
|
|
|
|
'br-setting' => ['\textnormal{\texttt{', '}}'],
|
|
|
|
'pg-option' => ['\textnormal{\texttt{', '}}'],
|
|
|
|
'pg-setting' => ['\textnormal{\texttt{', '}}'],
|
|
|
|
'code' => ['\textnormal{\texttt{', '}}'],
|
|
|
|
# 'code' => ['\texttt{', '}'],
|
|
|
|
# 'code-block' => ['', ''],
|
|
|
|
# 'exe' => [undef, ''],
|
|
|
|
'backrest' => [undef, ''],
|
|
|
|
'postgres' => ['PostgreSQL', '']
|
|
|
|
},
|
|
|
|
|
2015-09-03 00:55:04 +02:00
|
|
|
'html' =>
|
|
|
|
{
|
2015-11-22 23:44:01 +02:00
|
|
|
'quote' => ['<q>', '</q>'],
|
2015-10-28 11:10:36 +02:00
|
|
|
'b' => ['<b>', '</b>'],
|
|
|
|
'i' => ['<i>', '</i>'],
|
2015-11-22 23:44:01 +02:00
|
|
|
# 'bi' => ['<i><b>', '</b></i>'],
|
2015-10-28 11:10:36 +02:00
|
|
|
'ul' => ['<ul>', '</ul>'],
|
|
|
|
'ol' => ['<ol>', '</ol>'],
|
|
|
|
'li' => ['<li>', '</li>'],
|
|
|
|
'id' => ['<span class="id">', '</span>'],
|
2015-11-22 23:44:01 +02:00
|
|
|
'host' => ['<span class="host">', '</span>'],
|
2015-10-28 11:10:36 +02:00
|
|
|
'file' => ['<span class="file">', '</span>'],
|
|
|
|
'path' => ['<span class="path">', '</span>'],
|
|
|
|
'cmd' => ['<span class="cmd">', '</span>'],
|
|
|
|
'user' => ['<span class="user">', '</span>'],
|
|
|
|
'br-option' => ['<span class="br-option">', '</span>'],
|
|
|
|
'br-setting' => ['<span class="br-setting">', '</span>'],
|
|
|
|
'pg-option' => ['<span class="pg-option">', '</span>'],
|
|
|
|
'pg-setting' => ['<span class="pg-setting">', '</span>'],
|
2015-11-22 23:44:01 +02:00
|
|
|
'code' => ['<span class="id">', '</span>'],
|
2015-10-28 11:10:36 +02:00
|
|
|
'code-block' => ['<code-block>', '</code-block>'],
|
2015-11-22 23:44:01 +02:00
|
|
|
'exe' => [undef, ''],
|
2016-04-14 01:09:35 +02:00
|
|
|
'setting' => ['<span class="br-setting">', '</span>'], # ??? This will need to be fixed
|
2015-10-28 11:10:36 +02:00
|
|
|
'backrest' => [undef, ''],
|
|
|
|
'postgres' => ['<span class="postgres">PostgreSQL</span>', '']
|
2015-09-03 00:55:04 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
####################################################################################################################################
|
|
|
|
# CONSTRUCTOR
|
|
|
|
####################################################################################################################################
|
|
|
|
sub new
|
|
|
|
{
|
|
|
|
my $class = shift; # Class name
|
|
|
|
|
|
|
|
# Create the class hash
|
|
|
|
my $self = {};
|
|
|
|
bless $self, $class;
|
|
|
|
|
|
|
|
# Assign function parameters, defaults, and log debug info
|
|
|
|
(
|
|
|
|
my $strOperation,
|
|
|
|
$self->{strType},
|
2015-11-22 23:44:01 +02:00
|
|
|
$self->{oManifest},
|
|
|
|
$self->{strRenderOutKey},
|
2015-09-03 00:55:04 +02:00
|
|
|
) =
|
|
|
|
logDebugParam
|
|
|
|
(
|
2016-05-26 15:09:42 +02:00
|
|
|
__PACKAGE__ . '->new', \@_,
|
2015-09-03 00:55:04 +02:00
|
|
|
{name => 'strType'},
|
2015-11-22 23:44:01 +02:00
|
|
|
{name => 'oManifest'},
|
|
|
|
{name => 'strRenderOutKey', required => false}
|
2015-09-03 00:55:04 +02:00
|
|
|
);
|
|
|
|
|
2015-11-22 23:44:01 +02:00
|
|
|
# Initialize project tags
|
|
|
|
$$oRenderTag{markdown}{backrest}[0] = "{[project]}";
|
|
|
|
$$oRenderTag{markdown}{exe}[0] = "{[project-exe]}";
|
|
|
|
|
|
|
|
$$oRenderTag{text}{backrest}[0] = "{[project]}";
|
|
|
|
$$oRenderTag{text}{exe}[0] = "{[project-exe]}";
|
|
|
|
|
|
|
|
$$oRenderTag{latex}{backrest}[0] = "{[project]}";
|
|
|
|
$$oRenderTag{latex}{exe}[0] = "\\textnormal\{\\texttt\{[project-exe]}}\}\}";
|
|
|
|
|
|
|
|
$$oRenderTag{html}{backrest}[0] = "<span class=\"backrest\">{[project]}</span>";
|
|
|
|
$$oRenderTag{html}{exe}[0] = "<span class=\"file\">{[project-exe]}</span>";
|
|
|
|
|
|
|
|
if (defined($self->{strRenderOutKey}))
|
|
|
|
{
|
|
|
|
# Copy page data to self
|
2016-06-04 17:40:33 +02:00
|
|
|
my $oRenderOut =
|
|
|
|
$self->{oManifest}->renderOutGet($self->{strType} eq 'latex' ? 'pdf' : $self->{strType}, $self->{strRenderOutKey});
|
2015-11-22 23:44:01 +02:00
|
|
|
|
2016-06-04 17:40:33 +02:00
|
|
|
# If these are the backrest docs then load the reference
|
2016-06-04 18:04:09 +02:00
|
|
|
if ($self->{oManifest}->isBackRest())
|
|
|
|
{
|
|
|
|
$self->{oReference} =
|
|
|
|
new BackRestDoc::Common::DocConfig(${$self->{oManifest}->sourceGet('reference')}{doc}, $self);
|
|
|
|
}
|
2015-11-22 23:44:01 +02:00
|
|
|
|
2016-06-02 15:32:56 +02:00
|
|
|
if (defined($$oRenderOut{source}) && $$oRenderOut{source} eq 'reference' && $self->{oManifest}->isBackRest())
|
2015-11-22 23:44:01 +02:00
|
|
|
{
|
|
|
|
if ($self->{strRenderOutKey} eq 'configuration')
|
|
|
|
{
|
|
|
|
$self->{oDoc} = $self->{oReference}->helpConfigDocGet();
|
|
|
|
}
|
|
|
|
elsif ($self->{strRenderOutKey} eq 'command')
|
|
|
|
{
|
|
|
|
$self->{oDoc} = $self->{oReference}->helpCommandDocGet();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
confess &log(ERROR, "cannot render $self->{strRenderOutKey} from source $$oRenderOut{source}");
|
|
|
|
}
|
|
|
|
}
|
2016-06-02 15:32:56 +02:00
|
|
|
elsif (defined($$oRenderOut{source}) && $$oRenderOut{source} eq 'release' && $self->{oManifest}->isBackRest())
|
2016-05-26 15:20:55 +02:00
|
|
|
{
|
2016-06-02 15:32:56 +02:00
|
|
|
require BackRestDoc::Custom::DocCustomRelease;
|
|
|
|
BackRestDoc::Custom::DocCustomRelease->import();
|
|
|
|
|
|
|
|
$self->{oDoc} =
|
|
|
|
(new BackRestDoc::Custom::DocCustomRelease(${$self->{oManifest}->sourceGet('release')}{doc}, $self))->docGet();
|
2016-05-26 15:20:55 +02:00
|
|
|
}
|
2015-11-22 23:44:01 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
$self->{oDoc} = ${$self->{oManifest}->sourceGet($self->{strRenderOutKey})}{doc};
|
|
|
|
}
|
2016-06-02 15:32:56 +02:00
|
|
|
|
|
|
|
$self->{oSource} = $self->{oManifest}->sourceGet($$oRenderOut{source});
|
2015-11-22 23:44:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (defined($self->{strRenderOutKey}))
|
|
|
|
{
|
|
|
|
# Build the doc
|
|
|
|
$self->build($self->{oDoc});
|
|
|
|
|
|
|
|
# Get required sections
|
|
|
|
foreach my $strPath (@{$self->{oManifest}->{stryRequire}})
|
|
|
|
{
|
2016-06-24 14:12:58 +02:00
|
|
|
if (substr($strPath, 0, 1) ne '/')
|
|
|
|
{
|
|
|
|
confess &log(ERROR, "path ${strPath} must begin with a /");
|
|
|
|
}
|
|
|
|
|
2015-11-22 23:44:01 +02:00
|
|
|
if (defined(${$self->{oSection}}{$strPath}))
|
|
|
|
{
|
|
|
|
$self->required($strPath);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-09-03 00:55:04 +02:00
|
|
|
|
2016-11-07 17:06:35 +02:00
|
|
|
if (defined($self->{oDoc}))
|
|
|
|
{
|
|
|
|
$self->{bToc} = !defined($self->{oDoc}->paramGet('toc', false)) || $self->{oDoc}->paramGet('toc') eq 'y' ? true : false;
|
|
|
|
$self->{bTocNumber} =
|
|
|
|
$self->{bToc} &&
|
|
|
|
(!defined($self->{oDoc}->paramGet('toc-number', false)) || $self->{oDoc}->paramGet('toc-number') eq 'y') ? true : false;
|
|
|
|
}
|
|
|
|
|
2015-09-03 00:55:04 +02:00
|
|
|
# Return from function and log return values if any
|
|
|
|
return logDebugReturn
|
|
|
|
(
|
|
|
|
$strOperation,
|
|
|
|
{name => 'self', value => $self}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2015-11-22 23:44:01 +02:00
|
|
|
####################################################################################################################################
|
|
|
|
# variableReplace
|
|
|
|
#
|
|
|
|
# Replace variables in the string.
|
|
|
|
####################################################################################################################################
|
|
|
|
sub variableReplace
|
|
|
|
{
|
|
|
|
my $self = shift;
|
|
|
|
|
|
|
|
return $self->{oManifest}->variableReplace(shift, $self->{strType});
|
|
|
|
}
|
|
|
|
|
|
|
|
####################################################################################################################################
|
|
|
|
# variableSet
|
|
|
|
#
|
|
|
|
# Set a variable to be replaced later.
|
|
|
|
####################################################################################################################################
|
|
|
|
sub variableSet
|
|
|
|
{
|
|
|
|
my $self = shift;
|
|
|
|
|
|
|
|
return $self->{oManifest}->variableSet(shift, shift);
|
|
|
|
}
|
|
|
|
|
|
|
|
####################################################################################################################################
|
|
|
|
# variableGet
|
|
|
|
#
|
|
|
|
# Get the current value of a variable.
|
|
|
|
####################################################################################################################################
|
|
|
|
sub variableGet
|
|
|
|
{
|
|
|
|
my $self = shift;
|
|
|
|
|
|
|
|
return $self->{oManifest}->variableGet(shift);
|
|
|
|
}
|
|
|
|
|
|
|
|
####################################################################################################################################
|
|
|
|
# build
|
|
|
|
#
|
|
|
|
# Build the section map and perform keyword matching.
|
|
|
|
####################################################################################################################################
|
|
|
|
sub build
|
|
|
|
{
|
|
|
|
my $self = shift;
|
|
|
|
my $oNode = shift;
|
|
|
|
my $oParent = shift;
|
|
|
|
my $strPath = shift;
|
2016-11-17 23:35:11 +02:00
|
|
|
my $strPathPrefix = shift;
|
2015-11-22 23:44:01 +02:00
|
|
|
|
|
|
|
# &log(INFO, " node " . $oNode->nameGet());
|
|
|
|
|
|
|
|
my $strName = $oNode->nameGet();
|
|
|
|
|
|
|
|
if (defined($oParent))
|
|
|
|
{
|
|
|
|
if (!$self->{oManifest}->keywordMatch($oNode->paramGet('keyword', false)))
|
|
|
|
{
|
|
|
|
my $strDescription;
|
|
|
|
|
|
|
|
if (defined($oNode->nodeGet('title', false)))
|
|
|
|
{
|
|
|
|
$strDescription = $self->processText($oNode->nodeGet('title')->textGet());
|
|
|
|
}
|
|
|
|
|
|
|
|
&log(DEBUG, " filtered ${strName}" . (defined($strDescription) ? ": ${strDescription}" : ''));
|
|
|
|
|
|
|
|
$oParent->nodeRemove($oNode);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
&log(DEBUG, ' build document');
|
|
|
|
$self->{oSection} = {};
|
|
|
|
}
|
|
|
|
|
2016-11-17 23:35:11 +02:00
|
|
|
# Build section
|
2015-11-22 23:44:01 +02:00
|
|
|
if ($strName eq 'section')
|
|
|
|
{
|
2016-11-17 23:35:11 +02:00
|
|
|
&log(DEBUG, 'build section [' . $oNode->paramGet('id') . ']');
|
|
|
|
|
|
|
|
# Set path and parent-path for this section
|
2015-11-22 23:44:01 +02:00
|
|
|
if (defined($strPath))
|
|
|
|
{
|
|
|
|
$oNode->paramSet('path-parent', $strPath);
|
|
|
|
}
|
|
|
|
|
|
|
|
$strPath .= '/' . $oNode->paramGet('id');
|
|
|
|
|
|
|
|
&log(DEBUG, " path ${strPath}");
|
|
|
|
${$self->{oSection}}{$strPath} = $oNode;
|
|
|
|
$oNode->paramSet('path', $strPath);
|
2016-11-17 23:35:11 +02:00
|
|
|
|
|
|
|
# If section content is being pulled from elsewhere go get the content
|
|
|
|
if ($oNode->paramTest('source'))
|
|
|
|
{
|
|
|
|
my $oSource = ${$self->{oManifest}->sourceGet($oNode->paramGet('source'))}{doc};
|
|
|
|
|
|
|
|
foreach my $oSection ($oSource->nodeList('section'))
|
|
|
|
{
|
|
|
|
push(@{${$oNode->{oDoc}}{children}}, $oSection->{oDoc});
|
|
|
|
}
|
|
|
|
|
|
|
|
# Set path prefix to modify all section paths further down
|
|
|
|
$strPathPrefix = $strPath;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
# Build link
|
|
|
|
elsif ($strName eq 'link')
|
|
|
|
{
|
|
|
|
&log(DEBUG, 'build link [' . $oNode->valueGet() . ']');
|
|
|
|
|
|
|
|
# If the path prefix is set and this is a section
|
|
|
|
if (defined($strPathPrefix) && $oNode->paramTest('section'))
|
|
|
|
{
|
|
|
|
my $strNewPath = $strPathPrefix . $oNode->paramGet('section');
|
|
|
|
&log(DEBUG, "modify link section from '" . $oNode->paramGet('section') . "' to '${strNewPath}'");
|
|
|
|
|
|
|
|
$oNode->paramSet('section', $strNewPath);
|
|
|
|
}
|
2015-11-22 23:44:01 +02:00
|
|
|
}
|
|
|
|
|
2016-11-17 23:35:11 +02:00
|
|
|
# Iterate all text nodes
|
|
|
|
if (defined($oNode->textGet(false)))
|
|
|
|
{
|
|
|
|
foreach my $oChild ($oNode->textGet()->nodeList(undef, false))
|
|
|
|
{
|
|
|
|
if (ref(\$oChild) ne "SCALAR")
|
|
|
|
{
|
|
|
|
$self->build($oChild, $oNode, $strPath, $strPathPrefix);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
# Iterate all non-text nodes
|
2015-11-22 23:44:01 +02:00
|
|
|
foreach my $oChild ($oNode->nodeList(undef, false))
|
|
|
|
{
|
2016-11-17 23:35:11 +02:00
|
|
|
if (ref(\$oChild) ne "SCALAR")
|
|
|
|
{
|
|
|
|
$self->build($oChild, $oNode, $strPath, $strPathPrefix);
|
|
|
|
}
|
2015-11-22 23:44:01 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
####################################################################################################################################
|
|
|
|
# required
|
|
|
|
#
|
|
|
|
# Build a list of required sections
|
|
|
|
####################################################################################################################################
|
|
|
|
sub required
|
|
|
|
{
|
|
|
|
my $self = shift;
|
|
|
|
my $strPath = shift;
|
|
|
|
my $bDepend = shift;
|
|
|
|
|
|
|
|
# If node is not found that means the path is invalid
|
|
|
|
my $oNode = ${$self->{oSection}}{$strPath};
|
|
|
|
|
|
|
|
if (!defined($oNode))
|
|
|
|
{
|
|
|
|
confess &log(ERROR, "invalid path ${strPath}");
|
|
|
|
}
|
|
|
|
|
|
|
|
# Only add sections that are listed dependencies
|
|
|
|
if (!defined($bDepend) || $bDepend)
|
|
|
|
{
|
|
|
|
# Match section and all child sections
|
2016-05-19 16:25:04 +02:00
|
|
|
foreach my $strChildPath (sort(keys(%{$self->{oSection}})))
|
2015-11-22 23:44:01 +02:00
|
|
|
{
|
|
|
|
if ($strChildPath =~ /^$strPath$/ || $strChildPath =~ /^$strPath\/.*$/)
|
|
|
|
{
|
2016-06-18 15:22:26 +02:00
|
|
|
if (!defined(${$self->{oSectionRequired}}{$strChildPath}))
|
|
|
|
{
|
|
|
|
&log(INFO, " require section: ${strChildPath}");
|
2015-11-22 23:44:01 +02:00
|
|
|
|
2016-06-18 15:22:26 +02:00
|
|
|
${$self->{oSectionRequired}}{$strChildPath} = true;
|
|
|
|
}
|
2015-11-22 23:44:01 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
# Get the path of the current section's parent
|
|
|
|
my $strParentPath = $oNode->paramGet('path-parent', false);
|
|
|
|
|
|
|
|
if ($oNode->paramTest('depend'))
|
|
|
|
{
|
|
|
|
foreach my $strDepend (split(',', $oNode->paramGet('depend')))
|
|
|
|
{
|
|
|
|
if ($strDepend !~ /^\//)
|
|
|
|
{
|
|
|
|
if (!defined($strParentPath))
|
|
|
|
{
|
|
|
|
$strDepend = "/${strDepend}";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$strDepend = "${strParentPath}/${strDepend}";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$self->required($strDepend, true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
elsif (defined($strParentPath))
|
|
|
|
{
|
|
|
|
$self->required($strParentPath, false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
####################################################################################################################################
|
|
|
|
# isRequired
|
|
|
|
#
|
|
|
|
# Is it required to execute the section statements?
|
|
|
|
####################################################################################################################################
|
|
|
|
sub isRequired
|
|
|
|
{
|
|
|
|
my $self = shift;
|
|
|
|
my $oSection = shift;
|
|
|
|
|
|
|
|
if (!defined($self->{oSectionRequired}))
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
my $strPath = $oSection->paramGet('path');
|
|
|
|
|
|
|
|
defined(${$self->{oSectionRequired}}{$strPath}) ? true : false;
|
|
|
|
}
|
|
|
|
|
2015-09-03 00:55:04 +02:00
|
|
|
####################################################################################################################################
|
|
|
|
# processTag
|
|
|
|
####################################################################################################################################
|
|
|
|
sub processTag
|
|
|
|
{
|
|
|
|
my $self = shift;
|
|
|
|
|
|
|
|
# Assign function parameters, defaults, and log debug info
|
|
|
|
my
|
|
|
|
(
|
|
|
|
$strOperation,
|
|
|
|
$oTag
|
|
|
|
) =
|
|
|
|
logDebugParam
|
|
|
|
(
|
2016-05-26 15:09:42 +02:00
|
|
|
__PACKAGE__ . '->processTag', \@_,
|
2015-09-03 00:55:04 +02:00
|
|
|
{name => 'oTag', trace => true}
|
|
|
|
);
|
|
|
|
|
|
|
|
my $strBuffer = "";
|
|
|
|
|
|
|
|
my $strType = $self->{strType};
|
2015-09-08 13:31:24 +02:00
|
|
|
my $strTag = $oTag->nameGet();
|
2015-09-03 00:55:04 +02:00
|
|
|
|
2015-10-28 11:10:36 +02:00
|
|
|
if (!defined($strTag))
|
2015-09-03 00:55:04 +02:00
|
|
|
{
|
2015-10-28 11:10:36 +02:00
|
|
|
use Data::Dumper;
|
|
|
|
confess Dumper($oTag);
|
2015-09-03 00:55:04 +02:00
|
|
|
}
|
|
|
|
|
2015-10-28 11:10:36 +02:00
|
|
|
if ($strTag eq 'link')
|
2015-09-03 00:55:04 +02:00
|
|
|
{
|
2015-10-28 11:10:36 +02:00
|
|
|
my $strUrl = $oTag->paramGet('url', false);
|
|
|
|
|
2016-06-04 18:04:09 +02:00
|
|
|
if (!defined($strUrl))
|
2015-10-28 11:10:36 +02:00
|
|
|
{
|
2016-06-04 18:04:09 +02:00
|
|
|
my $strPage = $self->variableReplace($oTag->paramGet('page', false));
|
2015-10-28 11:10:36 +02:00
|
|
|
|
2016-06-04 18:04:09 +02:00
|
|
|
# If this is a page URL
|
|
|
|
if (defined($strPage))
|
2015-10-28 11:10:36 +02:00
|
|
|
{
|
2016-06-04 18:04:09 +02:00
|
|
|
# If the page wasn't rendered then point at the website
|
|
|
|
if (!defined($self->{oManifest}->renderOutGet($strType, $strPage, true)))
|
2016-06-02 15:32:56 +02:00
|
|
|
{
|
2016-06-04 18:04:09 +02:00
|
|
|
$strUrl = '{[backrest-url-base]}/' . $oTag->paramGet('page') . '.html';
|
|
|
|
}
|
|
|
|
# Else point locally
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if ($strType eq 'html' || $strType eq 'markdown')
|
2016-06-02 15:32:56 +02:00
|
|
|
{
|
2016-06-04 18:04:09 +02:00
|
|
|
$strUrl =
|
|
|
|
$oTag->paramGet('page', false) . '.' .
|
|
|
|
($strType eq 'html' ? $strType : '.md');
|
2016-06-02 15:32:56 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-06-04 18:04:09 +02:00
|
|
|
confess &log(ERROR, "page links not supported for type ${strType}, value '" . $oTag->valueGet() . "'");
|
2016-06-02 15:32:56 +02:00
|
|
|
}
|
|
|
|
}
|
2016-06-04 18:04:09 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
my $strSection = $oTag->paramGet('section');
|
2016-11-17 23:35:11 +02:00
|
|
|
my $oSection = ${$self->{oSection}}{$strSection};
|
|
|
|
|
|
|
|
if (!defined($oSection))
|
|
|
|
{
|
|
|
|
confess &log(ERROR, "section link '${strSection}' does not exist");
|
|
|
|
}
|
2016-06-04 18:04:09 +02:00
|
|
|
|
|
|
|
if (!defined($strSection))
|
|
|
|
{
|
|
|
|
confess &log(ERROR, "link with value '" . $oTag->valueGet() . "' must defined url, page, or section");
|
|
|
|
}
|
2015-12-23 18:04:26 +02:00
|
|
|
|
2016-06-04 18:04:09 +02:00
|
|
|
if ($strType eq 'html')
|
2015-12-23 18:04:26 +02:00
|
|
|
{
|
2016-11-17 23:35:11 +02:00
|
|
|
$strUrl = '#' . substr($strSection, 1);
|
2015-12-23 18:04:26 +02:00
|
|
|
}
|
2016-06-04 18:04:09 +02:00
|
|
|
elsif ($strType eq 'latex')
|
|
|
|
{
|
|
|
|
$strUrl = $strSection;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-11-17 23:35:11 +02:00
|
|
|
$strUrl = lc($self->processText($oSection->nodeGet('title')->textGet()));
|
|
|
|
$strUrl =~ s/[^\w\- ]//g;
|
|
|
|
$strUrl =~ s/ /-/g;
|
|
|
|
$strUrl = '#' . $strUrl;
|
2016-06-04 18:04:09 +02:00
|
|
|
}
|
2015-10-28 11:10:36 +02:00
|
|
|
}
|
2016-06-04 18:04:09 +02:00
|
|
|
}
|
2015-10-28 11:10:36 +02:00
|
|
|
|
2016-06-04 18:04:09 +02:00
|
|
|
if ($strType eq 'html')
|
|
|
|
{
|
2015-10-28 11:10:36 +02:00
|
|
|
$strBuffer = '<a href="' . $strUrl . '">' . $oTag->valueGet() . '</a>';
|
|
|
|
}
|
2016-06-04 18:04:09 +02:00
|
|
|
elsif ($strType eq 'markdown')
|
|
|
|
{
|
|
|
|
$strBuffer = '[' . $oTag->valueGet() . '](' . $strUrl . ')';
|
|
|
|
}
|
2015-11-22 23:44:01 +02:00
|
|
|
elsif ($strType eq 'latex')
|
|
|
|
{
|
2016-06-04 18:04:09 +02:00
|
|
|
if ($oTag->paramTest('url'))
|
2015-12-23 18:04:26 +02:00
|
|
|
{
|
2016-06-04 18:04:09 +02:00
|
|
|
$strBuffer = "\\href{$strUrl}{" . $oTag->valueGet() . "}";
|
2016-03-10 17:58:07 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-06-04 18:04:09 +02:00
|
|
|
$strBuffer = "\\hyperref[$strUrl]{" . $oTag->valueGet() . "}";
|
2016-03-10 17:58:07 +02:00
|
|
|
}
|
2015-11-22 23:44:01 +02:00
|
|
|
}
|
2015-10-28 11:10:36 +02:00
|
|
|
else
|
|
|
|
{
|
2016-06-04 18:04:09 +02:00
|
|
|
confess "'link' tag not valid for type ${strType}";
|
2015-10-28 11:10:36 +02:00
|
|
|
}
|
2015-09-03 00:55:04 +02:00
|
|
|
}
|
2015-09-08 13:31:24 +02:00
|
|
|
else
|
2015-09-03 00:55:04 +02:00
|
|
|
{
|
2015-10-28 11:10:36 +02:00
|
|
|
my $strStart = $$oRenderTag{$strType}{$strTag}[0];
|
|
|
|
my $strStop = $$oRenderTag{$strType}{$strTag}[1];
|
|
|
|
|
|
|
|
if (!defined($strStart) || !defined($strStop))
|
2015-09-03 00:55:04 +02:00
|
|
|
{
|
2016-06-04 18:04:09 +02:00
|
|
|
confess &log(ERROR, "invalid type ${strType} or tag ${strTag}");
|
2015-09-03 00:55:04 +02:00
|
|
|
}
|
|
|
|
|
2015-10-28 11:10:36 +02:00
|
|
|
$strBuffer .= $strStart;
|
|
|
|
|
|
|
|
if ($strTag eq 'p' || $strTag eq 'title' || $strTag eq 'li' || $strTag eq 'code-block' || $strTag eq 'summary')
|
|
|
|
{
|
|
|
|
$strBuffer .= $self->processText($oTag);
|
|
|
|
}
|
|
|
|
elsif (defined($oTag->valueGet()))
|
|
|
|
{
|
|
|
|
$strBuffer .= $oTag->valueGet();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
foreach my $oSubTag ($oTag->nodeList(undef, false))
|
|
|
|
{
|
|
|
|
$strBuffer .= $self->processTag($oSubTag);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$strBuffer .= $strStop;
|
|
|
|
}
|
2015-09-03 00:55:04 +02:00
|
|
|
|
|
|
|
# Return from function and log return values if any
|
|
|
|
return logDebugReturn
|
|
|
|
(
|
|
|
|
$strOperation,
|
|
|
|
{name => 'strBuffer', value => $strBuffer, trace => true}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
####################################################################################################################################
|
|
|
|
# processText
|
|
|
|
####################################################################################################################################
|
|
|
|
sub processText
|
|
|
|
{
|
|
|
|
my $self = shift;
|
|
|
|
|
|
|
|
# Assign function parameters, defaults, and log debug info
|
|
|
|
my
|
|
|
|
(
|
|
|
|
$strOperation,
|
|
|
|
$oText
|
|
|
|
) =
|
|
|
|
logDebugParam
|
|
|
|
(
|
2016-05-26 15:09:42 +02:00
|
|
|
__PACKAGE__ . '->processText', \@_,
|
2015-09-03 00:55:04 +02:00
|
|
|
{name => 'oText', trace => true}
|
|
|
|
);
|
|
|
|
|
|
|
|
my $strType = $self->{strType};
|
2015-09-08 13:31:24 +02:00
|
|
|
my $strBuffer = '';
|
2015-09-03 00:55:04 +02:00
|
|
|
|
2015-09-08 13:31:24 +02:00
|
|
|
foreach my $oNode ($oText->nodeList(undef, false))
|
2015-09-03 00:55:04 +02:00
|
|
|
{
|
2015-09-08 13:31:24 +02:00
|
|
|
if (ref(\$oNode) eq "SCALAR")
|
2015-09-03 00:55:04 +02:00
|
|
|
{
|
2015-11-22 23:44:01 +02:00
|
|
|
if ($oNode =~ /\"/)
|
|
|
|
{
|
|
|
|
confess &log(ERROR, "unable to process quotes in string (use <quote> instead):\n${oNode}");
|
|
|
|
}
|
|
|
|
|
2015-09-08 13:31:24 +02:00
|
|
|
$strBuffer .= $oNode;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$strBuffer .= $self->processTag($oNode);
|
2015-09-03 00:55:04 +02:00
|
|
|
}
|
|
|
|
}
|
2015-10-28 11:10:36 +02:00
|
|
|
#
|
|
|
|
# if ($strType eq 'html')
|
|
|
|
# {
|
|
|
|
# # $strBuffer =~ s/^\s+|\s+$//g;
|
|
|
|
#
|
|
|
|
# $strBuffer =~ s/\n/\<br\/\>\n/g;
|
|
|
|
# }
|
|
|
|
|
|
|
|
# if ($strType eq 'markdown')
|
|
|
|
# {
|
|
|
|
# $strBuffer =~ s/^\s+|\s+$//g;
|
|
|
|
|
|
|
|
$strBuffer =~ s/ +/ /g;
|
|
|
|
$strBuffer =~ s/^ //smg;
|
|
|
|
# }
|
2015-09-03 00:55:04 +02:00
|
|
|
|
2015-11-22 23:44:01 +02:00
|
|
|
if ($strType eq 'latex')
|
|
|
|
{
|
|
|
|
$strBuffer =~ s/\&mdash\;/---/g;
|
|
|
|
$strBuffer =~ s/\<\;/\</g;
|
|
|
|
$strBuffer =~ s/\<\=/\$\\leq\$/g;
|
|
|
|
$strBuffer =~ s/\>\=/\$\\geq\$/g;
|
|
|
|
# $strBuffer =~ s/\_/\\_/g;
|
|
|
|
}
|
|
|
|
|
|
|
|
$strBuffer = $self->variableReplace($strBuffer);
|
|
|
|
|
2015-09-03 00:55:04 +02:00
|
|
|
# Return from function and log return values if any
|
|
|
|
return logDebugReturn
|
|
|
|
(
|
|
|
|
$strOperation,
|
|
|
|
{name => 'strBuffer', value => $strBuffer, trace => true}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
1;
|