PodTemplates

Templates needed for a Processed Pod.

Table of Contents

Template Engine AutodetectionMinimum SetTest-TemplatesVerification utilityUsageData structures accepted by templatesStructure specification syntaxExamplesParameters of required templatesNotes

This describes the template set for the ProcessedPod renderer, the templating engines that can be used, the Test-Template functions, and the test-templates verification utility.

The templating part of Raku-Pod-Render is separated into a Templating module RenderPod::Templating. It is written to allow for other templating engines to be added. Currently the following Engines are available in this distribution:

  • Mustache

  • Raku Closure (a templating system designed for Raku-Pod-Render)

  • Cro Templates

Template Engine Autodetection

Templates are written to be interpretted by a templating engine. The Templating module in this distribution has been written to allow for other engines to be added. It is best to look at the module to see how this is done.

The first minimum set of templates is loaded and an autodetect function determines which engine to use. Subsequent templates added by plugins must use the same template engine.

The template engine is determined in two ways:

  • The hash (normally loaded from a file) containing the minimum set of templates may contain the key _templater, which must have a String value that is the name of the class implementing the Templating Engine. For the default engines, these are

MustacheMustacheTemplater

Raku ClosureRakuClosureTemplater

Cro TemplatesCroTemplater

Minimum Set

The minimum set of templates is block-code comment declarator defn dlist-end dlist-start escaped footnotes format-b format-c format-i format-k format-l format-n format-p format-r format-t format-u format-x glossary heading item list meta named output para pod raw source-wrap table toc.

Almost all of these templates expect a [parameter to be rendered](Parameters of required templates.md). The test functions will check the templates for the parameters to be returned.

Test-Templates

These subs are intended for use in a TAP context. They can be applied as follows

use Test;
use RenderPod::Test-Templates;
%templates = EVALFILE "templates/basic-templates.raku";
templates-present %templates, 'basic file contains minimum set of templates';

multi sub templates-present( Hash %templates, Str $description = 'minimum templates present' )Short for 'are all minimum templates present in the hash'. Takes a hash, whose keys are template names. Checks the key-names contains all of the required templates.

multi sub templates-match( Hash %templates, Str $description = 'minimum templates match the specification' )Checks whether the required templates render all parameters. Fails if any parameters are not rendered. If a parameter should not appear, render it as a comment or invisible element, so that it is in the output for it to match the specification, but not be seen when finally rendered. If there are more templates in the hash than are in the specifications, they are ignored.

multi sub extra-templates-match( Hash %templates, Hash %specifications, Str $description = 'extra templates match')Check that templates in %templates match the specifications in %specifications. True if the templates match, AND all the templates in %templates are specified in %specifications.

Verification utility

The test-templates utility helps to verify whether all the parameters specified for a template are in fact rendered by the template.

A template developer may decide not to render a parameter provided by ProcessedPod to the template. The verification tool will flag this with a warning.

If the minimum set of templates is not provided, the renderer will throw an error.

Usage

This testing tool has the structure of the minimum template set coded into it. It is called as

test-templates --extra='filename-of-custom-template-structure.raku' --verbosity=2 'filename-of-templates.raku'
  • --extra (optional, default: Any )

This is a Raku compilable program that returns a Hash with the structure of the key, more below.

  • --verbosity (optional, default: 0 )

An integer that produces more information for higher values:

*  = 0 returns 0 if no errors, or list templates with errors

*  = 1 0 + parameters sent, sub-keys not returned

*  = 2 1 + sub-keys found in error templates

*  = 3 2 + full response for error templates

*  = 4 all templates with sub-key returns

*  = 5 5 + full response for all templates
  • 'filename-of-templates.raku' (mandatory, string)

A Raku compilable program that returns a Hash contains all the minimum templates as keys pointing subroutines.

If the minimum set of templates is not provided in filename-of-templates.raku, a MissingTemplates exception will be thrown.

