[7c13b4]: inst / generate_package_html.m  Maximize  Restore  History

Download this file

392 lines (342 with data), 13.7 kB

  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
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
## Copyright (C) 2008 Soren Hauberg
##
## This program is free software; you can redistribute it and/or modify it
## under the terms of the GNU General Public License as published by
## the Free Software Foundation; either version 3 of the License, or (at
## your option) any later version.
##
## This program is distributed in the hope that it will be useful, but
## WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
## General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with this program; see the file COPYING. If not, see
## <http://www.gnu.org/licenses/>.
## -*- texinfo -*-
## @deftypefn {Function File} generate_package_html (@var{name}, @var{outdir}, @var{options})
## Generate @t{HTML} documentation for a package.
##
## The function reads information about package @var{name} using the
## package system. This is then used to generate bunch of
## @t{HTML} files; one for each function in the package, and one overview
## page. The files are all placed in the directory @var{outdir}, which defaults
## to the current directory. The @var{options} structure is used to control
## the design of the web pages.
##
## As an example, the following code generates the web pages for the @t{image}
## package, with a design suitable for the @t{Octave-Forge} project.
##
## @example
## options = get_html_options ("octave-forge");
## generate_package_html ("image", "image_html", options);
## @end example
##
## The resulting files will be available in the @t{"image_html"} directory. The
## overview page will be called @t{"image_html/image_overview.html"}.
##
## As a convenience, if @var{options} is a string, a structure will
## be generated by calling @code{get_html_options}. This means the above
## example can be reduced to the following.
##
## @example
## generate_package_html ("image", "image_html", "octave-forge");
## @end example
##
## It should be noted that the function only works for installed packages.
## @seealso{get_html_options}
## @end deftypefn
function generate_package_html (name = [], outdir = "manual",
options = struct (), section = "extra")
## Check input
if (isempty (name))
list = pkg ("list");
for k = 1:length (list)
generate_package_html (list {k}.name, outdir, options);
endfor
return;
elseif (isstruct (name))
desc = name;
if (isfield (name, "name"))
packname = desc.name;
else
packname = "";
endif
elseif (ischar (name))
packname = name;
pkg ("load", name);
desc = pkg ("describe", name) {1};
else
error (["generate_package_html: first input must either be the name of a ", ...
"package, or a structure giving its description."]);
endif
if (isempty (outdir))
outdir = packname;
elseif (!ischar (outdir))
error ("generate_package_html: second input argument must be a string");
endif
## Create output directory if needed
if (!exist (outdir, "dir"))
mkdir (outdir);
endif
packdir = fullfile (outdir, packname);
if (!exist (packdir, "dir"))
mkdir (packdir);
endif
[local_fundir, fundir] = mk_function_dir (packdir, packname, options);
## If options is a string, call get_html_options
if (ischar (options))
options = get_html_options (options);
elseif (!isstruct (options))
error ("generate_package_html: third input argument must be a string or a structure");
endif
##################################################
## Generate html pages for individual functions ##
##################################################
## Set javascript startup
if (!isfield (options, "body_command"))
if (isfield (options, "pack_body_cmd"))
options.body_command = options.pack_body_cmd;
else
options.body_command = "";
endif
endif
num_categories = length (desc.provides);
anchors = implemented = cell (1, num_categories);
for k = 1:num_categories
F = desc.provides {k}.functions;
category = desc.provides {k}.category;
anchors {k} = strrep (category, " ", ""); # anchor names
## For each function in category
num_functions = length (F);
implemented {k} = cell (1, num_functions);
for l = 1:num_functions
fun = F {l};
outname = fullfile (fundir, sprintf ("%s.html", fun));
try
html_help_text (fun, outname, options, "../../");
implemented {k}{l} = true;
catch
warning ("marking '%s' as not implemented", fun);
implemented {k}{l} = false;
end_try_catch
endfor
endfor
#########################
## Write overview file ##
#########################
if (isfield (options, "include_overview") && options.include_overview)
overview_filename = get_overview_filename (options, desc.name);
fid = fopen (fullfile (packdir, overview_filename), "w");
if (fid < 0)
error ("generate_package_html: couldn't open overview file for writing");
endif
[header, title, footer] = get_overview_header_title_and_footer (options, desc.name, "../");
fprintf (fid, "%s\n", header);
fprintf (fid, "<h2 class=\"tbdesc\">%s</h2>\n\n", desc.name);
fprintf (fid, " <div class=\"package_description\">\n");
fprintf (fid, " %s\n", desc.description);
fprintf (fid, " </div>\n\n");
fprintf (fid, " <ul>\n");
for k = 1:num_categories
category = desc.provides {k}.category;
fprintf (fid, " <li><a href=\"#%s\">%s</a></li>\n", anchors {k}, category);
endfor
fprintf (fid, " </ul>\n\n");
## Generate function list by category
for k = 1:num_categories
F = desc.provides {k}.functions;
category = desc.provides {k}.category;
fprintf (fid, " <h3 class=\"category\"><a name=\"%s\">%s</a></h3>\n\n",
anchors {k}, category);
## For each function in category
for l = 1:length (F)
fun = F {l};
if (implemented {k}{l})
link = sprintf ("../../%s/%s.html", local_fundir, fun);
fprintf (fid, " <div class=\"func\"><b><a href=\"%s\">%s</a></b></div>\n",
link, fun);
fprintf (fid, " <div class=\"ftext\">%s</div>\n\n",
get_first_help_sentence (fun, 200));
else
fprintf (fid, " <div class=\"func\"><b>%s</b></div>\n", fun);
fprintf (fid, " <div class=\"ftext\">Not implemented.</div>\n\n");
endif
endfor
endfor
fprintf (fid, "\n%s\n", footer);
fclose (fid);
endif
#####################################################
## Write short description for forge overview page ##
#####################################################
if (isfield (options, "include_package_list_item") && options.include_package_list_item)
pkg_list_item_filename = get_pkg_list_item_filename (desc.name, outdir, section);
text = strrep (options.package_list_item, "%name", desc.name);
text = strrep (text, "%uppername", toupper(desc.name));
text = strrep (text, "%version", desc.version);
text = strrep (text, "%extension", "tar.gz");
fid = fopen (pkg_list_item_filename, "w");
if (fid > 0)
fprintf (fid, text);
fclose (fid);
else
error ("generate_package_html: unable to open file %s.", pkg_list_item_filename);
endif
endif
######################
## Write index file ##
######################
if (isfield (options, "include_package_page") && options.include_package_page)
## Get detailed information about the package
all_list = pkg ("list");
list = [];
for k = 1:length (all_list)
if (strcmp (all_list {k}.name, packname))
list = all_list {k};
endif
endfor
if (isempty (list))
error ("generate_package_html: couldn't locate package '%s'", packname);
endif
## Open output file
index_filename = "index.html";
fid = fopen (fullfile (packdir, index_filename), "w");
if (fid < 0)
error ("generate_package_html: couldn't open index file for writing");
endif
## Write output
[header, title, footer] = get_index_header_title_and_footer (options, desc.name, "../");
fprintf (fid, "%s\n", header);
fprintf (fid, "<h2 class=\"tbdesc\">%s</h2>\n\n", desc.name);
fprintf (fid, "<table>\n");
fprintf (fid, "<tr><td rowspan=\"2\" class=\"box_table\">\n");
fprintf (fid, "<div class=\"package_box\">\n");
fprintf (fid, " <div class=\"package_box_header\">%s</div>\n", desc.name);
fprintf (fid, " <div class=\"package_box_contents\">\n");
fprintf (fid, " <table>\n");
fprintf (fid, " <tr><td class=\"package_table\">Package Version:</td><td>%s</td></tr>\n",
list.version);
fprintf (fid, " <tr><td class=\"package_table\">Last Release Date:</td><td>%s</td></tr>\n",
list.date);
fprintf (fid, " <tr><td class=\"package_table\">Package Author:</td><td>%s</td></tr>\n",
list.author);
fprintf (fid, " <tr><td class=\"package_table\">Package Maintainer:</td><td>%s</td></tr>\n",
list.maintainer);
fprintf (fid, " <tr><td class=\"package_table\">License:</td><td><a href=\"COPYING.html\">");
if (isfield (list, "license"))
fprintf (fid, "%s</a></td></tr>\n", list.license);
else
fprintf (fid, "Read license</a></td></tr>\n");
endif
fprintf (fid, " </table>\n");
fprintf (fid, " </div>\n");
fprintf (fid, "</div>\n");
fprintf (fid, "</td>\n\n");
fprintf (fid, "<td>\n");
if (isfield (options, "download_link"))
fprintf (fid, "<div class=\"download_package\">\n");
fprintf (fid, " <table><tr><td>\n");
fprintf (fid, " <img src=\"../download.png\"/>\n");
fprintf (fid, " </td><td>\n");
link = strrep (options.download_link, "%name", desc.name);
link = strrep (link, "%version", desc.version);
fprintf (fid, " <a href=\"%s\"\n", link);
fprintf (fid, " class=\"download_link\">\n");
fprintf (fid, " Download Package\n");
fprintf (fid, " </a>\n");
fprintf (fid, " </td></tr></table>\n");
fprintf (fid, "</div>\n");
endif
fprintf (fid, "</td></tr>\n");
fprintf (fid, "<tr><td>\n");
fprintf (fid, "<div class=\"package_function_reference\">\n");
fprintf (fid, " <table><tr><td>\n");
fprintf (fid, " <img src=\"../doc.png\"/>\n");
fprintf (fid, " </td><td>\n");
fprintf (fid, " <a href=\"%s\" class=\"function_reference_link\">\n", overview_filename);
fprintf (fid, " Function Reference\n");
fprintf (fid, " </a>\n");
fprintf (fid, " </td></tr></table>\n");
fprintf (fid, "</div>\n");
fprintf (fid, "</td></tr>\n");
fprintf (fid, "</table>\n\n");
fprintf (fid, "<h3>Description</h3>\n");
fprintf (fid, " <div id=\"description_box\">\n")
fprintf (fid, list.description);
fprintf (fid, " </div>\n\n")
fprintf (fid, "<h3>Details</h3>\n");
fprintf (fid, " <table id=\"extra_package_table\">\n");
if (isfield (list, "depends"))
fprintf (fid, " <tr><td>Dependencies: </td><td>\n");
for k = 1:length (list.depends)
p = list.depends {k}.package;
if (isfield (list.depends {k}, "operator") && isfield (list.depends {k}, "version"))
o = list.depends {k}.operator;
v = list.depends {k}.version;
vt = sprintf ("(%s %s) ", o, v);
else
vt = "";
endif
if (strcmpi (p, "octave"))
fprintf (fid, "<a href=\"http://www.octave.org\">Octave</a> ");
else
fprintf (fid, "<a href=\"../%s/index.html\">%s</a> ", p, p);
endif
fprintf (fid, vt);
endfor
fprintf (fid, "</td></tr>\n");
endif
if (isfield (list, "buildrequires"))
fprintf (fid, " <tr><td>Build Dependencies:</td><td>%s</td></tr>\n", list.buildrequires);
endif
if (isfield (list, "autoload"))
if (list.autoload)
a = "Yes";
else
a = "No";
endif
fprintf (fid, " <tr><td>Autoload:</td><td>%s</td></tr>\n", a);
endif
fprintf (fid, " </table>\n\n");
fprintf (fid, "\n%s\n", footer);
fclose (fid);
endif
######################
## Write COPYING file ##
######################
if (isfield (options, "include_package_license") && options.include_package_license)
## Get detailed information about the package
all_list = pkg ("list");
list = [];
for k = 1:length (all_list)
if (strcmp (all_list {k}.name, packname))
list = all_list {k};
endif
endfor
if (isempty (list))
error ("generate_package_html: couldn't locate package '%s'", packname);
endif
## Read license
filename = fullfile (list.dir, "packinfo", "COPYING");
fid = fopen (filename, "r");
if (fid < 0)
error ("generate_package_html: couldn't open license for reading");
endif
contents = char (fread (fid).');
fclose (fid);
## Open output file
copying_filename = "COPYING.html";
fid = fopen (fullfile (packdir, copying_filename), "w");
if (fid < 0)
error ("generate_package_html: couldn't open COPYING file for writing");
endif
## Write output
[header, title, footer] = get_index_header_title_and_footer (options, desc.name, "../");
fprintf (fid, "%s\n", header);
fprintf (fid, "<h2 class=\"tbdesc\">License for '%s' Package</h2>\n\n", desc.name);
fprintf (fid, "<pre>%s</pre>\n\n", contents);
fprintf (fid, "\n%s\n", footer);
fclose (fid);
endif
endfunction

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks