matreshka_league_21.0.0_0c8f4d47/tools/documentation_generator/documentation_generator-wiki.adb

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
with Ada.Wide_Wide_Text_IO;

with League.Strings;

with Documentation_Generator.Database;

package body Documentation_Generator.Wiki is

   use Documentation_Generator.Database;
   use type League.Strings.Universal_String;

   procedure Generate_Main_Page;

   procedure Generate_Type_Page (The_Type : not null Type_Access);

   function Wiki_Link
    (The_Module : not null Module_Access;
     Text       : League.Strings.Universal_String)
       return League.Strings.Universal_String;
   --  Returns wiki format reference to the corresponding wiki page.

   function Wiki_Link
    (The_Type : not null Type_Access;
     Text     : League.Strings.Universal_String)
       return League.Strings.Universal_String;
   --  Returns wiki format reference to the corresponding wiki page.

   function Wiki_Resource
    (The_Type : not null Type_Access) return League.Strings.Universal_String;
   --  Returns wiki resource name for the specified type.

   --------------
   -- Generate --
   --------------

   procedure Generate is
   begin
      Generate_Main_Page;
      Iterate (Generate_Type_Page'Access);
   end Generate;

   ------------------------
   -- Generate_Type_Page --
   ------------------------

   procedure Generate_Type_Page (The_Type : not null Type_Access) is
      File : Ada.Wide_Wide_Text_IO.File_Type;

   begin
      Ada.Wide_Wide_Text_IO.Create
       (File,
        Ada.Wide_Wide_Text_IO.Out_File,
        "wiki/"
          & Wiki_Resource (The_Type).To_UTF_8_String
          & ".wiki");

      Ada.Wide_Wide_Text_IO.Put_Line (File, "[[PageOutline]]");
      Ada.Wide_Wide_Text_IO.New_Line (File);

      Ada.Wide_Wide_Text_IO.Put_Line
       (File,
        "= "
          & The_Type.Name.To_Wide_Wide_String
          & " Type (declared in "
          & The_Type.Compilation_Unit.Name.To_Wide_Wide_String
          & " package) =");
      Ada.Wide_Wide_Text_IO.New_Line (File);

      Ada.Wide_Wide_Text_IO.Put_Line
       (File, The_Type.Description.To_Wide_Wide_String);
      Ada.Wide_Wide_Text_IO.New_Line (File);

      Ada.Wide_Wide_Text_IO.Close (File);
   end Generate_Type_Page;

   ------------------------
   -- Generate_Main_Page --
   ------------------------

   procedure Generate_Main_Page is

      procedure Process_Module (The_Module : not null Module_Access);

      procedure Process_Type (The_Type : not null Type_Access);

      File : Ada.Wide_Wide_Text_IO.File_Type;

      --------------------
      -- Process_Module --
      --------------------

      procedure Process_Module (The_Module : not null Module_Access) is
      begin
         Ada.Wide_Wide_Text_IO.Put_Line
          (File,
           "|| "
             & Wiki_Link (The_Module, The_Module.Name).To_Wide_Wide_String
             & " || "
             & The_Module.Short_Description.To_Wide_Wide_String
             & " ||");
      end Process_Module;

      ------------------
      -- Process_Type --
      ------------------

      procedure Process_Type (The_Type : not null Type_Access) is
      begin
         Ada.Wide_Wide_Text_IO.Put_Line
          (File,
           "|| "
             & Wiki_Link
                (The_Type,
                 The_Type.Name).To_Wide_Wide_String
             & " || "
             & The_Type.Compilation_Unit.Name.To_Wide_Wide_String
             & " ||");
      end Process_Type;

   begin
      Ada.Wide_Wide_Text_IO.Create
       (File, Ada.Wide_Wide_Text_IO.Out_File, "wiki/Reference.wiki");

      Ada.Wide_Wide_Text_IO.Put_Line (File, "= User's Guide =");
      Ada.Wide_Wide_Text_IO.New_Line (File);

      Ada.Wide_Wide_Text_IO.Put_Line (File, "== Modules ==");
      Ada.Wide_Wide_Text_IO.New_Line (File);

      Ada.Wide_Wide_Text_IO.Put_Line (File, "||= Name =||= Description =||");
      Iterate (Process_Module'Access);
      Ada.Wide_Wide_Text_IO.New_Line (File);

      Ada.Wide_Wide_Text_IO.Put_Line (File, "== Types ==");
      Ada.Wide_Wide_Text_IO.New_Line (File);

      Ada.Wide_Wide_Text_IO.Put_Line (File, "||= Name =||= Package =||");
      Iterate (Process_Type'Access);
      Ada.Wide_Wide_Text_IO.New_Line (File);

      Ada.Wide_Wide_Text_IO.Close (File);
   end Generate_Main_Page;

   ---------------
   -- Wiki_Link --
   ---------------

   function Wiki_Link
    (The_Type : not null Type_Access;
     Text     : League.Strings.Universal_String)
       return League.Strings.Universal_String is
   begin
      return
        "[wiki:"
          & Wiki_Resource (The_Type)
          & " "
          & Text
          & ']';
   end Wiki_Link;

   ---------------
   -- Wiki_Link --
   ---------------

   function Wiki_Link
    (The_Module : not null Module_Access;
     Text       : League.Strings.Universal_String)
       return League.Strings.Universal_String is
   begin
      return
        "[wiki:Reference/"
          & The_Module.Name
          & " "
          & Text
          & ']';
   end Wiki_Link;

   -------------------
   -- Wiki_Resource --
   -------------------

   function Wiki_Resource
    (The_Type : not null Type_Access) return League.Strings.Universal_String is
   begin
      return
        "Reference/"
          & The_Type.Module.Name
          & "/_types/"
          & The_Type.Name;
   end Wiki_Resource;

end Documentation_Generator.Wiki;