[8eda4e]: inst / generate_html_manual.m Maximize Restore History

Download this file

generate_html_manual.m    131 lines (104 with data), 4.3 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
## 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_html_manual (@var{srcdir}, @var{outdir})
## @end deftypefn
function generate_html_manual (srcdir, outdir = "manual", options = struct ())
## Check input
if (nargin == 0)
print_usage ();
endif
if (!ischar (srcdir))
error ("generate_html_manual: first input argument must be a string");
endif
if (!ischar (outdir))
error ("generate_html_manual: second input argument must be a string");
endif
## If options is a string, call get_html_options
if (ischar (options))
options = get_html_options (options);
elseif (!isstruct (options))
error ("generate_html_manual: third input argument must be a string or a structure");
endif
## Create directories
if (!exist (outdir, "dir"))
mkdir (outdir);
endif
chapter_dir = mk_chapter_dir (outdir, options);
[fun_dir, full_fun_dir] = mk_function_dir (outdir, options);
ds_handler = @(fun) docstring_handler (fun, fun_dir);
## Get file list
file_list = get_txi_files (srcdir);
txi_dir = fileparts (file_list {1});
texi_header = sprintf ("%s\n", get_texi_conf (srcdir));
## Copy images from Octave build
txi_dir = fullfile (srcdir, "doc", "interpreter");
pngs = fullfile (txi_dir, "*.png");
copyfile (pngs, ".");
## Set javascript startup
if (!isfield (options, "body_command"))
if (isfield (options, "manual_body_cmd"))
options.body_command = options.manual_body_cmd;
else
options.body_command = ""; # XXX: do we need this?
endif
endif
## Process each file
for k = 1:length (file_list)
file = file_list {k};
[notused, name] = fileparts (file);
text = txi2reference (file, ds_handler);
text = strcat (texi_header, text);
## Remove numbers from headings as this has been broken since we handle
## each chapter as a seperate file
text = strrep (text, "@chapter", "@unnumbered");
text = strrep (text, "@appendix", "@unnumbered");
text = strrep (text, "@section", "@unnumberedsec");
text = strrep (text, "@subsection", "@unnumberedsubsec");
text = strrep (text, "@subsubsection", "@unnumberedsubsubsec");
## Make sure any @include's work
include = "@include ";
include_with_path = sprintf ("@include %s%s", txi_dir, filesep ());
text = strrep (text, include, include_with_path);
## Add 'op' index
text = strcat ("@defindex op\n\n", text);
## Convert to HTML and write to disc
[header, body, footer] = texi2html (text, options, get_root (outdir, chapter_dir));
fid = fopen (fullfile (chapter_dir, sprintf ("%s.html", name)), "w");
fprintf (fid, "%s\n%s\n%s\n", header, body, footer);
fclose (fid);
endfor
## Move images into the chapter dir
movefile ("*.png", chapter_dir);
###################################################
## Generate reference for individual functions ##
###################################################
## Get INDEX structure
index = txi2index (srcdir);
## Generate the documentation
root = get_root (outdir, full_fun_dir);
for k = 1:length (index)
if (!isempty (index {k}))
printf ("Chapter: %s\n", index {k}.name); fflush (stdout);
generate_package_html (index {k}, full_fun_dir, :, options, root);
%reference = txi2reference (index {k}.filename);
endif
endfor
endfunction
function retval = docstring_handler (fun, fun_dir)
retval = sprintf ("@ifhtml\n@html\n<div class='seefun'>See <a href='../%s/%s.html'>%s</a></div>\n@end html\n@end ifhtml\n",
fun_dir, fun, fun);
endfunction