Pārlūkot izejas kodu

+ Check for empty example file name

git-svn-id: trunk@4466 -
michael 19 gadi atpakaļ
vecāks
revīzija
7eb023d7cd

+ 9 - 5
utils/fpdoc/dglobals.pp

@@ -1179,16 +1179,20 @@ end;
 function TFPDocEngine.GetExampleFilename(const ExElement: TDOMElement): String;
 var
   i: Integer;
+  fn : String;
+  
 begin
+  Result:='';
   for i := 0 to DescrDocs.Count - 1 do
-    if TDOMDocument(DescrDocs[i]) = ExElement.OwnerDocument then
     begin
-      Result := ExtractFilePath(DescrDocNames[i]) + ExElement['file'];
+    Fn:=ExElement['file'];
+    if (FN<>'') and (TDOMDocument(DescrDocs[i]) = ExElement.OwnerDocument) then
+      begin
+      Result := ExtractFilePath(DescrDocNames[i]) + FN;
       if (ExtractFileExt(Result)='') then
         Result:=Result+'.pp';
-      exit;
-    end;
-  SetLength(Result, 0);
+      end;
+    end;  
 end;
 
 

+ 26 - 22
utils/fpdoc/dw_html.pp

@@ -1884,9 +1884,9 @@ Procedure THTMLWriter.AppendExampleSection(AElement : TPasElement;DocNode : TDoc
 var
   Node: TDOMNode;
 //  TableEl, El, TREl, TDEl, ParaEl, NewEl, DescrEl: TDOMElement;
-  s: String;
+  fn,s: String;
   f: Text;
-
+  
 begin
   if not (Assigned(DocNode) and Assigned(DocNode.FirstExample)) then
     Exit;
@@ -1895,30 +1895,34 @@ begin
     begin
     if (Node.NodeType = ELEMENT_NODE) and (Node.NodeName = 'example') then
       begin
-      AppendText(CreateH2(BodyElement), SDocExample);
-      try
-        Assign(f, Engine.GetExampleFilename(TDOMElement(Node)));
-        Reset(f);
+      fn:=Engine.GetExampleFilename(TDOMElement(Node));
+      If (fn<>'') then
+        begin
+        AppendText(CreateH2(BodyElement), SDocExample);
         try
-          PushOutputNode(BodyElement);
-          DescrBeginCode(False, TDOMElement(Node)['highlighter']);
-          while not EOF(f) do
+          Assign(f, FN);
+          Reset(f);
+          try
+            PushOutputNode(BodyElement);
+            DescrBeginCode(False, TDOMElement(Node)['highlighter']);
+            while not EOF(f) do
+              begin
+              ReadLn(f, s);
+              DescrWriteCodeLine(s);
+              end;
+            DescrEndCode;
+            PopOutputNode;
+          finally
+            Close(f);
+          end;
+        except
+          on e: Exception do
             begin
-            ReadLn(f, s);
-            DescrWriteCodeLine(s);
+            e.Message := '[example] ' + e.Message;
+            raise;
             end;
-          DescrEndCode;
-          PopOutputNode;
-        finally
-          Close(f);
         end;
-      except
-        on e: Exception do
-          begin
-          e.Message := '[example] ' + e.Message;
-          raise;
-          end;
-      end;
+        end;
       end;
     Node := Node.NextSibling;
     end;

+ 2 - 1
utils/fpdoc/dw_man.pp

@@ -918,7 +918,8 @@ begin
       while Assigned(Example) do
         begin
         s:=Engine.GetExampleFileName(Example);
-        WriteExampleFile(S);
+        if (s<>'') then
+          WriteExampleFile(S);
         DescrEndParaGraph;
         Repeat
           Example := TDomElement(Example.NextSibling);

+ 2 - 1
utils/fpdoc/dw_template.pp

@@ -592,7 +592,8 @@ begin
       while Assigned(Example) do
         begin
         s:=Engine.GetExampleFileName(Example);
-        WriteExampleFile(S);
+        if (s<>'') then
+          WriteExampleFile(S);
         DescrEndParaGraph;
         Repeat
           Example := TDomElement(Example.NextSibling);

+ 2 - 1
utils/fpdoc/dwlinear.pp

@@ -842,7 +842,8 @@ begin
         if (S<>'') then // not first example, start new paragraph
           DescrBeginParagraph;
         s:=Engine.GetExampleFileName(Example);
-        WriteExampleFile(S);
+        if (S<>'') then
+          WriteExampleFile(S);
         if Assigned(Example.NextSibling) then
            DescrEndParaGraph;
         end;