Stilo e-Publishing Solutions picture - clouds picture - clouds
dark blue bar dark blue bar dark blue bar
Stilo
TrainingSupportContact Us Stilo Home
OmniMark Developer Resources  
Stilo
Public
Stilo
Stilo
Login
defects reporting

Literate Programming Using OmniMark

Contents

2. Template Processing

Template processing is central to the weaving process, where we build a formatted document from the literate program. The template language devised for this project is quite simple: a template consists of boilerplate text, and template parameters, which are strings bracketed by [: and :].

Templates are emitted via the emit-template function:

<1 template processing> =
define string source function emit-template value string source template as using group "fill-in template parameters" submit template

In our case, all the templates are stored in the global string shelf templates:

<2 global shelves> =
global string templates variable elsewhere

As a result, the argument to emit-template could be a string instead of a string source. Template parameters are stored in the global string shelf template-parameters:

<2 global shelves> +=
global string template-parameters variable

The substitution of template parameter values into the template is handled by find rules:

<1 template processing> +=
group "fill-in template parameters" find "[:" any ++ => parameter-name ":]" (blank* "%n")? output template-parameters{parameter-name} when template-parameters has key parameter-name

A second form of template parameter, this time delimited by [? and ?] is used when a referent should be emitted rather than a value:

<1 template processing> +=
group "fill-in template parameters" find "[?" ("key:" | "name:") => p any ++ => parameter-name "?]" (blank* "%n")? output referent (p || template-parameters{parameter-name}) when template-parameters has key parameter-name

Although the shelf of templates is shown here, the actual values are discussed later, when they are needed.

<2 global shelves> +=
global string templates variable initial { <5 main page template> with key "main page", <10 section page template> with key "section page", <7 section list item template> with key "section list item", <18 template anonymous code> with key "anonymous code", <12 template code identified> with key "identified code", <14 template code identified appended> with key "identified code appended", "<filename>[:filename:]</filename><block-number>[:block number:]</block-number>" with key "code pointer", <20 template code reference> with key "code reference", "<[:element name:]>[:element content:]</[:element name:]>" with key "identity" }

OmniMark's save-clear operation allows for rudimentary scoping of template parameters:

<3 clear template parameters> =
save-clear template-parameters

This is sufficient for our needs.

Previous section: Introduction

Next section: Weaving

blue bar