Skip to content

Commit badd7dd

Browse files
Merge branch 'topic/merge_master_to_edge' into 'edge'
Reset edge to master See merge request eng/ide/gnatdoc!181
2 parents e7f4253 + dc357db commit badd7dd

32 files changed

+939
-228
lines changed

documentation/project_file.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ include any project files directly or undirectly used by the root project.
1919
Note, externally build library project files are excluded from the
2020
documentation generation unconditionally.
2121

22+
## Image_Dirs
23+
24+
List of directories (relative to directory of the root project file) to lookup
25+
for images referenced in the documentation.
26+
2227
## Output_Dir
2328

2429
Allows to specify output directory for the generated documentation.

documentation/users_guide/backends.rst

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,17 @@ Layout of the resources directory
4646
style documentation is specified)
4747

4848

49+
ODF
50+
===
51+
52+
The ODF backend can be used to generate documentation in OpenDocument Format
53+
(ODF) format. The generated file can be opened by many office suites
54+
(Microsoft Word, LibreOffice Writer, etc) to apply different styles and print
55+
the documentation.
56+
57+
Output can be customized by providing a custom
58+
*<resources_dir>/template/documentation.fodt* file.
59+
4960

5061
RST
5162
===

documentation/users_guide/configuration.rst

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,3 +69,17 @@ and templates can be specified via the string attribute *Resources_Dir* of the
6969

7070
Each backend has own conventions on the layout of the resources directory: see
7171
the documentation of the particular backend.
72+
73+
74+
Images directories
75+
------------------
76+
77+
78+
List of directories to lookup for image files referenced in the documentation
79+
can be defined with *Image_Dirs* attribute of the root project file::
80+
81+
package Documentation is
82+
for Image_Dirs ("odf") use ("images");
83+
end Documentation;
84+
85+
By default paths are resolved relatively to the project file's root directory.
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
--
2+
-- Copyright (C) 2025, AdaCore
3+
--
4+
-- SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
5+
--
6+
7+
with Markdown.Blocks.Indented_Code;
8+
with Markdown.Blocks.Lists;
9+
with Markdown.Blocks.Paragraphs;
10+
with Markdown.Block_Containers;
11+
12+
package body Markdown.Blocks.Visitors is
13+
14+
procedure Visit_Block_Container
15+
(Self : in out Block_Iterator'Class;
16+
Container : Markdown.Block_Containers.Block_Container'Class;
17+
Visitor : in out Block_Visitor'Class);
18+
19+
procedure Visit_List
20+
(Self : in out Block_Iterator'Class;
21+
Block : Markdown.Blocks.Lists.List'Class;
22+
Visitor : in out Block_Visitor'Class);
23+
24+
-------------
25+
-- Iterate --
26+
-------------
27+
28+
procedure Iterate
29+
(Self : in out Block_Iterator'Class;
30+
Document : Markdown.Documents.Document'Class;
31+
Visitor : in out Block_Visitor'Class) is
32+
begin
33+
Self.Visit_Block_Container (Document, Visitor);
34+
end Iterate;
35+
36+
---------------------------
37+
-- Visit_Block_Container --
38+
---------------------------
39+
40+
procedure Visit_Block_Container
41+
(Self : in out Block_Iterator'Class;
42+
Container : Markdown.Block_Containers.Block_Container'Class;
43+
Visitor : in out Block_Visitor'Class) is
44+
begin
45+
for Item of Container loop
46+
if Item.Is_Paragraph then
47+
Visitor.Enter_Paragraph (Item.To_Paragraph);
48+
Visitor.Leave_Paragraph (Item.To_Paragraph);
49+
50+
elsif Item.Is_Indented_Code_Block then
51+
Visitor.Enter_Indented_Code_Block (Item.To_Indented_Code_Block);
52+
Visitor.Leave_Indented_Code_Block (Item.To_Indented_Code_Block);
53+
54+
elsif Item.Is_List then
55+
Self.Visit_List (Item.To_List, Visitor);
56+
57+
else
58+
raise Program_Error;
59+
end if;
60+
end loop;
61+
end Visit_Block_Container;
62+
63+
----------------
64+
-- Visit_List --
65+
----------------
66+
67+
procedure Visit_List
68+
(Self : in out Block_Iterator'Class;
69+
Block : Markdown.Blocks.Lists.List'Class;
70+
Visitor : in out Block_Visitor'Class) is
71+
begin
72+
Visitor.Enter_List (Block);
73+
74+
for Item of Block loop
75+
Visitor.Enter_List_Item (Item);
76+
77+
Self.Visit_Block_Container (Item, Visitor);
78+
79+
Visitor.Leave_List_Item (Item);
80+
end loop;
81+
82+
Visitor.Leave_List (Block);
83+
end Visit_List;
84+
85+
end Markdown.Blocks.Visitors;
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
--
2+
-- Copyright (C) 2025, AdaCore
3+
--
4+
-- SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
5+
--
6+
7+
with Markdown.Documents;
8+
with Markdown.List_Items;
9+
10+
package Markdown.Blocks.Visitors
11+
with Preelaborate
12+
is
13+
14+
type Block_Visitor is limited interface;
15+
16+
not overriding procedure Enter_Indented_Code_Block
17+
(Self : in out Block_Visitor;
18+
Block : Markdown.Blocks.Indented_Code.Indented_Code_Block'Class) is null;
19+
20+
not overriding procedure Leave_Indented_Code_Block
21+
(Self : in out Block_Visitor;
22+
Block : Markdown.Blocks.Indented_Code.Indented_Code_Block'Class) is null;
23+
24+
not overriding procedure Enter_List
25+
(Self : in out Block_Visitor;
26+
Block : Markdown.Blocks.Lists.List'Class) is null;
27+
28+
not overriding procedure Leave_List
29+
(Self : in out Block_Visitor;
30+
Block : Markdown.Blocks.Lists.List'Class) is null;
31+
32+
not overriding procedure Enter_List_Item
33+
(Self : in out Block_Visitor;
34+
Container : Markdown.List_Items.List_Item'Class) is null;
35+
36+
not overriding procedure Leave_List_Item
37+
(Self : in out Block_Visitor;
38+
Container : Markdown.List_Items.List_Item'Class'Class) is null;
39+
40+
not overriding procedure Enter_Paragraph
41+
(Self : in out Block_Visitor;
42+
Block : Markdown.Blocks.Paragraphs.Paragraph'Class) is null;
43+
44+
not overriding procedure Leave_Paragraph
45+
(Self : in out Block_Visitor;
46+
Block : Markdown.Blocks.Paragraphs.Paragraph'Class) is null;
47+
48+
type Block_Iterator is tagged limited private;
49+
50+
procedure Iterate
51+
(Self : in out Block_Iterator'Class;
52+
Document : Markdown.Documents.Document'Class;
53+
Visitor : in out Block_Visitor'Class);
54+
55+
private
56+
57+
type Block_Iterator is tagged limited null record;
58+
59+
end Markdown.Blocks.Visitors;

source/backend/odf/gnatdoc-backend-odf.adb

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@ with VSS.XML.XmlAda_Readers;
2020
with VSS.XML.Templates.Processors;
2121
with VSS.XML.Writers.Simple;
2222

23+
with GNATdoc.Backend.ODF_Markup.Image_Utilities;
2324
with GNATdoc.Entities.Proxies;
25+
with GNATdoc.Projects;
2426
with Streams;
2527

2628
package body GNATdoc.Backend.ODF is
@@ -118,6 +120,24 @@ package body GNATdoc.Backend.ODF is
118120
Output.Close;
119121
end Generate;
120122

123+
----------------
124+
-- Initialize --
125+
----------------
126+
127+
overriding procedure Initialize (Self : in out ODF_Backend) is
128+
begin
129+
Abstract_Backend (Self).Initialize;
130+
131+
if Self.Image_Directories.Is_Empty then
132+
GNATdoc.Backend.ODF_Markup.Image_Utilities.Set_Image_Directories
133+
([GNATdoc.Projects.Project_File_Directory]);
134+
135+
else
136+
GNATdoc.Backend.ODF_Markup.Image_Utilities.Set_Image_Directories
137+
(Self.Image_Directories);
138+
end if;
139+
end Initialize;
140+
121141
----------------------------------
122142
-- Process_Command_Line_Options --
123143
----------------------------------

source/backend/odf/gnatdoc-backend-odf.ads

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ private
2525
null;
2626
end record;
2727

28-
-- overriding procedure Initialize (Self : in out RST_Backend_Base);
28+
overriding procedure Initialize (Self : in out ODF_Backend);
2929

3030
overriding procedure Generate (Self : in out ODF_Backend);
3131

source/backend/odf/gnatdoc-backend-odf_markup-image_utilities.adb

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,13 @@ with GNAT.Strings;
2020

2121
with VSS.Strings.Conversions;
2222
with VSS.Strings.Converters.Decoders;
23+
with VSS.Strings.Formatters.Strings;
24+
with VSS.Strings.Templates;
2325

2426
with GNATCOLL.Coders.Base64;
2527

28+
with GNATdoc.Messages;
29+
2630
package body GNATdoc.Backend.ODF_Markup.Image_Utilities is
2731

2832
type Stream_Element_Array_Access is
@@ -32,6 +36,12 @@ package body GNATdoc.Backend.ODF_Markup.Image_Utilities is
3236
new Ada.Unchecked_Deallocation
3337
(Ada.Streams.Stream_Element_Array, Stream_Element_Array_Access);
3438

39+
Image_Directories : GNATdoc.Virtual_File_Vectors.Vector;
40+
41+
Not_Found_Template : constant
42+
VSS.Strings.Templates.Virtual_String_Template :=
43+
"image file '{}' is not found";
44+
3545
-----------------
3646
-- Load_Encode --
3747
-----------------
@@ -42,18 +52,30 @@ package body GNATdoc.Backend.ODF_Markup.Image_Utilities is
4252
is
4353
use type Ada.Streams.Stream_Element_Offset;
4454

55+
Name : constant GNATCOLL.VFS.Filesystem_String :=
56+
GNATCOLL.VFS.Filesystem_String
57+
(VSS.Strings.Conversions.To_UTF_8_String (Destination));
4558
File : GNATCOLL.VFS.Virtual_File;
4659
Binary : GNAT.Strings.String_Access;
4760
Encoded : Stream_Element_Array_Access;
4861
Coder : GNATCOLL.Coders.Base64.Encoder_Type;
4962

5063
begin
51-
File :=
52-
GNATCOLL.VFS.Create_From_UTF8
53-
(VSS.Strings.Conversions.To_UTF_8_String (Destination));
64+
for Directory of Image_Directories loop
65+
File :=
66+
GNATCOLL.VFS.Create_From_Base
67+
(Base_Name => Name,
68+
Base_Dir => Directory.Full_Name.all);
69+
70+
exit when File.Is_Regular_File;
71+
end loop;
5472

5573
if not File.Is_Regular_File then
56-
raise Program_Error;
74+
GNATdoc.Messages.Report_Warning
75+
(Not_Found_Template.Format
76+
(VSS.Strings.Formatters.Strings.Image (Destination)));
77+
78+
return;
5779
end if;
5880

5981
Binary := File.Read_File;
@@ -86,4 +108,14 @@ package body GNATdoc.Backend.ODF_Markup.Image_Utilities is
86108
GNAT.Strings.Free (Binary);
87109
end Load_Encode;
88110

111+
---------------------------
112+
-- Set_Image_Directories --
113+
---------------------------
114+
115+
procedure Set_Image_Directories
116+
(To : GNATdoc.Virtual_File_Vectors.Vector) is
117+
begin
118+
Image_Directories := To;
119+
end Set_Image_Directories;
120+
89121
end GNATdoc.Backend.ODF_Markup.Image_Utilities;

source/backend/odf/gnatdoc-backend-odf_markup-image_utilities.ads

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,7 @@ package GNATdoc.Backend.ODF_Markup.Image_Utilities is
2323
-- Loads given file, converts its content into Base64 encoded form and
2424
-- transforms to `Virtual_String`.
2525

26+
procedure Set_Image_Directories (To : GNATdoc.Virtual_File_Vectors.Vector);
27+
-- Set list of directories to lookup for image files.
28+
2629
end GNATdoc.Backend.ODF_Markup.Image_Utilities;

source/backend/rst/gnatdoc-backend-rst.adb

Lines changed: 4 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,6 @@ package body GNATdoc.Backend.RST is
3636
Entity : Entity_Information);
3737
-- Generate RTS file for given entity.
3838

39-
function "*"
40-
(Count : VSS.Strings.Character_Count;
41-
Item : VSS.Characters.Virtual_Character)
42-
return VSS.Strings.Virtual_String;
43-
4439
OOP_Style_Option : constant VSS.Command_Line.Binary_Option :=
4540
(Short_Name => <>,
4641
Long_Name => "rst-oop-style",
@@ -49,22 +44,6 @@ package body GNATdoc.Backend.RST is
4944
("Group subprograms by tagged types, generating a page for each"
5045
& " tagged type"));
5146

52-
---------
53-
-- "*" --
54-
---------
55-
56-
function "*"
57-
(Count : VSS.Strings.Character_Count;
58-
Item : VSS.Characters.Virtual_Character)
59-
return VSS.Strings.Virtual_String is
60-
begin
61-
return Result : VSS.Strings.Virtual_String do
62-
for J in 1 .. Count loop
63-
Result.Append (Item);
64-
end loop;
65-
end return;
66-
end "*";
67-
6847
------------------------------
6948
-- Add_Command_Line_Options --
7049
------------------------------
@@ -133,6 +112,8 @@ package body GNATdoc.Backend.RST is
133112
(Self : in out RST_Backend_Base'Class;
134113
Entity : Entity_Information)
135114
is
115+
use type VSS.Strings.Character_Count;
116+
136117
Name : constant GNATCOLL.VFS.Virtual_File :=
137118
GNATCOLL.VFS.Create_From_Base
138119
(GNATCOLL.VFS.Filesystem_String
@@ -240,11 +221,11 @@ package body GNATdoc.Backend.RST is
240221
begin
241222
File.Open (Name);
242223

243-
File.Put (Entity.Qualified_Name.Character_Length * '*', Success);
244224
File.New_Line (Success);
245225
File.Put (Entity.Qualified_Name, Success);
246226
File.New_Line (Success);
247-
File.Put (Entity.Qualified_Name.Character_Length * '*', Success);
227+
File.Put ((Entity.Qualified_Name.Character_Length + 2) * '*', Success);
228+
File.New_Line (Success);
248229
File.New_Line (Success);
249230

250231
File.Put (".. ada:set_package:: ", Success);
@@ -355,7 +336,6 @@ package body GNATdoc.Backend.RST is
355336
Right : not null GNATdoc.Entities.Entity_Information_Access)
356337
return Boolean
357338
is
358-
use type VSS.Strings.Character_Count;
359339
use type VSS.Strings.Line_Count;
360340
use type VSS.Strings.Virtual_String;
361341

0 commit comments

Comments
 (0)