comparison m-toolbox/html_help/help/create_class_desc/create_methods_desc.m @ 0:f0afece42f48

Import.
author Daniele Nicolodi <nicolodi@science.unitn.it>
date Wed, 23 Nov 2011 19:22:13 +0100
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:f0afece42f48
1 function create_methods_desc(fid, meta_obj, html_filename, indentation_in)
2
3 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4 %%% Go throught the methods of the meta class %%%
5 %%% and collect all public methods %%%
6 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7
8 public_fcn = struct;
9 static_fcn = struct;
10
11 for ii = length(meta_obj.Methods):-1:1
12
13 method = meta_obj.Methods{ii};
14
15 %%% Display only public and not handle methods
16 if strcmp(method.Access, 'public') && ~strcmp(method.DefiningClass.Name, 'handle')
17
18 %%% Devide the methods into 'normal' and 'static' methods
19 if ~method.Static
20 public_fcn.(method.Name) = method.DefiningClass.Name;
21 else
22 static_fcn.(method.Name) = method.DefiningClass.Name;
23 end
24
25 end
26 end
27
28 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
29 %%% Create a struct which fields represent the categories %%%
30 %%% and devide the methods into this fields %%%
31 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
32
33 %%% The struct have the following fields:
34 %%% Operator:
35 %%% Trigonometry:
36 %%% Constructor:
37
38 method_names = fieldnames(public_fcn);
39
40 category_struct = struct();
41
42 for ii = 1:length(method_names)
43
44 try
45
46 %%% Get minfo-object
47 info = feval(sprintf('%s.getInfo',meta_obj.Name), method_names{ii});
48
49 fcn_name = sprintf('%s/%s',public_fcn.(method_names{ii}), method_names{ii});
50 category = strrep(info.mcategory, ' ', '_');
51
52 %%% Add the new category to the struct
53 if ~ismember(category, fieldnames(category_struct))
54 category_struct.(category) = {fcn_name};
55 else
56 category_struct.(category){end+1} = fcn_name;
57 end
58
59 %%% Order the fiels of the structure.
60 category_struct = orderfields(category_struct);
61 catch
62 end
63 end
64
65 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
66 %%% Remove from the default link_box in the class not used categories %%%
67 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
68
69 def_link_box = default_link_box(html_filename);
70 fcn_link_box = {};
71 fcn_categories = sort(fieldnames(category_struct));
72 rr = 1;
73
74 for ii = 1:numel(fcn_categories)
75 idx = strcmpi(fcn_categories{ii}, strrep(def_link_box(:,1), ' ', '_'));
76 if any(idx)
77 fcn_link_box{rr,1} = def_link_box{idx,1};
78 fcn_link_box{rr,2} = def_link_box{idx,2};
79 fcn_link_box{rr,3} = def_link_box{idx,3};
80 else
81 fcn_link_box{rr,1} = fcn_categories{ii};
82 fcn_link_box{rr,2} = sprintf('%s#%s', html_filename, lower(strrep(fcn_categories{ii}, ' ', '_')));
83 fcn_link_box{rr,3} = sprintf('%s methods', fcn_categories{ii});
84 end
85 rr = rr + 1;
86 end
87
88 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
89 %%% Append to the fid the Information of the methods %%%
90 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
91
92 indentation(1:indentation_in) = ' ';
93
94 %%% Headline
95 fprintf(fid, '%s<h2 class="title"><a name="top_methods"/>Methods</h2>\n', indentation);
96
97 %%% Link box
98 create_link_box(fid, indentation_in, fcn_link_box, 'subcategorylist')
99
100 %%% Top of page link
101 create_top_of_page(fid, indentation_in);
102
103 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
104 %%% Create a table for each category %%%
105 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
106
107 categories = fieldnames(category_struct);
108
109 for ii = 1:length(categories)
110 category = categories{ii};
111 category_struct.(category) = sort(category_struct.(category));
112
113 %%% table predefinitions %%%
114 fprintf(fid, '%s<!-- ===== Methods Category: %s ===== -->\n', indentation, category);
115 fprintf(fid, '%s<h3 class="title"><a name="%s"/>%s</h3>\n', indentation, lower(category), strrep(category, '_', ' '));
116 fprintf(fid, '%s<p>\n', indentation);
117 fprintf(fid, '%s <table cellspacing="0" class="body" cellpadding="2" border="0" width="80%%">\n', indentation);
118 fprintf(fid, '%s <colgroup>\n', indentation);
119 fprintf(fid, '%s <col width="15%%"/>\n', indentation);
120 fprintf(fid, '%s <col width="73%%"/>\n', indentation);
121 fprintf(fid, '%s <col width="12%%"/>\n', indentation);
122 fprintf(fid, '%s </colgroup>\n', indentation);
123 fprintf(fid, '%s <thead>\n', indentation);
124 fprintf(fid, '%s <tr valign="top">\n', indentation);
125 fprintf(fid, '%s <th class="categorylist">Methods</th>\n', indentation);
126 fprintf(fid, '%s <th class="categorylist">Description</th>\n', indentation);
127 fprintf(fid, '%s <th class="categorylist">Defined in class</th>\n', indentation);
128 fprintf(fid, '%s </tr>\n', indentation);
129 fprintf(fid, '%s </thead>\n', indentation);
130 fprintf(fid, '%s <tbody>\n', indentation);
131
132 for jj = 1:length(category_struct.(category))
133
134 fcn_name = category_struct.(category){jj};
135
136 %%%%%%%%%% Read the methods file to get the H1 line %%%%%%%%%%
137 fid_open = fopen(which(fcn_name));
138
139 f_line = fgetl(fid_open);
140 fcn_desc = 'No description';
141 while f_line ~= -1
142 f_line = strtrim(f_line);
143 if f_line(1) == '%'
144 fcn_desc = f_line(2:end);
145 fcn_desc = strtrim(fcn_desc);
146 break
147 end
148 f_line = fgetl(fid_open);
149 end
150 fclose(fid_open);
151
152 %%% define the color for each row %%%
153 if mod(jj,2) == 0
154 bgcolor = '';
155 else
156 bgcolor = ' bgcolor="#f3f4f5"';
157 end
158
159 %%% table body %%%
160 fprintf(fid, '%s <!-- %s -->\n', indentation, fcn_name);
161 fprintf(fid, '%s <tr valign="top">\n', indentation);
162 fprintf(fid, '%s <td%s>\n', indentation, bgcolor);
163 %%% Create a special entry for a constructor
164 [t, r] = strtok(fcn_name, '/');
165 if strcmp(t, r(2:end))
166 fprintf(fid, '%s <p><a href="matlab:doc(''%s'')">%s</a></p>\n', indentation, t, fcn_name(length(strtok(fcn_name, '/'))+2:end));
167 else
168 name = fcn_name(length(strtok(fcn_name, '/'))+2:end);
169 fprintf(fid, '%s <p><a href="matlab:doc(''%s'')">%s</a></p>\n', indentation, [meta_obj.Name, '/', name], name);
170 end
171 fprintf(fid, '%s </td>\n', indentation);
172 fprintf(fid, '%s <td%s>\n', indentation, bgcolor);
173 fprintf(fid, '%s <p>%s</p>\n', indentation, fcn_desc);
174 fprintf(fid, '%s </td>\n', indentation);
175 fprintf(fid, '%s <td%s>\n', indentation, bgcolor);
176 fprintf(fid, '%s <p>%s</p>\n', indentation, strtok(fcn_name, '/'));
177 fprintf(fid, '%s </td>\n', indentation);
178 fprintf(fid, '%s </tr>\n', indentation);
179 end
180
181 %%% table end %%%
182 fprintf(fid, '%s </tbody>\n', indentation);
183 fprintf(fid, '%s </table>\n', indentation);
184
185 %%% Back to top of the methods %%%
186 back2m = 'Back to Top of Section';
187
188 fprintf(fid, '%s <!-- ===== Back to Top of Methods ===== -->\n', indentation);
189 fprintf(fid, '%s <a href="#top_methods">\n', indentation);
190 fprintf(fid, '%s <img src="doc_to_top_up.gif" border="0" align="bottom" alt="%s"/>\n', indentation, back2m);
191 fprintf(fid, '%s %s\n', indentation, back2m);
192 fprintf(fid, '%s </a>\n\n', indentation);
193 fprintf(fid, '%s</p>\n\n', indentation);
194 end
195
196 end
197
198
199 function fcn_link_box = default_link_box(html_filename)
200 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
201 %%% Define the link box for the methods %%%
202 %%% link_box{:,1} --> Link name %%%
203 %%% link_box{:,2} --> URL %%%
204 %%% link_box{:,3} --> Link description %%%
205 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
206
207 i = 1;
208 fcn_link_box{i,1} = 'Arithmetic Operator';
209 fcn_link_box{i,2} = [html_filename, '#arithmetic_operator'];
210 fcn_link_box{i,3} = 'Arithmetic Operator';
211
212 i = i+1;
213 fcn_link_box{i,1} = 'Constructor';
214 fcn_link_box{i,2} = [html_filename, '#constructor'];
215 fcn_link_box{i,3} = 'Constructor of this class';
216
217 i = i+1;
218 fcn_link_box{i,1} = 'Converter';
219 fcn_link_box{i,2} = [html_filename, '#converter'];
220 fcn_link_box{i,3} = 'Convertor methods';
221
222 i = i+1;
223 fcn_link_box{i,1} = 'GUI function';
224 fcn_link_box{i,2} = [html_filename, '#gui_function'];
225 fcn_link_box{i,3} = 'GUI function methods';
226
227 i = i+1;
228 fcn_link_box{i,1} = 'Helper';
229 fcn_link_box{i,2} = [html_filename, '#helper'];
230 fcn_link_box{i,3} = 'Helper methods only for internal usage';
231
232 i = i+1;
233 fcn_link_box{i,1} = 'Internal';
234 fcn_link_box{i,2} = [html_filename, '#internal'];
235 fcn_link_box{i,3} = 'Internal methods only for internal usage';
236
237 i = i+1;
238 fcn_link_box{i,1} = 'Input';
239 fcn_link_box{i,2} = [html_filename, '#input'];
240 fcn_link_box{i,3} = 'Input methods';
241
242 i = i+1;
243 fcn_link_box{i,1} = 'MDC1';
244 fcn_link_box{i,2} = [html_filename, '#mdc1'];
245 fcn_link_box{i,3} = 'Mock data challenge 1';
246
247 i = i+1;
248 fcn_link_box{i,1} = 'Operator';
249 fcn_link_box{i,2} = [html_filename, '#operator'];
250 fcn_link_box{i,3} = 'Operator methods';
251
252 i = i+1;
253 fcn_link_box{i,1} = 'Output';
254 fcn_link_box{i,2} = [html_filename, '#output'];
255 fcn_link_box{i,3} = 'Output methods';
256
257 i = i+1;
258 fcn_link_box{i,1} = 'Relational Operator';
259 fcn_link_box{i,2} = [html_filename, '#relational_operator'];
260 fcn_link_box{i,3} = 'Relational operator methods';
261
262 i = i+1;
263 fcn_link_box{i,1} = 'Signal Processing';
264 fcn_link_box{i,2} = [html_filename, '#signal_processing'];
265 fcn_link_box{i,3} = 'Signal processing methods';
266
267 i = i+1;
268 fcn_link_box{i,1} = 'Statespace';
269 fcn_link_box{i,2} = [html_filename, '#statespace'];
270 fcn_link_box{i,3} = 'Statespace methods';
271
272 i = i+1;
273 fcn_link_box{i,1} = 'Trigonometry';
274 fcn_link_box{i,2} = [html_filename, '#trigonometry'];
275 fcn_link_box{i,3} = 'Trigometry methods';
276
277 i = i+1;
278 fcn_link_box{i,1} = 'User defined';
279 fcn_link_box{i,2} = [html_filename, '#user_defined'];
280 fcn_link_box{i,3} = 'User defined methods';
281 end
282
283
284