NaturalDocs:: Builder:: HTMLBase

A base package for all the shared functionality in NaturalDocs::Builder::HTML and NaturalDocs::Builder::FramedHTML

All functions are called with Package->Function() notation. 

Summary
A base package for all the shared functionality in NaturalDocs::Builder::HTML and NaturalDocs::Builder::FramedHTML.
A hash of text equivalents of the Topic Types.
An existence hash of acceptable abbreviations.
An array of the headings of all the index sections.
An array of the HTML anchors of all the index sections.
These variables are for the menu generation functions only.
The current menu group number.
An array of the NaturalDocs::Menu::Entry objects of each group surrounding the selected menu item.
The length of the entire menu, fully expanded.
A hash of the length of each group, not including any subgroup contents.
A hash of the number of each group, as managed by menuGroupNumber.
Constants used to approximate the lengths of the menu or its groups.
The behavior of these functions is shared between HTML output formats.
Deletes the output files associated with the purged source files.
Deletes the output files associated with the purged source files.
Checks that the project’s CSS file is the same as the master CSS file, unless -s Custom is specified.
Builds and returns the HTML page title of a file.
Builds and returns the side menu of a file.
A recursive function to build a segment of the menu.
Builds and returns the main page content.
Builds a summary, either for the entire file or the current class/section.
Builds and returns the prototype as HTML.
Builds and returns the HTML footer for the page.
Builds and returns index’s content in HTML.
Returns a link in the index, complete with surrounding IEntry tags.
Builds an index file or files.
Builds a navigation bar for a page of the index.
Returns the JavaScript necessary to expand and collapse the menus.
Returns the JavaScript necessary to detect the browser.
Returns the JavaScript that will add opening browser styles if necessary.
Returns the JavaScript that will close browser styles if necessary.
Removes all or some of the output files for an index.
Returns the output file name of the source file.
Returns a relative path between two files in the output tree and returns it in URL format.
Converts a text string to HTML.
Converts a class and symbol to a HTML symbol, meaning one that is safe to include in anchor and link tags.
Converts a block of NDMarkup to HTML.
Creates a HTML link to a symbol, if it exists.
Creates a HTML link to an e-mail address.
Adds second spaces after the appropriate punctuation with   so they show up in HTML.
Converts certain characters to their HTML amp char equivalents.
Returns a hidden word break in HTML.
Adds hidden breaks to symbols.
A recursive function that finds and returns the first file entry in the menu.
Determines which groups should be expanded.

Variables

topicNames

my %topicNames

A hash of text equivalents of the Topic Types.  Makes output easier.  The keys are the tokens, and the values are their text equivalents. 

abbreviations

my %abbreviations

An existence hash of acceptable abbreviations.  These are words that AddDoubleSpaces() won’t put a second space after when followed by period-whitespace-capital letter.  Yes, this is seriously over-engineered. 

indexHeadings

my @indexHeadings

An array of the headings of all the index sections.  First is for symbols, second for numbers, and the rest for each letter. 

indexAnchors

my @indexAnchors

An array of the HTML anchors of all the index sections.  First is for symbols, second for numbers, and the rest for each letter. 

Menu Variables

These variables are for the menu generation functions only.  Since they’re needed in recursion, passing around references instead would just be a pain. 

menuGroupNumber

my $menuGroupNumber

The current menu group number.  Each time a group is created, this is incremented so that each one will be unique. 

menuSelectionHierarchy

my @menuSelectionHierarchy

An array of the NaturalDocs::Menu::Entry objects of each group surrounding the selected menu item.  First entry is the group immediately encompassing it, and each subsequent entries works its way towards the outermost group. 

menuLength

my $menuLength

The length of the entire menu, fully expanded.  The value is computed from the Menu Length Constants

menuGroupLengths

my %menuGroupLengths

A hash of the length of each group, not including any subgroup contents.  The keys are references to each groups’ NaturalDocs::Menu::Entry object, and the values are their lengths computed from the Menu Length Constants

menuGroupNumbers

my %menuGroupNumbers

A hash of the number of each group, as managed by menuGroupNumber.  The keys are references to each groups’ NaturalDocs::Menu::Entry object, and the values are the number. 

Menu Length Constants

Constants used to approximate the lengths of the menu or its groups. 

MENU_TITLELENGTHThe length of the title. 
MENU_SUBTITLELENGTHThe length of the subtitle. 
MENU_FILELENGTHThe length of one file entry. 
MENU_GROUPLENGTHThe length of one group entry. 
MENU_TEXTLENGTHThe length of one text entry. 
MENU_LINKLENGTHThe length of one link entry. 
MENU_LENGTHLIMITThe limit of the menu’s length.  If the total length surpasses this limit, groups that aren’t required to be open to show the selection will default to closed on browsers that support it. 

