Parse:...t::HTML(3pm)
β¨ NAME β¨
Parse::Dia::SQL::Output::HTML β bestie, this module literally exists to create HTML documentation. That's it, that's the whole job. π
It lives in the Perl manual pages, section 3pm, and honestly? She's a whole vibe. π
π¦ SYNOPSIS π¦
use Parse::Dia::SQL;
my $dia = Parse::Dia::SQL->new(
file => 'foo.dia',
db => 'html' [ , htmlformat => {formatfile} ]
);
print $dia->get_sql();
πΈ DESCRIPTION πΈ
okay so. This sub-class creates HTML formatted database documentation. That's her main character moment. π
The HTML formatting is controlled by templates, and you pick those with the optional htmlformat parameter β that one hands over a format file. Peep "HTML formats" below for the whole tea. π«
Real talk though: the generated HTML is meant to be useful rather than beautiful. It's giving "functional, not a glow-up." No cap.
This sub-class follows the exact same structure as the rdbms output sub-classes, and the whole point of that is keeping things consistent β even though ngl, this gives less than optimum efficiency. Consistency ate, efficiency didn't. π
π§ new π§
The constructor. The setup. The "let me introduce myself" moment. β¨
Object names in HTML have no inherent limit. The number 64 was just arbitrarily chosen. Like, no deep lore, someone just picked it. π
π get_sql π
Returns all sql documentation. Periodt.
First, she builds the data structures:
schema create
view create
permissions create
inserts
associations create (indices first, then foreign keys)
Then she generates the output:
html start
html comments
body start
generate main html
body end
html end
π _get_preamble π
HTML Header. That's the whole thing, bestie.
π _get_comment π
Comment for HTML Header.
π get_smallpackage_pre_sql π
HTML Body start.
π get_smallpackage_post_sql π
HTML Body close.
π _get_postscript π
HTML close.
π¦ _get_create_table_sql π¦
Extracts the documentation details for a single table. One table, all the deets.
π get_schema_drop π
Do nothing. She's not doing anything here. Nothing. Zero. Resting. π
π get_view_drop π
Do nothing. Same energy.
π _get_fk_drop π
Do nothing. Still nothing.
π _get_drop_index_sql π
Do nothing. Iconic behaviour, honestly.
π get_permissions_create π
Permissions get formatted as "{type} {name} to {list of roles}", and here's what each lil piece means:
- "type" is the operation β
"GRANT","REVOKE"etc. - "name" is the permission name β
"SELECT","INSERT"etc. - "list of roles" is the set of datbase roles affected. (yes, "datbase" β she said what she said π)
β οΈ Warning: Permissions are at best lightly tested (ie potentially buggy). Bestie, tread carefully. π¨
π get_permissions_drop π
Do nothing. Again. We love a low-effort queen.
π _get_create_association_sql π
Extracts the documentation for table relationships. It's giving connection. π«Ά
π _get_create_index_sql π
Extracts the documentation for table indices.
β generate_html β
Do the output. She does the output. That's the job. β¨
π§ set_html_template π§
Sets up the formatting template.
Template elements use "{placeholders}" to identify how the document should be built. Like little fill-in-the-blanks but make it documentation. π
πΈ HTML Formats πΈ
The default format may be all you need, fr fr. But if you want different HTML formats for different uses, then bestie, make a format file β you define template elements between "{def:element}" and "{/def:element}" markers. π
And here's the slay part: you only need to define the elements you want to be different from the defaults. Nothing more. π
Any text outside the "{def:element}" and "{/def:element}" is ignored, so you can drop comments in there without it affecting the output at all. Free real estate for your thoughts. π
Any "\n" literals in the format file get replaced with newlines. And yeah, newlines in generated HTML typically have no effect on the layout β but they can make the output easier for humans to read, and honestly, we do it for the humans. π«Ά
β¨ Template elements β¨
π htmlpreamble π
The start of the html document.
Placeholders: filename
Default:
<html><head>\n<title>Database documentation: {filename}</title>
π htmlcomment π
A generated comment at the start of the html document. This is the standard comment at the start of the SQL script.
Placeholders: htmlcomment
Default:
\n<!-- {htmlcomment} -->\n
π htmlstartbody π
The start body html tag.
Default: </head><body>
π htmlendbody π
The end body html tag.
Placeholders: gentime
Default: <p style="font-size:75%">Generated at {gentime}.</p>
π htmlend π
The end html tag.
Default: </html>
π¦ tablelist π¦
The bit at the top of the page which lists all the tables. Each one is formatted with "tablelistitem", separated by "tablelistsep".
Placeholders: tablelist (the assembled list of table), filename
Default:
<h1>Data Dictionary for {filename}</h1>
<h2\>List of Tables</h2>
{tablelist}
<hr width='80%'/>
π¦ tablelistitem π¦
An individual element (table) in the table list.
Placeholders: tablename, tablecomment
Default: <a href='#{tablename}'>{tablename}</a>
π¦ tablelistsep π¦
Separator between individual elements in the table list.
Default: ", "
π tablestart π
Introduction to the table details.
Default: <h2>Table details</h2>
π table π
Details of one table.
Placeholders: tablename, comment, refto, refby, tablerowdata, autoupdate, indices, permissions.
Default:
<h3>Table: {tablename}<a name='{tablename}'/></h3>
{comment}
{refto}
{refby}
<table border='1' cellspacing='0' cellpadding='1'>
<tr><td>Field</td><td>Type</td><td>Default</td><td>Description</td></tr>
{tablerowdata}
</table>
{autoupdate}
{indices}
{permissions}
<hr width='80%'/>
π tablekeyrow, tablerow π
Details of an individual field (column) from the (table) in the table detail.
tablekeyrow is used for primary key fields, tablerow for other fields.
Placeholders: name, type, default, comment.
Default tablekeyrow:
<tr><td><b>{name}</b></td><td>{type}</td><td>{default}</td><td>{comment}</td></tr>
Default tablerow:
<tr><td>{name}</td><td>{type}</td><td>{default}</td><td>{comment}</td></tr>
π tablecomment π
Table comments/description.
Placeholders: comment
Default: <p>{comment}</p>
π tablecommentlist π
Table comments/description in a list context.
Placeholders: comment
Default: {comment}
β autoupdate β
Auto update code, if used.
Placeholders: autoupdate
Default: <p>Automatically set:{autoupdate}</p>
β refby, refto β
refby β References by β a list of tables that refer to this one via foreign keys.
refto β References to β a list of tables to which this table refers via foreign keys.
π¨ The whole section is omitted if there are no references β and yes, that includes any static text. Gone. Poof. π¨
Placeholders: refbylist, reftolist respectively.
Default refby: <p>Referenced by: {refbylist}</p>
Default refto: <p>References: {reftolist}</p>
β refbyitem, reftoitem β
A single item in the reference by list.
Placeholders: tablename, key, fk, action, refname
Here tablename is the other table, key is the field in this table, fk is the field in the other table, action is the action on update/delete (such as cascade or update) and refname is the name of the constraint.
Default: <a href='#{tablename}'>{tablename}</a>
β refbysep, reftosep β
Separator between references.
Default: ", "
π indices π
List of indices on this tables.
π¨ The whole section is omitted if there are no indices β again, including any static text. Nothing survives. π
Placeholders: indexlist
Default: <h4>Indices</h4><p>{indexlist}</p>
π indexitem π
A single item in the index list.
Placeholders: tablename, columns, comment, type, indexname
Here tablename is the indexed (ie current) table, columns is the set of columns in the index, comment is the index comment if any, type is 'unique' (or blank) and indexname is the name of the index.
Default: {indexname}: {type} on {columns} {comment}
π indexsep π
Separator between indices.
Default: "<br\>"
π permission π
A list of permissions granted on this table.
Placeholders: permissionlist
Default: <h4>Permissions</h4><p>{permissionlist}</p>
π permissionitem π
A single permission in the list.
Placeholders: permission
Default: {permission}
π permissionsep π
Separator between permissions.
Default: <br/>
π«Ά fieldblank π«Ά
Replacement character(s) for blank values. Default value is empty.
π Sample format file π
This format file generates vertical lists of tables and references rather than single paragraph, comma separated lists (which is the default).
{def:tablelist}
<h1>List of Tables</h1>
<table border='1' cellspacing='0' cellpadding='2'>
<tr><td><b>Name</b></td><td><b>Description</b></td></tr>
{tablelist}
</table>
<hr width='80%'/>
{/def:tablelist}
{def:tablelistitem}<tr><td><a href='#{tablename}'>{tablename}</a></td><td>{tablecomment}</td></tr> {/def:tablelistitem}
{def:tablelistsep}\n{/def:tablelistsep}
{def:refby}<p><b>Referenced by:</b> <br/>{refbylist}</p>{/def:refby}
{def:refbyitem}{fk}=<a href='#{tablename}'>{tablename}</a>.{key} {action}{/def:refbyitem}
{def:refbysep} <br/>{/def:refbysep}
{def:refto}<p><b>References:</b> <br/>{reftolist}</p>{/def:refto}
{def:reftoitem} {fk}=<a href='#{tablename}'>{tablename}</a>.{key} {action}{/def:reftoitem}
{def:reftosep}<br/>{/def:reftosep}
# Comments don't matter
{def:permission}<h4>Permissions</h4><p>{permissionlist}</p>{/def:permission}
{def:permissionitem}{permission}{/def:permissionitem}
{def:permissionsep}<br/>{/def:permissionsep}
Note that comments or other text outside the {def:} The other template elements are the same as the default.
(yes bestie, that sentence is just like that in the source. We keep the lore accurate. π)
π¦ TODO π¦
Things that might get added in future versions:
- Views are not currently documented.
- Bugs etc
and that's the whole page, bestie!! πβ¨
This one came from the Perl manual pages, perl v5.36.0, dated 2022-11-19 β that's the source and the date, mwah, no notes. π«Άππ
π¦ where this page comes from
- debian bookworm: libparse-dia-sql-perl 0.31-2 Β· GPL-2.0-or-later
- debian trixie: libparse-dia-sql-perl 0.31-2 Β· GPL-2.0-or-later
- ubuntu noble: libparse-dia-sql-perl 0.31-2 Β· GPL-2.0-or-later
- ubuntu resolute: libparse-dia-sql-perl 0.31-2 Β· GPL-2.0-or-later
- ubuntu stonking: libparse-dia-sql-perl 0.31-2 Β· GPL-2.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms