@@ -111,15 +111,90 @@ function publishTask(context)
111111% References:
112112% https://www.mathworks.com/help/matlab/matlab_prog/display-custom-documentation.html
113113% https://www.mathworks.com/help/matlab/matlab_prog/create-a-help-summary-contents-m.html
114-
115- pkg_root = fullfile(context .Plan .RootFolder , ' +stdlib ' );
114+ pkg_name = ' +stdlib ' ;
115+ pkg_root = fullfile(context .Plan .RootFolder , pkg_name );
116116html_dir = fullfile(pkg_root , ' html' );
117- styleFile = fullfile(context .Plan .RootFolder , " private/style.css" );
117+ contents = fullfile(pkg_root , " Contents.m" );
118+
119+ % styleFile = fullfile(context.Plan.RootFolder, "private/style.css");
120+ %
121+ % readme = publish_gen_index_html("stdlib", ...
122+ % "A standard library of functions for Matlab.", ...
123+ % "https://github.com/geospace-code/matlab-stdlib", ...
124+ % html_dir, styleFile);
125+
126+ pkg = what(pkg_root );
127+ funcs = string(pkg .m ).' ;
128+ pn = extractAfter(pkg_name , 1 );
129+
130+ txt = [" %% Standard library of functions for MATLAB" , " %" ];
131+
132+ repo = gitrepo(pkg .path );
133+ txt(end + 1 ) = " % Git branch / commit: " + repo .CurrentBranch .Name + " " + ...
134+ repo.LastCommit.ID{1 }(1 : 8 ) + " " + string(repo .LastCommit .CommitterDate );
135+
136+
137+ txt = [txt , " %" , " % <https://github.com/geospace-code/matlab-stdlib GitHub Source Code>" , " %" , ...
138+ " % Library Functions:" , " %" , ...
139+ " % <html>" , " % <table>" , " % <tr><th>Function</th> <th>Description</th> <th>Backends</th></tr>" ];
140+
141+ writelines(join(txt , newline ), contents , WriteMode= " overwrite" )
142+
143+
144+ Nbe = struct(dotnet = 0 , java= 0 , perl= 0 , python= 0 , sys= 0 , native= 0 , legacy= 0 , top_level= 0 );
145+
146+ for m = funcs
147+ Nbe.top_level = Nbe .top_level + 1 ;
148+
149+ if m == " Contents.m"
150+ continue
151+ end
152+
153+ [~ , name ] = fileparts(m );
154+
155+ doc_fn = publish(pn + " ." + name , evalCode= false , outputDir= html_dir );
156+ disp(doc_fn )
157+
158+ % inject summary for each function
159+ help_txt = splitlines(string(help(pn + " ." + name )));
160+ words = split(strip(help_txt(1 )), " " );
161+
162+ % error if no docstring
163+ fname = words(1 );
164+ assert(endsWith(fname , name , IgnoreCase= true ), " fname %s does not match name %s \nis there a docstring at the top of the .m file?" , fname , name )
165+
166+ line = " % <tr><td><a href=" + name + " .html>" + fname + " </a></td><td>" ;
167+ if numel(words ) > 1
168+ line = join([line , words(2 : end ).' ]);
169+ end
170+
171+ req = " " ;
172+ for bkd = string(pkg .packages ).'
173+ if ~isempty(which(pn + " ." + bkd + " ." + name ))
174+ Nbe.(bkd ) = Nbe.(bkd ) + 1 ;
175+ req = req + " " + bkd ;
176+ end
177+ end
178+
179+ line = line + " </td> <td>" + req + " </td></tr>" ;
180+
181+ writelines(line , contents , WriteMode= " append" )
182+ end
183+
184+ writelines(" % </table></html>" + newline + " %" , contents , WriteMode= " append" )
185+
186+ line = " % Function counts:" + newline + " %" ;
187+
188+ for n = string(fieldnames(Nbe )).'
189+ line(end + 1 ) = " % * " + n + " " + string(Nbe.(n )); % #ok<AGROW>
190+ end
191+
192+ writelines(join(line , newline ), contents , WriteMode= " append" )
193+
194+ readme = publish(pn + " .Contents" , evalCode= false , showCode= false );
118195
119- readme = publish_gen_index_html(" stdlib" , ...
120- " A standard library of functions for Matlab." , ...
121- " https://github.com/geospace-code/matlab-stdlib" , ...
122- html_dir , styleFile );
196+ movefile(readme , html_dir + " /index.html" );
197+ readme = html_dir + " /index.html" ;
123198
124199fprintf(" \nweb('file:///%s') to view docs\n\n" , readme );
125200end
0 commit comments