tep...gen(3tcl)
πΈ tep...gen(3tcl) β Tcl's Enhanced Procedure and Argument Manager πΈ
okay bestie, welcome to the manual page for tep...gen β aka Tcl's Enhanced Procedure and Argument Manager. this is the TEPAM Doc Gen reference manual, and it's giving documentation-generation main character energy. π
β¨ NAME β¨
tepam::doc_gen β TEPAM DOC Generation, reference manual
π SYNOPSIS π
okay so first, the vibe check on requirements and signatures:
package require Tcl 8.5 9
package require tepam 0.5
package require tepam::doc_gen ?0.1.3?
tepam::doc_gen::generate ?-format format? ?-style style?
?-header_footer? ?-dest_file dest_file? name
tepam::doc_gen::patch ?-format format? ?-style style? ?-search_pattern
search_pattern? ?-src_string src_string | -src_file src_file?
?-dest_file dest_file? ?name?
periodt. those are the exact spells you cast. β¨
π DESCRIPTION π
okay so this package generates documentations of TEPAM procedures β and when we say TEPAM procedures, we mean procedures that have been declared with tepam::procedure. The documents are generated in the classic UNIX document style using the following document sections: Name, Synopsis, Description, Arguments and Example. TEPAM Doc Gen provides support for various document formats. Support for additional formats can be added if necessary. no cap. π«Ά
The TEPAM Doc Gen package provides the following commands:
tepam::doc_gen::generate?-format format? ?-style style? ?-header_footer? ?-dest_file dest_file? nameβ This command generates the documentation for a specified procedure (name) in one of the supported formats (TXT, HTML, POD (Perl Doc), DT (TclLib DocTool), or in a custom specific format). The format is specified via?format?. The flag?-header_footer?adds to the documentation file header and footer. If?dest_file?is specified the documentation is stored in a file (the file header and footer are added automatically in this case) and the file name is returned. Otherwise the documentation string is returned bygenerate. πtepam::doc_gen::patch?-format format? ?-style style? ?-search_pattern search_pattern? ?-src_string src_string | -src_file src_file? ?-dest_file dest_file? ?name?β This command inserts procedure documentations into an existing master document at the locations indicated by insertion placeholders which are matching the pattern of?search_pattern?. The existing master document is either provided as data to the argument (?src_string?) or via a file (?src_file?). The final document is returned bypatchif no destination file is defined (?dest_file?). Otherwise, the document is stored in the specified file, and the number of insertion placeholders that could be handled successfully is returned.
Any insertion placeholders of the master document are handled by default. By defining the argument ?name? the documentation insertion will be restricted to a particular procedure. π¦
π ARGUMENTS π
here's the tea on every argument, bestie. don't skip a single one, fr fr:
?-format format?β Specifies the documentation format. TEPAM Doc Gen provides support for the following formats:TXT- Text format (default)HTMLPOD- Perl Plain Old Documentation format (PerlPOD)DT- TclLib DocTool format
Section ADDING SUPPORT FOR NEW DOCUMENT FORMATS shows how support for additional formats can be added.
?-style style?β The documentation is by default generated in Tcl style (e.g.command arg1 arg2 ...). C-style documentation can be generated by setting this argument to'C'(e.g.command(arg1,arg2,...)).?-dest_file dest_file?β If?dest_file?is defined the documentation is written into the specified destination file. Otherwise the documentation string is returned by the commandsgenerateandpatch.name/?name?β This is the name of the procedure for which the documentation has to be generated. This is a mandatory argument forgenerate, but an optional argument forpatch.?-header_footer?βgenerateadds to the generated procedure documentation the file header and footer only if a file is generated. By selecting the flag?-header_footer?the header and footer are also generated if the documentation is returned as string bygenerate.?-src_string src_string | -src_file src_file?βpatchinserts procedure documentations into an existing document that is either provided as string to the argument (?src_string?) or as a file (?src_file?). One of these two arguments need to be specified.?-search_pattern search_pattern?β The argument?search_pattern?defines the documentation insertion placeholder used in a document. It is a regular expression accepted byregexpand needs to contain a parenthesized sub-expression that contains the procedure name for which the documentation needs to be inserted.
The default insertion placeholder pattern is \{!(.*?)!\}, which means that the procedure name will be embedded between {! and !}. The section EXAMPLES contains a custom insertion placeholder pattern example.
π PREDEFINED DOCUMENT FORMATS π
TEPAM Doc Gen pre-defines the following document formats:
π TXT - TEXT FORMAT
The documentation will be generated in a simple text format if this format is selected. The format can be customized via the following variable:
tepam::doc_gen::Option(TXT,MaxLineLength)
Default: 80
This variable defines the line wrapping limit (character position).
π HTML - HTML FORMAT
TEPAM Doc Gen generates CSS styled HTML files. The HTML documentation can be customized via the following variable:
tepam::doc_gen::Option(HTML,CssFile)
Default: "tepam_doc_stylesheet.css"
This variable specifies the CSS stylesheet file that is referred by the generated HTML files.
The CSS stylesheet can be customized to change the documentation formatting. A good starting point to create a customized CSS stylesheet is to use the CSS file provided by the TEPAM Doc Gen example/demo. The HTML documentation uses the following CSS class styles:
h1.tepam_page_title- Document page title. Only used bygenerateif a file is created or if the header and footer are built (flag?-header_footer?selected).div.tepam_command_help- Documentation container. The entire procedure documentation is placed inside this container.p.tepam_section_title- Section title (e.g. Name, Synopsis, Description, ...)p.tepam_sub_section_title- Sub-section title (used to separate the documentation of multiple sub-procedures)p.tepam_name- Name sectionp.tepam_synopsis- Synopsis sectionp.tepam_description- Single description paragraphul.tepam_description_list- Item of a HTML bulleted/unordered list inside the description sectiondt.tepam_argument- Item of a HTML description list used to list the procedure argumentsp.tepam_argument_description- Argument description paragraphp.tepam_argument_attribute- Argument attribute linepre.tepam_example- Example section
πͺ POD - PERL DOCUMENT FORMAT
The documentation is generated in the Perl Plain Old Documentation format (PerlPOD) if this format is selected.
π§° DT - TCLLIB DOCTOOLS FORMAT
The documentation is generated in the Tcllib DocTools format if this format is selected.
π¦ ADDING SUPPORT FOR NEW DOCUMENT FORMATS π¦
okay bestie, so you wanna teach tepam a brand new document format? iconic. all you gotta do is define a lil family of procedures inside the tepam::doc_gen namespace, and those procedures will generate the different document components. that's it, that's the whole vibe π
this next listing is like the master map β every token in here points at one of the document generation procedures:
<01>
<03> <20s> NAME<20e>
<30s> message_box - Displays text in a message box<30e>
<20s> SYNOPSYS<20e>
<40s> message_box [-mtype <mtype>] <text><40e>
<20s> DESCRIPTION<20e>
<21s> message_box<21e>
<54s> message_box [-mtype <mtype>] <text><54e>
<50s> This procedure allows displaying a text in an message box. The following
message types are supported:<50e>
<51> <53s> * Info<53e>
<53s> * Warning<53e>
<53s> * Error<53e> <52>
<50s> If the text parameter is use multiple times the different texts are
concatenated to create the message text.<50e>
<20s> ARGUMENTS<20e>
<60> <62s> [-mtype <mtype>]<62e>
<63> <65s> Message type<65e>
<66s> Default: "Warning"<66e>
<66s> Multiple: yes<66e>
<66s> Choices: Info, Warning, Error<66e> <64>
<62s> <text><62e>
<63> <65s> One or multiple text lines to display<65e>
<66s> Type: string<66e>
<66s> Multiple: yes<66e> <64><61>
<20s> EXAMPLE<20e>
<70> <72s> message_box "Please save first the document"<72e>
<73s> -> 1<73e> <71><04>
<02>
so there's 2 types of document generation procedures, and you gotta know the difference, fr fr:
- Content generation procedures (like
<40s>...<40e>) β these ones spit out actual document content based on the text you hand them as an argument. and see how the listing above shows two tokens for them? that's to mark the beginning and the end of the generated content. cute, right? π - Control generation procedures (like
<03>) β these generate control constructs, like the prolog code and epilog code for lists, sections, whatever. and guess what, they take no argument at all. low maintenance queens π
πΈ the procedure set you gotta define πΈ
here's the full roster that needs to exist to support a new document format. no skipping, bestie, all of them:
01βgen($Format,Header) {Text}β only gets called ifdoc_gengenerates a file, or if it's called with the flag?-header_footer?. it creates the file header. the parameter it gets is the procedure name the documentation is being generated for.02βgen($Format,Footer) {Text}β same deal, only called ifdoc_gengenerates a file or if it's called with the flag?-header_footer?. it creates the file footer.03βgen($Format,Begin) {}β generates the documentation prolog (a.k.a. the preamble).04βgen($Format,End) {}β generates the documentation epilog.20βgen($Format,SectionTitle) {Text}β generates a section title (like Name, Synopsis, Description, ...). the raw title text comes in as the parameter.21βgen($Format,SubSectionTitle) {Text}β generates a sub-section title. sub-sections come into play when a single documentation is generated for multiple sub-commands, so there's a separation between them. the raw title text comes in as the parameter.30βgen($Format,Name) {Text}β generates the name section (no title). the raw section text comes in as the parameter.40βgen($Format,Synopsis) {Text}β generates the synopsis section (no title). the section text you get as parameter is pre-formatted (the argument strings are generated bygen($Format,ArgumentString)).50βgen($Format,Description) {Text}β generates a description paragraph. the raw paragraph text comes in as the parameter.51βgen($Format,DescriptionListBegin) {}β generates the prolog of a bulleted/unordered list inside the description section. this prolog is usually the start code of a list structure.52βgen($Format,DescriptionListEnd) {}β generates the epilog of a bulleted/unordered list inside the description section. this epilog is usually the end code of a list structure.53βgen($Format,DescriptionListItem) {Text}β generates a text item in a bulleted/unordered description list. the raw item text comes in as the parameter.54βgen($Format,DescriptionSynopsis) {Text}β generates the synopsis line at the beginning of the description section. the command can totally return an empty string if no synopsys line is needed in that spot.
some formats (hi Tcl DocTools π) require that the synopsis line is defined in the description section, so they can then automatically build the synopsis section. the section text you get as parameter is pre-formatted (the argument strings are generated by gen($Format,ArgumentString)).
60βgen($Format,ArgumentListBegin) {}β generates the prolog of an argument list (definition/non-bulleted list). this prolog is usually the start code of a definition list.61βgen($Format,ArgumentListEnd) {}β generates the epilog of the argument list. this epilog is usually the end string of a list structure.62βgen($Format,ArgumentListItem) {Name IsOptional IsNamed Type}β generates an argument item line inside the argument list. this command can lean ongen($Format,ArgumentDetailBegin)because the parameters are identical. twin behavior, slay π63βgen($Format,ArgumentDetailBegin) {}β generates the argument details prolog (preamble).64βgen($Format,ArgumentDetailEnd) {}β generates the argument details epilog.65βgen($Format,ArgumentDescription) {Text}β generates the argument description (single paragraph).66βgen($Format,ArgumentAttribute) {Text}β generates a single argument attribute string. this command gets called individually for each attribute.70βgen($Format,ExampleBegin) {}β generates the example section prolog (preamble).71βgen($Format,ExampleEnd) {}β generates the example section epilog.72βgen($Format,ExampleCommandLine) {Text}β generates a single command line in the example section. this command is called for each individual command line.73βgen($Format,ExampleResultLine) {Text}β generates a command result line.80βgen($Format,ArgumentString) {Name IsOptional IsNamed Type}β generates the part of the command line (or the synopsis) that's specific to one argument. the generated string has to show whether an argument is optional, named, and whether it's a flag.
π§ the gen($Format,ArgumentString) parameters π§
here's what gets handed to that procedure, one by one:
- Name β the name of the argument. obviously π
- IsOptional β if it's true (
=1) the argument is optional, and the generated string should show that (for example by putting the argument into brackets{[]}or into question marks'?'):
gen(TXT,ArgumentString) mtype 1 0 string -> "[mtype]"
- IsNamed β if it's true (
=1) the argument is a named argument (an option). in that case the generated string should contain the argument/option name, followed by the argument itself:
gen(TXT,ArgumentString) mtype 0 1 string -> "-mtype <mtype>"
and named arguments can also be optional, bestie:
gen(TXT,ArgumentString) mtype 1 1 string -> "[-mtype <mtype>]"
- Type β tells you the type of the argument. if the type is set to
none, the argument is a flag, and the generated string needs to show that. example:
gen(TXT,ArgumentString) close 1 1 none -> "[-close]"
β¨ EXAMPLES β¨
Okay bestie, this is the part where it gets fun β actual working examples, we love to see it π
πΈ TEPAM::DOC_GEN::GENERATE πΈ
The cutest way to explore the TEPAM Doc Gen package is literally just to generate the documentation of tepam::doc_gen::generate itself. Meta, right? Iconic behaviour honestly.
This first one spits out the doc in text format (which is the default format, no cap):
tepam::doc_gen::generate tepam::doc_gen::generate
And this one goes full glow-up and gives you HTML instead:
tepam::doc_gen::generate -format HTML tepam::doc_gen::generate
The flag ?header_footer? also throws in the file header and the footer, like accessories for your doc:
tepam::doc_gen::generate -format HTML -header_footer tepam::doc_gen::generate
Now β the documentation can be stored directly into a file too π. And when you do that, the file header and footer get generated automatically, no extra work from you:
tepam::doc_gen::generate -format HTML -dest_file doc_gen.html tepam::doc_gen::generate
Heads up bestie β οΈ β the generated HTML file refers to a CSS stylesheet file (default: tepam_doc_stylesheet.css). If you want that HTML to actually display correctly, you need to copy the CSS stylesheet into the directory of the generated HTML file. Otherwise it's giving unstyled chaos π
The Tcl DOC Tools format can be used as an intermediate format to generate other formats β HTML, for example. It's a whole pipeline, and it's lowkey genius:
# Generate the documentation in Tcl Doc Tool format
set dt [tepam::doc_gen::generate -format DT -header_footer tepam::doc_gen::generate]
# Create a new doc tools object (HTML format)
package require doctools
::doctools::new myDoc -format html
# Open the HTML file, and write the HTML formatted documentation
set fHtml [open doc_gen.dt.html w]
puts $fHtml [myDoc format $dt]
close $fHtml
π¦ TEPAM::DOC_GEN::PATCH π¦
So generate gives you a limited number of ways to vary the document structure, right? But patch? patch is the flexible one π
. Multiple documentations for different procedures plus meta information can be added, for example.
Here's how the patch command does its thing. It first defines a HTML master document string that contains 2 procedure documentation placeholders β those are {*<ProcedureName>*}. Then patch swaps those placeholders out with the generated documentation of the referred procedures. And since these are nonstandard placeholders, patch gets called with an explicit placeholder pattern definition (that's the argument search_pattern):
# Define the HTML master document
set HtmlMasterDoc {\
<html>
<head>
<title>tepam::doc_gen</title>
<link rel="stylesheet" href="tepam_doc_stylesheet.css">
<meta content="documentation" name="keywords"></meta>
</head>
<body>
<h1>tepam::doc_gen</h1>
<h2>Generate</h2>
{*tepam::doc_gen::generate*}
<h2>Patch</h2>
{*tepam::doc_gen::patch*}
</body>
<html>\
}
# Patch the master document: This will replace the placeholders by the
# procedure documentation divisions:
tepam::doc_gen::patch -format HTML -search_pattern {\{\*(.*?)\*\}} \
-src_string $HtmlMasterDoc -dest_file tepam_doc_gen.html
π SEE ALSO π
tepam(3tcl)tepam::procedure(3tcl)
π KEYWORDS π
- automatic documentation
- documentation
- procedure documentation
π·οΈ CATEGORY π·οΈ
Documentation tools β yes, that's the whole category, and it ate β¨
Β©οΈ COPYRIGHT Β©οΈ
Copyright (c) 2013, Andreas Drollinger
And that's a wrap on tep...gen(3tcl), bestie π«Άπ Go forth and document everything, you've got this. This page is from tcllib, version 0.1.3 β periodt π
β¨
π¦ where this page comes from
- debian trixie: tcllib 2.0+dfsg-4 Β· Tcl
- ubuntu questing: tcllib 2.0+dfsg-4
- ubuntu resolute: tcllib 2.0+dfsg-5 Β· Tcl
- ubuntu stonking: tcllib 2.0+dfsg-6 Β· Tcl
- Copyright (c) 2013, Andreas Drollinger
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms