mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-04-19 14:29:29 +02:00
wiki test: load files
git-svn-id: trunk@35644 -
This commit is contained in:
parent
0d46fab5d1
commit
9e9f823a55
@ -38,6 +38,43 @@
|
||||
</package>
|
||||
</fpdoc>
|
||||
|
||||
|
||||
wptText, // TWPTextToken
|
||||
wptAttribute, // e.g. class="code" TWPNameValueToken
|
||||
wptLineBreak, // <br> /br> <br/>
|
||||
wptBold, // '''
|
||||
wptItalic, // ''
|
||||
wptStrikeTagShort, // <s>
|
||||
wptUnderlineTag, // <u>
|
||||
wptTT, // <tt>
|
||||
wptSup, // <sup>
|
||||
wptSub, // <sub>
|
||||
wptSmall, // <small>
|
||||
wptEm, // <em>
|
||||
wptString, // <string>
|
||||
wptVar, // <var>
|
||||
wptKey, // <key>
|
||||
wptCmt, // <cmt>
|
||||
wptSpan, // <span>
|
||||
wptCode, // TWPNameValueToken
|
||||
wptSpecial, // double curly bracket: title, shortcut like Ctrl+Shift+1
|
||||
wptPre, // space at line start
|
||||
wptP, // paragraph
|
||||
wptCenter, // <center>
|
||||
wptInternLink, // [[]]
|
||||
wptExternLink, // []
|
||||
wptHorizontalRow, // ----
|
||||
wptNumberedList, // #
|
||||
wptBulletList, // *
|
||||
wptDefinitionList, // : or ;
|
||||
wptListItem,
|
||||
wptTable, // wiki tag for table
|
||||
wptTableRow, // wiki tag for table row
|
||||
wptTableHeadCell, // wiki tag for table head cell
|
||||
wptTableCell, // wiki tag for table cell
|
||||
wptSection, // started/ended by =
|
||||
wptHeader, // =Text=
|
||||
|
||||
}
|
||||
unit Wiki2FPDocConvert;
|
||||
|
||||
|
@ -709,7 +709,7 @@ var
|
||||
Filename: String;
|
||||
begin
|
||||
inherited Convert;
|
||||
if (CSSFilename<>'') then begin
|
||||
if (CSSFilename<>'') and (OutputDir<>'') then begin
|
||||
Filename:=TrimAndExpandFilename(CSSFilename);
|
||||
if not FileExistsUTF8(Filename) then
|
||||
raise Exception.Create('css file not found: "'+Filename+'"');
|
||||
@ -722,7 +722,10 @@ end;
|
||||
|
||||
function TWiki2XHTMLConverter.GetRelativeCSSFilename: string;
|
||||
begin
|
||||
Result:=TrimAndExpandFilename(CSSFilename);
|
||||
Result:=CSSFilename;
|
||||
if (OutputDir='') or not FilenameIsAbsolute(OutputDir) then
|
||||
exit;
|
||||
Result:=TrimAndExpandFilename(Result);
|
||||
if Result='' then exit;
|
||||
Result:=CreateRelativePath(Result,OutputDir);
|
||||
end;
|
||||
|
@ -62,6 +62,7 @@ type
|
||||
FOutputDir: string;
|
||||
fPages: TW2FormatPageList;
|
||||
FPageClass: TW2FormatPageClass;
|
||||
fMultiReadExclusiveWrite: TMultiReadExclusiveWriteSynchronizer;
|
||||
function GetPages(Index: integer): TW2FormatPage;
|
||||
procedure SetOutputDir(AValue: string);
|
||||
procedure SetImagesDir(AValue: string);
|
||||
@ -73,9 +74,13 @@ type
|
||||
function AddWikiPage(Filename: string; ParseNow: boolean = true): TW2FormatPage;
|
||||
procedure Convert; virtual;
|
||||
function Count: integer;
|
||||
procedure BeginRead;
|
||||
procedure EndRead;
|
||||
procedure BeginWrite;
|
||||
procedure EndWrite;
|
||||
property Pages[Index: integer]: TW2FormatPage read GetPages; default;
|
||||
property PageClass: TW2FormatPageClass read FPageClass;
|
||||
property OutputDir: string read FOutputDir write SetOutputDir; // the directory of the fpdoc files
|
||||
property OutputDir: string read FOutputDir write SetOutputDir;
|
||||
property ImagesDir: string read FImagesDir write SetImagesDir;
|
||||
property Title: string read FTitle write SetTitle;
|
||||
property WarnMissingPageLinks: boolean read FWarnMissingPageLinks write FWarnMissingPageLinks; // warn if an internal link links to non existing page
|
||||
@ -87,6 +92,7 @@ function WikiPageToFilename(Page: string; IsInternalLink, AppendCaseID: boolean)
|
||||
function WikiFilenameToPage(Filename: string): string;
|
||||
function WikiImageToFilename(Image: string; IsInternalLink, InsertCaseID: boolean;
|
||||
KeepScheme: boolean = false): string;
|
||||
function WikiCreateCommonLanguageList(AddLazWikiLangs: boolean): TKeyWordFunctionList;
|
||||
|
||||
implementation
|
||||
|
||||
@ -123,6 +129,7 @@ end;
|
||||
|
||||
constructor TWiki2FormatConverter.Create;
|
||||
begin
|
||||
fMultiReadExclusiveWrite:=TMultiReadExclusiveWriteSynchronizer.Create;
|
||||
FPageClass:=TW2FormatPage;
|
||||
fPages:=TW2FormatPageList.Create;
|
||||
FTitle:='FPC/Lazarus Wiki (offline, generated '+DatetoStr(Now)+')';
|
||||
@ -136,6 +143,7 @@ begin
|
||||
FreeAndNil(FNoWarnBaseURLs);
|
||||
FreeAndNil(fPages);
|
||||
inherited Destroy;
|
||||
FreeAndNil(fMultiReadExclusiveWrite);
|
||||
end;
|
||||
|
||||
procedure TWiki2FormatConverter.Clear;
|
||||
@ -195,6 +203,26 @@ begin
|
||||
Result:=fPages.Count;
|
||||
end;
|
||||
|
||||
procedure TWiki2FormatConverter.BeginRead;
|
||||
begin
|
||||
fMultiReadExclusiveWrite.Beginread;
|
||||
end;
|
||||
|
||||
procedure TWiki2FormatConverter.EndRead;
|
||||
begin
|
||||
fMultiReadExclusiveWrite.Endread;
|
||||
end;
|
||||
|
||||
procedure TWiki2FormatConverter.BeginWrite;
|
||||
begin
|
||||
fMultiReadExclusiveWrite.Beginwrite;
|
||||
end;
|
||||
|
||||
procedure TWiki2FormatConverter.EndWrite;
|
||||
begin
|
||||
fMultiReadExclusiveWrite.Endwrite;
|
||||
end;
|
||||
|
||||
{ TW2FormatPage }
|
||||
|
||||
constructor TW2FormatPage.Create(TheConverter: TWiki2FormatConverter);
|
||||
@ -325,5 +353,26 @@ begin
|
||||
Result:=Result+id+'.'+Ext;
|
||||
end;
|
||||
|
||||
function WikiCreateCommonLanguageList(AddLazWikiLangs: boolean): TKeyWordFunctionList;
|
||||
begin
|
||||
Result:=TKeyWordFunctionList.Create('LanguageTags');
|
||||
with Result do begin
|
||||
Add('code',@AllwaysTrue);
|
||||
Add('source',@AllwaysTrue);
|
||||
Add('pascal',@AllwaysTrue);
|
||||
Add('delphi',@AllwaysTrue);
|
||||
if AddLazWikiLangs then begin
|
||||
Add('bash',@AllwaysTrue);
|
||||
Add('java',@AllwaysTrue);
|
||||
Add('javascript',@AllwaysTrue);
|
||||
Add('xml',@AllwaysTrue);
|
||||
Add('perl',@AllwaysTrue);
|
||||
Add('python',@AllwaysTrue);
|
||||
Add('sql',@AllwaysTrue);
|
||||
Add('objc',@AllwaysTrue);
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
|
||||
end.
|
||||
|
||||
|
@ -5,11 +5,28 @@ unit WikiHelpManager;
|
||||
interface
|
||||
|
||||
uses
|
||||
Classes, SysUtils, LazFileUtils, LazLogger, Wiki2HTMLConvert;
|
||||
Classes, SysUtils, LazFileUtils, LazLogger, Wiki2HTMLConvert,
|
||||
MTProcs;
|
||||
|
||||
type
|
||||
TWikiHelp = class;
|
||||
|
||||
{ TW2HelpPage
|
||||
for future extensions and descendants }
|
||||
|
||||
TW2HelpPage = class(TW2HTMLPage)
|
||||
public
|
||||
|
||||
end;
|
||||
|
||||
{ TWiki2HelpConverter }
|
||||
|
||||
TWiki2HelpConverter = class(TWiki2HTMLConverter)
|
||||
protected
|
||||
public
|
||||
constructor Create; override;
|
||||
end;
|
||||
|
||||
{ TWikiHelpThread }
|
||||
|
||||
TWikiHelpThread = class(TThread)
|
||||
@ -19,6 +36,7 @@ type
|
||||
procedure MainThreadLog;
|
||||
procedure Log(Msg: string);
|
||||
procedure OnScanComplete; // called in thread at end
|
||||
procedure LoadWikiPage(Index: PtrInt; {%H-}Data: Pointer; {%H-}Item: TMultiThreadProcItem);
|
||||
public
|
||||
Help: TWikiHelp;
|
||||
XMLDirectory: string;
|
||||
@ -30,6 +48,7 @@ type
|
||||
TWikiHelp = class(TComponent)
|
||||
private
|
||||
FAborting: boolean;
|
||||
FConverter: TWiki2HelpConverter;
|
||||
FImagesDirectory: string;
|
||||
FScanning: boolean;
|
||||
FXMLDirectory: string;
|
||||
@ -48,6 +67,7 @@ type
|
||||
property Aborting: boolean read FAborting;
|
||||
property XMLDirectory: string read FXMLDirectory write SetXMLDirectory; // directory where the wiki xml files are
|
||||
property ImagesDirectory: string read FImagesDirectory write SetImagesDirectory; // directory where the wiki image files are
|
||||
property Converter: TWiki2HelpConverter read FConverter;
|
||||
end;
|
||||
|
||||
var
|
||||
@ -55,13 +75,50 @@ var
|
||||
|
||||
implementation
|
||||
|
||||
{ TWiki2HelpConverter }
|
||||
|
||||
constructor TWiki2HelpConverter.Create;
|
||||
begin
|
||||
inherited Create;
|
||||
fPageClass:=TW2HelpPage;
|
||||
end;
|
||||
|
||||
{ TWikiHelpThread }
|
||||
|
||||
procedure TWikiHelpThread.Execute;
|
||||
var
|
||||
FileInfo: TSearchRec;
|
||||
Files: TStringList;
|
||||
i: Integer;
|
||||
Filename: String;
|
||||
begin
|
||||
Files:=nil;
|
||||
try
|
||||
Log('TWikiHelpThread.Execute START XMLDirectory="'+XMLDirectory+'"');
|
||||
|
||||
Files:=TStringList.Create;
|
||||
try
|
||||
// get all wiki xml files
|
||||
if FindFirstUTF8(XMLDirectory+AllFilesMask,faAnyFile,FileInfo)=0 then begin
|
||||
repeat
|
||||
if CompareFileExt(FileInfo.Name,'.xml',false)=0 then
|
||||
Files.Add(FileInfo.Name);
|
||||
until FindNextUTF8(FileInfo)<>0;
|
||||
end;
|
||||
FindCloseUTF8(FileInfo);
|
||||
|
||||
// add file names to converter
|
||||
for i:=0 to Files.Count-1 do begin
|
||||
Filename:=XMLDirectory+Files[i];
|
||||
Help.Converter.AddWikiPage(Filename,false);
|
||||
end;
|
||||
finally
|
||||
Files.Free;
|
||||
end;
|
||||
|
||||
// load xml files
|
||||
ProcThreadPool.DoParallel(@LoadWikiPage,0,Help.Converter.Count-1);
|
||||
|
||||
Log('TWikiHelpThread.Execute SCAN complete XMLDirectory="'+XMLDirectory+'"');
|
||||
except
|
||||
on E: Exception do begin
|
||||
@ -95,13 +152,22 @@ begin
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TWikiHelpThread.LoadWikiPage(Index: PtrInt; Data: Pointer;
|
||||
Item: TMultiThreadProcItem);
|
||||
var
|
||||
Page: TW2HelpPage;
|
||||
begin
|
||||
Page:=TW2HelpPage(Help.Converter.Pages[Index]);
|
||||
Page.ParseWikiDoc;
|
||||
end;
|
||||
|
||||
{ TWikiHelp }
|
||||
|
||||
procedure TWikiHelp.SetImagesDirectory(AValue: string);
|
||||
var
|
||||
NewDir: String;
|
||||
begin
|
||||
NewDir:=AppendPathDelim(TrimFilename(AValue));
|
||||
NewDir:=TrimAndExpandDirectory(TrimFilename(AValue));
|
||||
if FImagesDirectory=NewDir then Exit;
|
||||
FImagesDirectory:=NewDir;
|
||||
end;
|
||||
@ -110,7 +176,7 @@ procedure TWikiHelp.SetXMLDirectory(AValue: string);
|
||||
var
|
||||
NewDir: String;
|
||||
begin
|
||||
NewDir:=AppendPathDelim(TrimFilename(AValue));
|
||||
NewDir:=TrimAndExpandDirectory(TrimFilename(AValue));
|
||||
if FXMLDirectory=NewDir then Exit;
|
||||
FXMLDirectory:=NewDir;
|
||||
end;
|
||||
@ -129,11 +195,13 @@ constructor TWikiHelp.Create(AOwner: TComponent);
|
||||
begin
|
||||
InitCriticalSection(FCritSec);
|
||||
inherited Create(AOwner);
|
||||
FConverter:=TWiki2HelpConverter.Create;
|
||||
end;
|
||||
|
||||
destructor TWikiHelp.Destroy;
|
||||
begin
|
||||
Abort;
|
||||
FreeAndNil(FConverter);
|
||||
inherited Destroy;
|
||||
DoneCriticalsection(FCritSec);
|
||||
end;
|
||||
|
@ -5,8 +5,8 @@ unit WikiSearchMain;
|
||||
interface
|
||||
|
||||
uses
|
||||
Classes, SysUtils, FileUtil, IpHtml, Forms, Controls, Graphics, Dialogs,
|
||||
StdCtrls, ExtCtrls, WikiHelpManager;
|
||||
Classes, SysUtils, FileUtil, IpHtml, Forms, Controls, Graphics,
|
||||
Dialogs, StdCtrls, ExtCtrls, WikiHelpManager;
|
||||
|
||||
type
|
||||
|
||||
@ -46,6 +46,9 @@ begin
|
||||
WikiHelp:=TWikiHelp.Create(nil);
|
||||
WikiHelp.XMLDirectory:=SetDirSeparators('../wikixml');
|
||||
WikiHelp.ImagesDirectory:=SetDirSeparators('../images');
|
||||
WikiHelp.Converter.OutputDir:='';
|
||||
WikiHelp.Converter.CSSFilename:='wiki.css';
|
||||
|
||||
WikiHelp.StartScan;
|
||||
end;
|
||||
|
||||
|
@ -257,21 +257,7 @@ constructor TWiki2FPDocApplication.Create(TheOwner: TComponent);
|
||||
begin
|
||||
inherited Create(TheOwner);
|
||||
StopOnException:=True;
|
||||
FLanguageTags:=TKeyWordFunctionList.Create('LanguageTags');
|
||||
with FLanguageTags do begin
|
||||
Add('code',@AllwaysTrue);
|
||||
Add('source',@AllwaysTrue);
|
||||
Add('pascal',@AllwaysTrue);
|
||||
Add('delphi',@AllwaysTrue);
|
||||
Add('bash',@AllwaysTrue);
|
||||
Add('java',@AllwaysTrue);
|
||||
Add('javascript',@AllwaysTrue);
|
||||
Add('xml',@AllwaysTrue);
|
||||
Add('perl',@AllwaysTrue);
|
||||
Add('python',@AllwaysTrue);
|
||||
Add('sql',@AllwaysTrue);
|
||||
Add('objc',@AllwaysTrue);
|
||||
end;
|
||||
FLanguageTags:=WikiCreateCommonLanguageList(true);
|
||||
FFPDocConverter:=TWiki2FPDocConverter.Create;
|
||||
FPDocConverter.LanguageTags:=LanguageTags;
|
||||
FXHTMLConverter:=TWiki2XHTMLConverter.Create;
|
||||
|
Loading…
Reference in New Issue
Block a user