tepam...c_gen(n)
πΈ NAME πΈ
okay bestie, gather round, this is tepam::doc_gen β the TEPAM DOC Generation reference manual π
β¨ and fr fr it's the whole thing, no skips, no cuts.
π SYNOPSIS π
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?
π¦ DESCRIPTION π¦
so this package generates documentation for TEPAM procedures β and by "TEPAM procedures" we mean the ones you declared with tepam::procedure, iykyk π«Ά. The docs come out in that classic UNIX document style, using these sections: Name, Synopsis, Description, Arguments and Example. TEPAM Doc Gen supports a bunch of document formats, and lowkey if you need more, extra formats can be added when necessary πβοΈ.
The TEPAM Doc Gen package gives you these commands:
tepam::doc_gen::generate ?-format format? ?-style style? ?-header_footer? ?-dest_file dest_file? nameβ this one generates the documentation for a specified procedure (name) in one of the supported formats (TXT, HTML, POD (Perl Doc), DT (TclLib DocTool), or a custom specific format of your own). The format goes informat. The flag-header_footeradds header and footer to the documentation file. Ifdest_fileis specified, the documentation is stored in a file β and yes, the file header and footer get added automatically in that case β and the file name is returned. Otherwise,generatereturns the documentation string instead. bestie, one of these two, not both π«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 one inserts procedure documentations into an existing master document, at the locations indicated by insertion placeholders that match the pattern ofsearch_pattern. The existing master document comes either as data via the argumentsrc_string, or via a filesrc_file. If no destination file is defined (dest_file),patchreturns the final document. Otherwise the document is stored in the specified file, and it returns the number of insertion placeholders that could be handled successfully π₯.
By default, any insertion placeholders of the master document get handled. But if you define the argument name, the documentation insertion gets restricted to a particular procedure. cute right?
π ARGUMENTS π
-format formatβ specifies the documentation format. TEPAM Doc Gen supports these formats:- TXT β Text format (default)
- HTML
- POD β Perl Plain Old Documentation format (PerlPOD)
- DT β TclLib DocTool format
The section ADDING SUPPORT FOR NEW DOCUMENT FORMATS shows how support for additional formats can be added π
-style styleβ documentation is by default generated in Tcl style (likecommand arg1 arg2 ...). You can get C-style documentation by setting this argument to'C'(likecommand(arg1,arg2,...)). pick your fighter π-dest_file dest_fileβ ifdest_fileis defined, the documentation gets 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. It's a mandatory argument forgenerate, but an optional argument forpatch. noted bestie π-header_footerβgenerateadds the file header and footer to the generated procedure documentation 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 a string bygenerateβ¨-src_string src_string | -src_file src_fileβpatchinserts procedure documentations into an existing document that is either provided as a string to the argumentsrc_stringor as a filesrc_file. One of these two arguments needs to be specified. no skipping, fr fr-search_pattern search_patternβ the argumentsearch_patterndefines the documentation insertion placeholder used in a document. It's a regular expression accepted byregexpand it 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 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) π
- Default:
π 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 π¨
- Default:
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_footerselected).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.
more coming bestie, don't go anywhere π
β¨ ADDING SUPPORT FOR NEW DOCUMENT FORMATS β¨
okay so bestie, you wanna teach doc_gen a whole new language? π
You totally can β you just define a little squad of procedures inside the tepam::doc_gen namespace, and each one of them is responsible for spitting out one specific piece of the document. That's it. That's the whole vibe. π«Ά
The listing down here is your map, fr fr β all those tokens point at the different 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>
πΈ The two flavors of doc generation procedures
There are 2 types, and honestly they're giving very different energies:
- Content generation procedures (like
<40s>...<40e>) β these ones build actual document content out of the text you hand them as an argument. See in the listing how each of these has two tokens? Yeah, that's the glow-up: one token marks where the generated content starts, the other marks where it ends. π - Control generation procedures (like
<03>) β these ones generate control constructs, like the prolog code and epilog code for lists, sections, whatever. And the iconic part? they take no argument at all. Zero. Nada. Main character behavior. π
π The procedure set you gotta define
To support a shiny new document format, you need this whole lineup. No skipping, bestie, they all matter:
01 - gen($Format,Header) {Text}β only gets called ifdoc_genis generating 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 that 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 (the preamble). π¦04 - gen($Format,End) {}β generates the documentation epilog.20 - gen($Format,SectionTitle) {Text}β generates a section title (thinkName,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 you need something separating them. The raw title text is the parameter.30 - gen($Format,Name) {Text}β generates the name section, without the title. The raw section text is the parameter.40 - gen($Format,Synopsis) {Text}β generates the synopsis section, without the title. The section text you get as parameter is already pre-formatted (the argument strings get generated bygen($Format,ArgumentString)).50 - gen($Format,Description) {Text}β generates a description paragraph. Raw paragraph text in, parameter style.51 - gen($Format,DescriptionListBegin) {}β generates the prolog of a bulleted/unordered list inside the description section. Usually this prolog is the start code of a list structure.52 - gen($Format,DescriptionListEnd) {}β generates the epilog of a bulleted/unordered list inside the description section. Usually the end code of a list structure.53 - gen($Format,DescriptionListItem) {Text}β generates a text item inside a bulleted/unordered description list. The raw item text is the parameter.54 - gen($Format,DescriptionSynopsis) {Text}β generates the synopsis line at the beginning of the description section. It's totally allowed to return an empty string if no synopsis line is wanted at that spot. π«Ά
Some formats (hi, Tcl DocTools π) require the synopsis line to live inside the description section, so they can then automatically build the synopsis section from it. The section text you get as parameter is pre-formatted (the argument strings come from gen($Format,ArgumentString)).
60 - gen($Format,ArgumentListBegin) {}β generates the prolog of the argument list (that's the definition/non-bulleted kind of list). Usually the start code of a definition list.61 - gen($Format,ArgumentListEnd) {}β generates the epilog of the argument list. 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. It's allowed to lean ongen($Format,ArgumentDetailBegin), since the parameters are literally identical. π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 (a single paragraph).66 - gen($Format,ArgumentAttribute) {Text}β generates a single argument attribute string. This one gets called individually for each attribute, so it's doing the most, one at a time. π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 inside the example section. Gets 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. Whatever string it generates has to show whether an argument is optional, named, and whether it's a flag. π§
These are the parameters it gets:
Nameβ name of the argument.IsOptionalβ if true (=1) the argument is optional, and the generated string should say so (for example by putting the argument into brackets{[]}or into question marks'?'):
gen(TXT,ArgumentString) mtype 1 0 string -> "[mtype]"
IsNamedβ if 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 yep, named arguments can be optional too:
gen(TXT,ArgumentString) mtype 1 1 string -> "[-mtype <mtype>]"
Typeβ tells you what type the argument is. If the type is set tonone, the argument is a flag, and the generated string has to indicate that. Example:
gen(TXT,ArgumentString) close 1 1 none -> "[-close]"
π TEPAM::DOC_GEN::GENERATE π
okay bestie, the cutest way to explore this whole package is literally to just... generate the docs for the command that generates docs. meta much? iconic. So:
This example spits out the documentation for tepam::doc_gen::generate in text format β which is the default format, no cap:
tepam::doc_gen::generate tepam::doc_gen::generate
And this one? HTML, because we're fancy now:
tepam::doc_gen::generate -format HTML tepam::doc_gen::generate
The flag ?header_footer? also adds the file header and footer, so the whole thing is wrapped up nice:
tepam::doc_gen::generate -format HTML -header_footer tepam::doc_gen::generate
You can send the documentation straight 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 points at a CSS stylesheet file (default: tepam_doc_stylesheet.css). For the HTML to actually look right, that stylesheet file has to be copied into the directory where your generated HTML file lives. Don't forget it or it's giving naked HTML energy. π
The Tcl DOC Tools format can also be used as an intermediate format to generate other formats β HTML, for example:
# 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. patch? way more flexibility, periodt. You can add multiple documentations for different procedures, plus meta information, all in one go. Obsessed.
The listing below shows how the patch command works. First it defines an HTML master document string that contains 2 procedure documentation placeholders ({*<ProcedureName>*}). Those placeholders get replaced by patch with the generated documentation of the procedures they refer to. And because these are nonstandard placeholders, patch is called with an explicit placeholder pattern definition β that's the search_pattern argument:
# 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(n)tepam::procedure(n)
π KEYWORDS π
automatic documentation, documentation, procedure documentation
π CATEGORY π
Documentation tools
π COPYRIGHT π
Copyright (c) 2013, Andreas Drollinger
and that's the whole page bestie, you ate it. π
This lil legend came out of tcllib, version 0.1.3, and it's filed under the very glamorous name tepam...c_gen(n). Go generate something gorgeous. π¦β¨
π¦ where this page comes from
- fedora 43: tcllib 2.0-3.fc43 Β· TCL
- fedora 44: tcllib 2.0-4.fc44 Β· TCL
- nixos 26.05: tcllib 2.0
- nixpkgs unstable: tcllib 2.0
- 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