Просмотр исходного кода

* --example-dir support

(cherry picked from commit 45c683325867989800e574edc8e013030c56d33d)
Michaël Van Canneyt 4 лет назад
Родитель
Сommit
0df4f6fcaa
4 измененных файлов с 34 добавлено и 9 удалено
  1. 16 7
      utils/fpdoc/dglobals.pp
  2. 3 0
      utils/fpdoc/fpdoc.pp
  3. 1 0
      utils/fpdoc/fpdocstrs.pp
  4. 14 2
      utils/fpdoc/mkfpdoc.pp

+ 16 - 7
utils/fpdoc/dglobals.pp

@@ -37,7 +37,7 @@ Var
 Const
   SVisibility: array[TPasMemberVisibility] of string =
        ('Default', 'Private', 'Protected', 'Public',
-       'Published', 'Automated','Strict Private','Strict Protected',
+      'Published', 'Automated','Strict Private','Strict Protected',
        'Required', 'Optional' // ObjCClass
        );
 
@@ -146,6 +146,7 @@ type
   TFPDocEngine = class(TPasTreeContainer)
   private
     FDocLogLevels: TFPDocLogLevels;
+    FExamplesPath: String;
     FOnParseUnit: TOnParseUnitEvent;
     function ResolveLinkInPackages(AModule: TPasModule; const ALinkDest: String; Strict: Boolean=False): String;
     function ResolveLinkInUsedUnits(AModule: TPasModule; const ALinkDest: String; Strict: Boolean=False): String;
@@ -210,6 +211,7 @@ type
     property RootDocNode: TDocNode read FRootDocNode;
     Property DocLogLevels : TFPDocLogLevels Read FDocLogLevels Write FDocLogLevels;
     Property OnParseUnit : TOnParseUnitEvent Read FOnParseUnit Write FOnParseUnit;
+    Property ExamplesPath : String Read FExamplesPath Write FExamplesPath;
   end;
 
 
@@ -1541,16 +1543,23 @@ var
   
 begin
   Result:='';
-  for i := 0 to DescrDocs.Count - 1 do
+  Fn:=UTF8Encode(ExElement['file']);
+  if FN='' then
+    exit;
+  if ExamplesPath<>'' then
+    Result:=IncludeTrailingPathDelimiter(ExamplesPath)+FN
+  else
     begin
-    Fn:=UTF8Encode(ExElement['file']);
-    if (FN<>'') and (TDOMDocument(DescrDocs[i]) = ExElement.OwnerDocument) then
+    I:=0;
+    While (Result='') and (I<DescrDocs.Count) do
       begin
-      Result := ExtractFilePath(DescrDocNames[i]) + FN;
-      if (ExtractFileExt(Result)='') then
-        Result:=Result+'.pp';
+      if (TDOMDocument(DescrDocs[i]) = ExElement.OwnerDocument) then
+        Result := ExtractFilePath(DescrDocNames[i]) + FN;
+      Inc(I);
       end;
     end;  
+  if (ExtractFileExt(Result)='') then
+    Result:=Result+'.pp';
 end;
 
 

+ 3 - 0
utils/fpdoc/fpdoc.pp

@@ -85,6 +85,7 @@ begin
   Writeln(SUsageOption035);
   Writeln(SUsageOption040);
   Writeln(SUsageOption050);
+  Writeln(SUsageOption055);
   Writeln(SUsageOption060);
   Writeln(SUsageOption070);
   Writeln(SUsageOption080);
@@ -349,6 +350,8 @@ begin
       FProjectFile:=True;
       FCreator.LoadProjectFile(Arg);
       end
+    else if (Cmd = '--examples-dir') then
+      FCreator.ExamplesPath:=Arg
     else if (Cmd = '--descr') then
       AddToFileList(SelectedPackage.Descriptions, Arg)
     else if (Cmd = '--descr-dir') then

+ 1 - 0
utils/fpdoc/fpdocstrs.pp

@@ -153,6 +153,7 @@ resourcestring
   SUsageOption035  = '                  --descr=c:\WIP\myzipperdoc.xml';
   SUsageOption040  = '                  This option is allowed more than once';
   SUsageOption050  = '--descr-dir=Dir   Add All XML files in Dir to list of description files';
+  SUsageOption055  = '--example-dir=DIR Look for examples in directory DIR';
   SUsageOption060  = '--format=fmt      Select output format.';
   SUsageOption070  = '--help            Show this help.';
   SUsageOption080  = '--hide-protected  Do not show protected methods in overview';

+ 14 - 2
utils/fpdoc/mkfpdoc.pp

@@ -27,6 +27,7 @@ Type
     FBaseDescrDir: String;
     FBaseInputDir: String;
     FCurPackage : TFPDocPackage;
+    FExamplesPath: String;
     FProcessedUnits : TStrings;
     FOnLog: TPasParserLogHandler;
     FPParserLogEvents: TPParserLogEvents;
@@ -39,6 +40,7 @@ Type
     function GetPackages: TFPDocPackages;
     procedure SetBaseDescrDir(AValue: String);
     procedure SetBaseInputDir(AValue: String);
+    procedure SetExamplesPath(AValue: String);
     procedure SetProjectMacros(AValue: TStrings);
   Protected
     Function FixInputFile(Const AFileName : String) : String;
@@ -68,6 +70,7 @@ Type
     // When set, they will be prepended to non-absolute filenames.
     Property BaseInputDir : String Read FBaseInputDir Write SetBaseInputDir;
     Property BaseDescrDir : String Read FBaseDescrDir Write SetBaseDescrDir;
+    Property ExamplesPath : String Read FExamplesPath Write SetExamplesPath;
     // Macros used when loading the project file
     Property ProjectMacros : TStrings Read FProjectMacros Write SetProjectMacros;
   end;
@@ -188,6 +191,14 @@ begin
     FBaseInputDir:=IncludeTrailingPathDelimiter(FBaseInputDir);
 end;
 
+procedure TFPDocCreator.SetExamplesPath(AValue: String);
+begin
+  if FExamplesPath=AValue then Exit;
+  FExamplesPath:=AValue;
+  If FExamplesPath<>'' then
+    FExamplesPath:=IncludeTrailingPathDelimiter(FExamplesPath);
+end;
+
 procedure TFPDocCreator.SetProjectMacros(AValue: TStrings);
 begin
   if FProjectMacros=AValue then Exit;
@@ -260,7 +271,7 @@ begin
     Engine.WriteContentFile(APackage.ContentFile);
 end;
 
-Function TFPDocCreator.GetLogLevels : TFPDocLogLevels;
+function TFPDocCreator.GetLogLevels: TFPDocLogLevels;
 
   Procedure DoOpt(doSet : Boolean; aLevel: TFPDocLogLevel);
 
@@ -290,8 +301,9 @@ begin
   Cmd:='';
   FCurPackage:=APackage;
   Engine:=TFPDocEngine.Create;
-  Engine.OnLog:= @DoLogSender;
   try
+    Engine.OnLog:= @DoLogSender;
+    Engine.ExamplesPath:=Self.ExamplesPath;
     // get documentation Writer html, latex, and other
     WriterClass:=GetWriterClass(Options.Backend);
     For J:=0 to Apackage.Imports.Count-1 do