From cbe2bf359f3e20d1856d9ffb63b93de56446ae42 Mon Sep 17 00:00:00 2001 From: michael Date: Sat, 31 May 2008 21:18:12 +0000 Subject: [PATCH] * Added index page generation to html engine git-svn-id: trunk@11145 - --- utils/fpdoc/dglobals.pp | 7 +- utils/fpdoc/dw_html.pp | 214 ++++++++++++++++++++++++++++++++++++++-- 2 files changed, 212 insertions(+), 9 deletions(-) diff --git a/utils/fpdoc/dglobals.pp b/utils/fpdoc/dglobals.pp index 9e4f9340e5..ec6db9b0e9 100644 --- a/utils/fpdoc/dglobals.pp +++ b/utils/fpdoc/dglobals.pp @@ -46,7 +46,9 @@ resourcestring SDocClasses = 'Classes'; SDocProceduresAndFunctions = 'Procedures and functions'; SDocVariables = 'Variables'; - + SDocIdentifierIndex = 'Index'; + SDocModuleIndex = 'Index of all identifiers in unit ''%s'''; + SDocPackageIndex = 'Index of all identifiers in package ''%s'''; SDocUnitOverview = 'Overview of unit ''%s'''; SDocOverview = 'Overview'; SDocSearch = 'Search'; @@ -101,6 +103,9 @@ resourcestring // HTML usage SHTMLUsageFooter = 'Append xhtml from file as footer to html page'; SHTMLUsageFooterDate = 'Append footer with date. fmt is Optional format for FormatDateTime'; + SHTMLUsageCharset = 'Set the HTML character set'; + SHTMLHtmlSearch = 'Add search page with given name to the menu bar'; + SHTMLIndexColcount = 'Use N columns in the identifier index pages'; // CHM usage SCHMUsageTOC = 'Use [File] as the table of contents. Usually a .hhc file.'; diff --git a/utils/fpdoc/dw_html.pp b/utils/fpdoc/dw_html.pp index b98a29f9a5..4202e5e1b2 100644 --- a/utils/fpdoc/dw_html.pp +++ b/utils/fpdoc/dw_html.pp @@ -31,6 +31,7 @@ const VarsSubindex = 6; // Maybe needed later for topic overview ?? TopicsSubIndex = 7; + IndexSubIndex = 8; // Subpage indices for classes PropertiesByInheritanceSubindex = 1; @@ -107,6 +108,8 @@ type FooterFile: string; FIDF : Boolean; FDateFormat: String; + FIndexColCount : Integer; + FSearchPage : String; function ResolveLinkID(const Name: String): DOMString; function ResolveLinkIDInUnit(const Name,UnitName: String): DOMString; function ResolveLinkWithinPackage(AElement: TPasElement; @@ -213,9 +216,12 @@ type Procedure AppendSeeAlsoSection(AElement : TPasElement;DocNode : TDocNode); Procedure AppendExampleSection(AElement : TPasElement;DocNode : TDocNode); procedure AppendFooter; - + procedure CreateIndexPage(L : TStringList); + procedure CreateModuleIndexPage(AModule: TPasModule); procedure CreatePageBody(AElement: TPasElement; ASubpageIndex: Integer); virtual; procedure CreatePackagePageBody; + procedure CreatePackageIndex; + procedure AddModuleIdentifiers(AModule : TPasModule; L : TStrings); Procedure CreateTopicPageBody(AElement : TTopicElement); procedure CreateModulePageBody(AModule: TPasModule; ASubpageIndex: Integer); procedure CreateConstPageBody(AConst: TPasConst); @@ -239,7 +245,10 @@ type procedure WriteHTMLPages; virtual; procedure WriteXHTMLPages; - SearchPage: String; + Function InterPretOption(Const Cmd,Arg : String) : boolean; override; + Procedure WriteDoc; override; + class procedure Usage(List: TStrings); override; + Property SearchPage: String Read FSearchPage Write FSearchPage; property Allocator: TFileAllocator read FAllocator; property Package: TPasPackage read FPackage; property PageCount: Integer read GetPageCount; @@ -247,9 +256,7 @@ type Property DateFormat : String Read FDateFormat Write FDateFormat; property OnTest: TNotifyEvent read FOnTest write SetOnTest; Property CharSet : String Read FCharSet Write FCharSet; - Function InterPretOption(Const Cmd,Arg : String) : boolean; override; - Procedure WriteDoc; override; - class procedure Usage(List: TStrings); override; + Property IndexColCount : Integer Read FIndexColCount write FIndexColCount; end; THTMWriter = class(THTMLWriter) @@ -493,6 +500,7 @@ constructor THTMLWriter.Create(APackage: TPasPackage; AEngine: TFPDocEngine); DidAutolink: Boolean; begin AddPage(AModule, 0); + AddPage(AModule,IndexSubIndex); AddTopicPages(AModule); with AModule do begin @@ -574,6 +582,7 @@ var i: Integer; begin inherited ; + IndexColCount:=3; Charset:='iso-8859-1'; CreateAllocator; FPackage := APackage; @@ -585,6 +594,7 @@ begin if Length(Package.Name) > 1 then begin AddPage(Package, 0); + AddPage(Package,IndexSubIndex); AddTopicPages(Package); end; @@ -1815,7 +1825,7 @@ begin ParaEl := CreateEl(CreateTD(TREl), 'b'); if Assigned(Module) then - begin + begin AddLink(0, SDocOverview); if Module.InterfaceSection.ResStrings.Count > 0 then AddLink(ResstrSubindex, SDocResStrings); @@ -1829,7 +1839,20 @@ begin AddLink(ProcsSubindex, SDocProceduresAndFunctions); if Module.InterfaceSection.Variables.Count > 0 then AddLink(VarsSubindex, SDocVariables); - end; + AddLink(IndexSubIndex,SDocIdentifierIndex); + end + else + begin + // Manually add link for package page + AppendText(ParaEl, '['); + if (IndexSubIndex = ASubpageIndex) then + AppendText(ParaEl, SDocIdentifierIndex) + else + AppendText( + CreateLink(ParaEl, ResolveLinkWithinPackage(Package, IndexSubIndex)), + SDocIdentifierIndex); + AppendText(ParaEl, ']'); + end; if Length(SearchPage) > 0 then begin @@ -2055,7 +2078,13 @@ begin BaseDirectory := Allocator.GetRelativePathToTop(AElement); if AElement.ClassType = TPasPackage then - CreatePackagePageBody + begin + Module:=Nil; + If (ASubPageIndex=0) then + CreatePackagePageBody + else + CreatePackageIndex + end else begin Element := AElement; @@ -2082,6 +2111,147 @@ begin end; end; +procedure THTMLWriter.CreateIndexPage(L : TStringList); + +Var + Lists : Array['A'..'Z'] of TStringList; + CL : TStringList; + TableEl, TREl, EL: TDOMElement; + E : TPasElement; + I,Rows,J,Index : Integer; + S : String; + C : Char; + +begin + For C:='A' to 'Z' do + Lists[C]:=Nil; + L.Sort; + // Divide over alphabet + For I:=0 to L.Count-1 do + begin + S:=L[i]; + E:=TPasElement(L.Objects[i]); + If not (E is TPasUnresolvedTypeRef) then + begin + If (S<>'') then + begin + C:=Upcase(S[1]); + If Lists[C]=Nil then + begin + CL:=TStringList.Create; + Lists[C]:=CL; + end; + end; + CL.AddObject(S,E); + end; + end; + Try + // Create a quick jump table to all available letters. + TableEl := CreateTable(BodyElement); + TableEl['border']:='1'; + TableEl['width']:='50%'; + TREl := CreateTR(TableEl); + for C:='A' to 'Z' do + If (Lists[C]<>Nil) then + begin + El:=CreateTD_vtop(TREl); + AppendText(CreateLink(El,'#SECTION'+C),C); + If C<>'Z' then + AppendNBsp(El,1); + end; + // Now emit all identifiers. + TableEl:=Nil; + For C:='A' to 'Z' do + begin + CL:=Lists[C]; + If CL<>Nil then + begin + El:=CreateH2(BodyElement); + AppendText(El,C); + CreateAnchor(El,'SECTION'+C); + TableEl := CreateTable(BodyElement); + TableEl['Width']:='80%'; + // Determine number of rows needed + Rows:=(CL.Count div IndexColCount); + If ((CL.Count Mod IndexColCount)<>0) then + Inc(Rows); + // Fill rows + For I:=0 to Rows-1 do + begin + TREl := CreateTR(TableEl); + For J:=0 to IndexColCount-1 do + begin + El:=CreateTD_vtop(TREl); + Index:=(J*Rows)+I; + If (Index