Since all the templates are provided to all the templates, it is recommended to use sub-templates within the minimum set to simplify the code.

Data structures accepted by templates

All templates, whether Mustache or RakuClosure, expect PodRender to present them with parameters with one of the following data structures

levelallowable Typeelement Type
topStrn/a
topHashStr
Bool
Hash
Array
! topStrn/a
! topBooln/a
! topHashStr
Bool
Hash
Array
! topArrayStr
! topArrayHash

This specification allows for test-templates to create create random data for template and to test whether it is returned.

However, the developer has to provide information about what each template is expecting.

Structure specification syntax

As can be seen from the table in [Data structures accepted by templates](Data structures accepted by templates.md), a parameter value, whether directly expected from a key, or as part of an Array or Hash, may be either 'Bool' or 'Str'. These are given as Str values, eg.

'title' => 'Str',
'heading' => { :text('Str'), :level('Str'), :is-header('Bool') }

A Hash element is specified as a Hash, using { ... } as shown above, and an Array is specified using [ ... ] , eg.

'table' => { :rows( [ 'Str', ] ) }

Examples

Examples of a set of RakuClosureTemplates can be found in the resources directory of the distribution, as

  • closure-temp.raku is an array of templates, including a custom image template. The templates are designed for Pod::To::HTML2.

  • extra-test.raku is a hash with the template structure for the image template.

Parameters of required templates

These are the parameters for the required templates for ProcessedPod, and helper templates in Pod::To::HTML2

Required templates and their normal parameters

KeyParameterSub-paramTypeDescription
escapedShould be a special case
contentsStringString
rawShould be a special case
contentsStringnormally should return the contents unchanged
block-codetemplate for code
contentsStringA code body
comment
contentsStringwill be made into a comment
declaratorrenders documentation on a sub or variable
targetString'target' is used in the glossary to point to the content, like a TOC for a header
codeStringthe line of code that is being documented
contentsStringthe documentation
dlist-startStringthe tag or code that starts a declaration list
defnrenders and element of a definition list
termStringthe term part of a definition
contentsStringthe definition body
dlist-endStringthe end tag of a definition list
format-bbold
contentsString
format-cinline code
contentsString
format-iitalic
contentsString
format-kkeyboard
contentsString
format-rreplace
contentsString
format-tterminal
contentsString
format-uunderline
contentsString
paraThe template for a normal paragraph
contentsStringtext in para block
format-lrenders a link to somewhere else
internalBooleantrue if target is within document
externalBooleantrue if target is not in local area, eg., an internet url
targetStringThe url of the link
localStringurl is local to system (perhaps with implied file extension)
contentsStringThe text associated with the link, which should be read (may be empty)
format-nrender the footnote for the text
retTargetStringThe anchor name the footnote will target
fnTargetStringThe target for the footnote text
fnNumberStringThe footnote number as allocated by the renderer
format-pRenders arbitrary text at some url.
contentsStringThe text at the link indicated by P
htmlBooleanif True, then contents is in HTML format
format-x
targetStringAnchor name the glossary item will target
textStringThe text to be included (the text to be included in the glossary is in the glossary structure)
headerBooleanTrue if the glossary item is also a header
headingRenders a heading in the text
levelStringThe level of the heading
targetStringThe anchor which TOC will target
topStringTop of document target
textStringText of the header
itemRenders to a string an item block
contentsStringcontents of block
listrenders a lest of items,
itemsArrayOf strings already rendered with the "item" template
namedA named block is included in the TOC
levelStringlevel of the header implied by the block = 1
targetStringThe target in the text body to which the TOC entry points
topStringThe top of the document for the Header to point to
nameStringThe Name of the block
contentsStringThe contents of the block
outputOutput block contents
contentsString
pod
nameStringLike "named"
contentsStringas "named"
tailStringany remaining list at end of pod not triggered by next pod statement
tablerenders table with hash of keys
captionStringpossibly empty caption
headersArrayof hash with key 'cells'
cellsArrayOf string elements, that are the headers
rowsArrayOf cells for the table body
cellsArrayOf strings
source-wrapTurns all content to a string for a file
nameStringName of file
titleStringTitle for top of file / header
subtitleStringSubtitle string (if any)
title-targetStringtarget name in text (may be same as top target)
metadataStringrendered metadata string
langStringThe language of the document (default 'en')
tocStringrendered TOC string
glossaryStringrendered glossary string
bodyStringrendered body string
footnotesStringrendered footnotes string
renderedtimeStringrendered time
pathStringpath to source file
page-configHashuser data given in first pod statement
footnotesrenders the notes structure to a string
notesArrayOf hash with the following keys
fnTargetStringtarget in the footnote area
textStringtext for the footnote
retTargetStringname for the anchor that the footnote will target
fnNumberStringThe footnote number as allocated by the renderer
glossaryrenders the glossary structure to string
glossaryArrayOf hash with keys
textStringtext to be displayed in glossary (aka index)
refsArrayOf hash with keys
(refs) targetStringtarget in text of one ref
(refs) placeStringdescription of place in text of one ref (most recent header)
tocRenders the TOC structure to a string
tocArrayOf hash with keys:
levelStringlevel of relevant header
targetStringtarget in text where header is
counterStringformatted counter corresponding to level
textStringtext of the header
metarenders the meta structure to a string that is then called metadata
metaArrayOf hash
nameStringName of meta data, eg. AUTHOR
valueStringValue of key