Implemented Interface Functions

The behavior of these functions is shared between HTML output formats. 

PurgeFiles

sub PurgeFiles

Deletes the output files associated with the purged source files. 

PurgeIndexes

sub PurgeIndexes #(indexes)

Deletes the output files associated with the purged source files. 

Parameters

indexesAn existence hashref of the index types to purge.  The keys are the Topic Types or * for the general index. 

EndBuild

sub EndBuild #(hasChanged)

Checks that the project’s CSS file is the same as the master CSS file, unless -s Custom is specified. 

Section Functions

BuildTitle

sub BuildTitle #(sourceFile)

Builds and returns the HTML page title of a file. 

Parameters

sourceFileThe source file to build the title of. 

Returns

The source file’s title in HTML. 

BuildMenu

sub BuildMenu #(outputFile,
isFramed)

Builds and returns the side menu of a file. 

Parameters

outputFileThe output file to build the menu for.  Does not have to be on the menu itself. 
isFramedWhether the menu will appear in a frame.  If so, it assumes the <base> HTML tag is set to make links go to the appropriate frame. 

Returns

The side menu in HTML. 

BuildMenuSegment

sub BuildMenuSegment #(outputFile,
isFramed,
menuSegment)

A recursive function to build a segment of the menu.  Remember to reset the Menu Variables before calling this for the first time. 

Parameters

outputFileThe output file the menu is being built for.  Does not have to be on the menu itself. 
isFramedWhether the menu will be in a HTML frame or not.  Assumes that if it is, the <base> HTML tag will be set so that links are directed to the proper frame. 
menuSegmentAn arrayref specifying the segment of the menu to build.  Either pass the menu itself or the contents of a group. 

Returns

The array ( menuHTML, hasSelection, length ). 

menuHTMLThe menu segment in HTML. 
hasSelectionWhether the group or any of its subgroups contains the entry for the selected file. 
groupLengthThe length of the group, not including the contents of any subgroups, as computed from the Menu Length Constants

BuildContent

sub BuildContent #(sourceFile,
parsedFile)

Builds and returns the main page content. 

Parameters

sourceFileThe source file name. 
parsedFileThe parsed source file as an arrayref of NaturalDocs::Parser::ParsedTopic objects. 

Returns

The page content in HTML. 

BuildSummary

sub BuildSummary #(sourceFile,
parsedFile,
index)

Builds a summary, either for the entire file or the current class/section. 

Parameters

sourceFileThe source file the summary appears in. 
parsedFileA reference to the parsed source file. 
indexThe index into the parsed file to start at.  If undef or zero, it builds a summary for the entire file.  If it’s the index of a class or section entry, it builds a summary for that class or section. 

Returns

The summary in HTML. 

BuildPrototype

sub BuildPrototype #(prototype)

Builds and returns the prototype as HTML. 

BuildFooter

sub BuildFooter

Builds and returns the HTML footer for the page. 

BuildIndexContent

sub BuildIndexContent #(index,
outputFile)

Builds and returns index’s content in HTML. 

Parameters

indexAn arrayref of NaturalDocs::SymbolTable::IndexElement objects. 
outputFileThe output file the index is going to be stored in. 

Returns

An arrayref of the index sections.  Index 0 is the symbols, index 1 is the numbers, and each following index is A through Z.  The content of each section is its HTML, or undef if there is nothing for that section. 

BuildIndexLink

sub BuildIndexLink #(name,
tag,
class,
showClass,
symbol,
file,
type,
prototype,
outputFile)

Returns a link in the index, complete with surrounding IEntry tags. 

Parameters

nameThe text to appear for the link. 
tagThe tag to apply to name.  For example, ISymbol
classThe class of the symbol, if any. 
showClassWhether the class name should be shown in parenthesis. 
symbolThe symbol to link to. 
fileThe source file the symbol appears in. 
typeThe type of the symbol.  One of the Topic Types
prototypeThe prototype of the symbol, if any. 
outputFileThe output file the link is appearing in. 

Returns

The link entry, including IEntry tags. 

BuildIndexFiles

sub BuildIndexFiles #(type,
indexContent,
beginPage,
endPage)

Builds an index file or files. 

Parameters

typeThe type the index is limited to, or undef for none.  Should be one of the Topic Types
indexContentAn arrayref containing the index content.  Each entry is a section; index 0 is symbols, index 1 is numbers, and following indexes represent A through Z. 
beginPageAll the content of the HTML page up to where the index content should appear. 
endPageAll the content of the HTML page past where the index should appear. 

Returns

The number of pages in the index. 

BuildIndexNavigationBar

sub BuildIndexNavigationBar #(type,
page,
locations)

Builds a navigation bar for a page of the index. 

Parameters

typeThe type of the index, or undef for general.  Should be one of the Topic Types
pageThe page of the index the navigation bar is for. 
locationsAn arrayref of the locations of each section.  Index 0 is for the symbols, index 1 for the numbers, and the rest for each letter.  The values are the page numbers where the sections are located. 

MenuToggleJavaScript

sub MenuToggleJavaScript

Returns the JavaScript necessary to expand and collapse the menus. 

BrowserStylesJavaScript

sub BrowserStylesJavaScript

Returns the JavaScript necessary to detect the browser. 

OpeningBrowserStyles

sub OpeningBrowserStyles

Returns the JavaScript that will add opening browser styles if necessary. 

ClosingBrowserStyles

sub ClosingBrowserStyles

Returns the JavaScript that will close browser styles if necessary. 

Support Functions

PurgeIndexFiles

sub PurgeIndexFiles #(type,
startingPage)

Removes all or some of the output files for an index. 

Parameters

typeThe index type, or undef for general.  Should be one of the Topic Types
startingPageIf defined, only pages starting with this number will be removed.  Otherwise all pages will be removed. 

OutputFileOf

sub OutputFileOf #(sourceFile)

Returns the output file name of the source file. 

MakeRelativeURL

sub MakeRelativeURL #(baseFile,
targetFile)

Returns a relative path between two files in the output tree and returns it in URL format. 

Parameters

baseFileThe base file in local format, not in URL format. 
targetFileThe target of the link in local format, not in URL format. 

Returns

The relative URL to the target. 

StringToHTML

sub StringToHTML #(string)

Converts a text string to HTML.  Does not apply paragraph tags or accept formatting tags. 

Parameters

stringThe string to convert. 

Returns

The string in HTML. 

SymbolToHTMLSymbol

sub SymbolToHTMLSymbol #(class,
symbol)

Converts a class and symbol to a HTML symbol, meaning one that is safe to include in anchor and link tags.  You don’t need to pass the result to ConvertAmpChars()

Parameters

classThe symbol’s class.  Set to undef if global. 
symbolThe symbol’s name. 

Returns

The HTML symbol string. 

NDMarkupToHTML

sub NDMarkupToHTML #(sourceFile,
text,
scope)

Converts a block of NDMarkup to HTML. 

Parameters

sourceFileThe source file the NDMarkup appears in. 
textThe NDMarkup text to convert. 
scopeThe scope the NDMarkup appears in. 

Returns

The text in HTML. 

MakeLink

sub MakeLink #(scope,
text,
sourceFile)

Creates a HTML link to a symbol, if it exists. 

Parameters

scopeThe scope the link appears in. 
textThe link text
sourceFileThe file the link appears in. 

Returns

The link in HTML, including tags.  If the link doesn’t resolve to anything, returns the HTML that should be substituted for it. 

MakeEMailLink

sub MakeEMailLink #(address)

Creates a HTML link to an e-mail address.  The address will be transparently munged to protect it (hopefully) from spambots. 

Parameters

addressThe e-mail address. 

Returns

The HTML e-mail link, complete with tags. 

AddDoubleSpaces

sub AddDoubleSpaces #(text)

Adds second spaces after the appropriate punctuation with &nbsp; so they show up in HTML.  They don’t occur if there isn’t at least one space after the punctuation, so things like class.member notation won’t be affected. 

Parameters

textThe text to convert. 

Returns

The text with double spaces as necessary. 

ConvertAmpChars

sub ConvertAmpChars #(text)

Converts certain characters to their HTML amp char equivalents. 

Parameters

textThe text to convert. 

Returns

The converted text. 

HiddenBreak

sub HiddenBreak

Returns a hidden word break in HTML.  Or more accurately, the best approximation of it I can make. 

AddHiddenBreaks

sub AddHiddenBreaks #(string)

Adds hidden breaks to symbols.  Puts them after symbol and directory separators so long names won’t screw up the layout. 

Parameters

stringThe string to break. 

Returns

The string with hidden breaks. 

FindFirstFile

sub FindFirstFile #(arrayref)

A recursive function that finds and returns the first file entry in the menu. 

Parameters

arrayrefThe array to search.  Set to NaturalDocs::Menu::Content()

ExpandMenu

sub ExpandMenu #(outputFile,
rootLength)

Determines which groups should be expanded. 

Parameters

outputFileThe file the menu is being built for.  Does not have to be on the menu itself. 
rootLengthThe length of the menu’s root group, not including the contents of subgroups. 

Returns

An arrayref of all the group numbers that should be expanded.  At minimum, it will contain the numbers of the groups present in menuSelectionHierarchy, though it may contain more.