metadoctool

Index Home MAE > MAE Architecture > MAE Utilities > metadoctool

Generates a formatted document from a metadocument and XML data.

Synopsis

metadoctool [-html|-xml] metacodefile hasharrayfile [fnfile]

Description

In the commhub ecosystem, metadoctool is a utility based upon the MetaDocument class. It is designed to take a metadocument and convert it into a formatted document. Presently, only HTML is supported on output. However, as computing trends change and other output formats become popular, metadoctool can be updated to output to those formats. It is a portability layer for formatted documents.

Metadoctool requires at least two input files – the metadocument (e.g. *.tpl) and an XML data file. Data from the XML file will be inserted into the formatted document as specified in the metadocument. A metadocument may contain metavariables/metafunctions; typically those are specified inside program code that the MetaDocument class externally calls, however when a metadocument is being created, it may be handy to specify values for those metavariables/metafunctions. For this, the third input may be optionally provided.

Options

Command

Action

-html

Convert the metacodefile into an HTML content (default).  Output is sent to stdout. CSS definitions are drawn from http://maeappsite.com/maedoc.css

-xml

Output the MetaDocument internal representation for the portable document as XML. This may be handy to understand the raw portable document before it is output as the formatted document.


Syntax of metacodefile

A metadocument (metacodefile) typically has the file suffix of .tpl and, by default, resides in /usr/mae/html/template. In practice, it may reside anywhere.

Each line of the metadocument is a command toward generating formatted output. Output text is grouped into blocks. A block may be a paragraph, section, table (a container of blocks), table cell, or similar. Parameters to commands are variables (extracted from XML), literals (strings, numbers), metavariables or metafunctions. Metavariables and functions both begin with $ followed by an identifier. A metafunction additionally has parenthesis with parameters.

Programmatically, blocks are achieved via indentation, like Python. The commands to execute for an if statement will follow it, but be indented. The next command with the same indentation as the if command (or less indentation) implicitly ends the if block.

A line beginning with a # is ignored as a comment line. Commands may have simple terms; there are no expressions like format programming languages; if expressions are needed, you likely need a formal programming language, not metadoctool.

Syntacitcal Parts of metadoctool Commands

Term Part

Description

style

A style is defined in a separate configuration file specific to the output format. For example, HTML output uses the CSS file http://maeappsite.com/maedoc.css, which defines the available styles. These styles are built in:

bold

make the text stand out

italic

italicize the text

underscore

display text underlined


text_term

A text term may be quoted text, a number, a field, or a metavariable/metafunction.

Quoted text

any text appearing between double quotes, e.g. “text”.

A number

a floating point number

A field

The name of an XML tag. This may be a top level value of the XML data provided. Or, if inside a with statement block, this may be from a level deeper into the XML. The the tag is an XML node (not a property), then the XML of that node is returned.

Metavariable

A metavariable starts with a “$” and is followed by an identifier, e.g. $name. Metavariables are either intrinsic or configured through an external application interface. For metadoctool, that external application interface pulls the value from the fnfile is specified on the command line. Intrinsic variables are:

$i, $j, $k, $l, $m, $n

This returns the current value being processed by a foreach command. $i is the value of the topmost foreach command, $j is the value of the 2nd topmost foreach command, etc.

$template

This returns the template name being processed (e.g. metacodefile specified on command line).

$toc

This generates a table of contents (using the headers defined in the document)

$1, $2, ... $n

This returns the parameter provided with the template. This is only available for the programming interface of MetaDocument; the metadoctool command does not support this.

pull nth CSV value from text_term, e.g. ${"this,that,other":3} returns "other"

pull value from text_term where text_term is a key-value array (very likely, text_term is a parameter field that was input as a HashArray or XML)

$fields

this returns the entire data input to the template – all the fields


Metafunction

A metafunction is a metavariable with function parameters. Note that there must not be any space between the metavariable and the open paranthesis, e.g. f(a, b, c). All metafunctions are passed to the external applicatrion with the provided parameters. Each parameter is expected to be a text_term. In metadoctool, the metafunction name is located in the fnfile specified on the command line. In that file (which contains metacode), the parameters are referenced via $1, $2, etc.


text_terms

One or more text_term values, separated by whitespace.

xpath

This is a path through the XML data provided. When used inside a with block, the path is tried from both the current level and the top of the XML data. An XML references each level as it descends into the data structure (the data inside the hasharrayfile command line file with each level separated by “/”. Note that when multiple records exist with the same name (like an array), the desired array offset (starting at 0) may be specified inside square brackets. For example: /record/person[4]. The path may be many levels deep.


Syntax of metadoctool Commands

Start Paragraph

Syntax: { [style]

An open curly bracket signals the beginning of a paragraph – a block of sentences/text. It may optionally be followed by a style name. The style will be applied across the paragraph. A style is defined in a separate configuration file specific to the output format. For example, HTML output uses the CSS file /maedoc.css, which defines the available styles.

End Paragraph

Syntax: }

An close curly bracket signals the end of a paragraph.

Start Document Section

Syntax: {{ section-type

Begin a document section. A paragraph and table or other block cannot cross a section boundary. A section is typically used for text that is like-wise similarly formatted, but different than other areas of the document. A default document implicitly has one section (1-column), but additional sections may be added. Valid section types are:

Style Type

Description

1-column

Page width will be a single column of text, like a letter or book.

2-column

Page width will contain 2 columns. Text will flow down left column, then continue at top of right column.

3-column

Page width will contain 3 columns. Text will flow down left column, then continue at top of middle column. After flowing down the middle column, it will continue at the top of the right column. This style is handy for lists of items that are short (shorter than 1/3 page width).


End Docuemnt Section

Syntax: }}

End a document section; return to the default document 1-column section type.

Document Headers

Syntax: h1 text_terms

Output a header line. Headers are indented/hierarchical with h1 being the top level, h2 below that, h3 below that, etc. down to h9. Note that h1 and H1 are both valid.

Output Text

Syntax: [write] text_terms [using style]

Output text into the flow of the document. Text may be quote text, a number, a field, or a metavariable/metafunction. See text_terms above. If the text should be output a particular way, specify the using term followed by the style (see style above.)

Begin a Table

Syntax: table name rows cols [fmt]

Create a table. A name must be provided so it may later be referenced. The size of the table in the rows and columns parameter. Note that more rows may be added to the table (see below). If the fmt parameter is specified, it may be left, right, or center, which aligns the table on the page as flush left, flush right, or balanced in the middle.

Syntax: [tablename](r,c) [using style] [command]

Move to a table cell and perform the command, if specified. A table cell is a block of flowing text; text written into a table cell is added to any text already written to that cell. The table name is optional; if specified, it refers to that table. When no table name is specified, the current table is used. The numbers inside the parenthesis refer to the row and column – specify numbers. A style for the cell may be specified with the using keyword.

Move to Column in Row

Syntax: (,c) [command]

Move to the specified column in the current row. The value of c must be a number.

Advance to Next Table Row

Syntax: (+,c) [command]

Move down a row and to column c. The value of c must be a number. When there is no additional row, another row is added. This is handy for adding rows when the size of the table is not known when the table is started. After moving to the new table cell, the command is processed, if specified.

Advance to Next Table Column

Syntax: (,+) [command]

Move right a column in the same row. When there is no additional column, it stays in the current cell.

Finish Table / Move to End of Table / Move to End of Document

Syntax: ()

When inside a table, this moves text flow to immediately after the table. When outside a table, this moves text flow to the end of the document.

Conditional Execution - if

Syntax: if text_term

If the text_term resolves to non-null text, then process the indented commands following the if line.

Conditional Execution - else

Syntax: else

When inside an if block, the commands inside the else block are processed when the if condition is false (null text). Strictly speaking, the else block is executed if the preceding if or else block was not processed.

Repeat Loop Through Values

Syntax: foreach text_term

Loops through the indendent commands following foreach for each value in the text_term. If the text is a CSV list, then each value in the list will be used for looping. Otherwise, only one iteration will be performed with the text provided. If no text is provided, the block or commands is not processed. Inside the foreach block, use the metavariable $i to reference the current value for the loop. For embedded foreach loops, use $j (1st nested block), $k (2nd nested block), etc. to $n.

Access more XML Values

Syntax: with xpath

Move into an XML structure so more fields can be referenced. If /people/person[3] references the 4th array element of the array of person records under people, then the properties of that array element are available as a field for text_term. This is like the Pascal with statement.

Repeat Loop Over XML Values

Syntax: witheach xpath

This command combines foreach and with - it processes an array of XML records, making each iterated record available as a field for term_text. If the XML data contains people which contains an array of person record, then "witheach people/person" will iterator over each person record.

Format of fncode file

The fncode file contains a list of metafunction names with their code blocks. For the metafunction, just specify the leading “$” followed by the function name. For example:

$Weapons

{

    write "Weapon Table Here"

}

See Also

wiki2doc