Helper templates in Pod::To::HTML2

KeyParameterCallsCalled-byDescription
camelia-imghead-blockReturns the string $camelia-svg
css-texthead-blockReturns the string $css-text
faviconhead-blockReturns the string $favicon-bin
imageRenders a Custom =Image Pod Block
srcthe src for the image
widthDefault width
heightDefault height
altDefault ALT text (when no image is loaded)
titlehead-blockHelper template to format title for text (title also used in header-block)
title
title-target
subtitlesource-wrapHelper template to format title for text
subtitle
head-blocksource-wrapForms the text for the 'head' section
title
metadata
csscss-textif 'css' is empty, it calls css-text
head
favicon
headersource-wraprenders the header section for the body
title
camelia-img
footersource-wraprenders the footer section for the body
pathpath to the source file
renderedtimetime the source was rendered

Notes

  • All blocks pass any extra config parameters to the template, eg., 'class', as well but if a developer passes configuration data to a block, she will be able to use it in the template.

  • The template does not need to render a parameter, but the template verification tool will issue a warning if it does not.

  • required templates are called by the Renderer, but it is cleaner to break the template into sections. The templates for Pod::To::HTML2 do this, with footer, header and head-block templates, all of which are called by file-wrap. This structure is shown in the table above.

Rendered from PodTemplates at 2022-06-13T16:49:51Z

Raku::Pod::Render v3.7.6

A generic Pod6 Renderer with custom Pod::Blocks, FormatCodes for one or more files using templates, provides HTML and MarkDown.

Authors

  • Richard Hainsworth

License

Artistic-2.0

Dependencies

Template::MustacheCro::WebApp::Template::Repository::HashCro::WebAppURILibCurlPod::LoadTest::Deeply::RelaxedFile::Directory::TreeTest::OutputFile::TempTest::METAPrettyDumpJSON::Fast

Test Dependencies

Provides

  • ExtractPod
  • InstallAtomHighlighter
  • Pod::To::HTML2
  • Pod::To::HTML2::Mustache
  • Pod::To::MarkDown
  • ProcessedPod
  • RenderPod::Exceptions
  • RenderPod::Highlighting
  • RenderPod::Templating
  • RenderPod::Test-Templates
  • raku-pod-render-install-highlighter
  • test-templates

The Camelia image is copyright 2009 by Larry Wall. "Raku" is trademark of the Yet Another Society. All rights reserved.