This repository has been archived by the owner on Nov 16, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
make_docs.m
78 lines (67 loc) · 2.41 KB
/
make_docs.m
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
% Generate documentation.
package_name = '+mypackage';
output_dir = 'helpfiles';
examples_dir = 'examples';
package_dir = ['.' filesep package_name];
% Create output directory
mkdir(output_dir);
disp('Generating toolbox API reference...')
toolbox_filenames = what(package_dir);
toolbox_filenames = toolbox_filenames.m;
old_dir = cd;
cd(package_dir);
for ind = 1:length(toolbox_filenames)
filename = toolbox_filenames{ind};
disp(['Converting ', filename, ' to HTML (', int2str(ind), '/', int2str(length(toolbox_filenames)), ')'])
publish(filename, ...
'format', 'html', ...
'outputDir', ['..' filesep output_dir], ...
'evalCode', false, ...
'showCode', false);
end
cd(old_dir);
disp('Generating toolbox example pages...')
addpath(examples_dir, '.')
example_filenames = what(examples_dir);
example_filenames = example_filenames.m;
old_dir = cd;
cd(package_dir);
for ind = 1:length(example_filenames)
filename = example_filenames{ind};
disp(['Converting ', filename, ' to HTML (', int2str(ind), '/', int2str(length(example_filenames)), ')'])
publish(filename, ...
'format', 'html', ...
'outputDir', ['..' filesep output_dir], ...
'evalCode', true, ...
'showCode', true);
end
cd(old_dir);
% Before constructing table of contents, remove root doc page
% as it is manually included at the top level
toolbox_filenames(contains(toolbox_filenames, 'index.m')) = [];
% Generate helptoc.xml file from list of .m source files
addToXML('<?xml version=''1.0'' encoding="utf-8"?>');
addToXML('<toc version="2.0">');
addToXML('<tocitem target="index.html">Sample MATLAB toolbox');
% Add links to API reference
addToXML('<tocitem target="">Reference');
for ind = 1:length(toolbox_filenames)
[~, func_name, ~] = fileparts(toolbox_filenames{ind});
addToXML(['<tocitem target="' func_name '.html">' func_name '</tocitem>']);
end
addToXML('</tocitem>');
% Add links to examples
addToXML('<tocitem target="">Examples');
for ind = 1:length(example_filenames)
[~, example_name, ~] = fileparts(example_filenames{ind});
addToXML(['<tocitem target="' example_name '.html">' example_name '</tocitem>']);
end
addToXML('</tocitem>');
addToXML('</tocitem>');
addToXML('</toc>');
% convenience function to call writelines
function addToXML(line)
output_dir = 'helpfiles';
filename = [output_dir filesep 'helptoc.xml'];
writelines(line, filename, 'WriteMode','append');
end