Changeset 29
- Timestamp:
- 03/31/12 18:05:01 (13 years ago)
- Location:
- prextra
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
prextra/prcontent2html.m
r14 r29 1 1 %PRCONTENT2HTML Construct HTML file from PRTools Contents file 2 2 % 3 % PRCONTENT2HTML(NAME,RECREATE) 4 5 6 function out = prcontent2html(name,recreate) 7 8 if nargin < 2, recreate = 0; end 3 % PRCONTENT2HTML(NAME,RECREATE,HTMLDIR) 4 5 6 function out = prcontent2html(name,recreate,htmldir) 7 8 if nargin < 3, htmldir = cd; end 9 if nargin < 2 | isempty(recreate), recreate = 0; end 9 10 10 11 if exist([name '/Contents.m']) == 2 … … 63 64 pp = fileparts(file); 64 65 [pp2,subdir] = fileparts(pp); 65 s = [s '<tr> <td width="100" valign="top">' commandrefs(tok,recreate,subdir ) '</td>'];66 s = [s '<tr> <td width="100" valign="top">' commandrefs(tok,recreate,subdir,htmldir) '</td>']; 66 67 s = [s '<td>' posttok '</td></tr>']; 67 68 end … … 69 70 s = [s '</table>']; 70 71 s = [s '</p></body></html>']; 71 writf([ name'.html'],s);72 writf([fullfile(htmldir,name) '.html'],s); 72 73 if nargout > 0 73 74 out = s; … … 130 131 return 131 132 132 function s = commandrefs(r,recreate,subdir )133 function s = commandrefs(r,recreate,subdir,htmldir) 133 134 if nargin < 2, recreate = 0; end 134 135 if regexp(r,'^ *$') … … 143 144 end 144 145 145 if exist( htmlname,'file') == 2146 if exist(fullfile(htmldir,htmlname),'file') == 2 146 147 s = [s '<a href="' htmlname '">' tok '</a>, ']; 147 148 elseif isempty(tok) | regexp(tok,'^ *') -
prextra/prhelp2html.m
r15 r29 1 1 %PRHELP2HTML Construct HTML file from help part of PRTools routine 2 2 % 3 % S = PRHELP2HTML(COMMAND,RECREATE,SUBDIR) 3 % S = PRHELP2HTML(COMMAND,RECREATE,HTMLDIR) 4 % S = PRHELP2HTML(TOOLBOX,RECREATE,HTMLDIR) 4 5 % 5 6 % INPUT 6 7 % COMMAND String with PRTools command, default: all prtools m-files 8 % TOOLBOX Name of the toolbox to be handled, default PRTOOLS. 9 % Toolbox should be in the bath in in this call the last 10 % character should be a '/'. 7 11 % RECREATE 0/1 flag indicating whether non-existing references 8 12 % in the SEE ALSO section should be created as well 9 % SUBDIR String with desired sub-directory in which the HTML13 % HTMLDIR String with desired directory in which the HTML 10 14 % file should be stored 11 15 % … … 56 60 57 61 58 59 60 function out = prhelp2html(name,recreate,subdir) 61 62 if nargin < 3, subdir = []; end 63 if nargin < 2 || isempty(recreate), recreate = 0; end 64 if nargin < 1 65 run_all_files(mfilename); 66 s = prcontent2html('prtools'); 62 % BEFORE YOU START TO DEBUG, READ THIS 63 % This routine was original intended to work on the prtools dir only. 64 % Later it was somewhat changed in order to handle files in prdatasets, 65 % prdatafiles and possibly distools and dd_tools as well. Only for 66 % prtools the subdir structure (with the @dataset, @datafile, @mapping 67 % sub dirs) is recognized, and only if the first parameter, COMMAND, is 68 % empty. 69 % 70 % The Contents files have a special layout. It is handled by prcontent2html 71 % in case of PRTools, but for other toolboxes it most likely doesn't work. 72 % 73 % The formatting rules of the PRTools help are strict. Don't try to relax 74 % them in the below code, but change the help-text if you are not satisfied 75 % with the result. Especially avoid ' ' (double spaces) where they are not 76 % needed as the conversion jumps into a table-mode as soon as they are 77 % encountered. 78 % 79 % Bob Duin, April 2011 80 81 function out = prhelp2html(name,recreate,htmldir) 82 83 if nargin < 3, htmldir = cd; end 84 if nargin < 2 | isempty(recreate), recreate = 0; end 85 if nargin < 1 | isempty(name) % default is prtools 86 dirs = {'ldc','dataset','datafile','mapping'}; 87 run_all_files(mfilename,dirs,htmldir); 88 s = prcontent2html('prtools',[],htmldir); 67 89 if nargout > 0 68 90 out = s; 69 91 end 70 92 return; 93 else 94 if strcmp(name(end),'/') & exist(name(1:end-1),'dir') == 7 95 name = name(1:end-1); 96 dirs = {fullfile(name,'Contents.m')}; 97 run_all_files(mfilename,dirs,htmldir); 98 s = prcontent2html(name,[],htmldir); % does not work usually 99 if nargout > 0 100 out = s; 101 end 102 return 103 end 71 104 end 72 105 … … 78 111 end 79 112 %[pp,name] = fileparts(file); 80 if isempty( subdir)81 [xx, subdir] = fileparts(fileparts(file));82 end 83 if isempty(strmatch(subdir,char('prtools','@dataset','@datafile','@mapping'),'exact'))84 % disp([name ' Not PRTools'])85 out = [];86 return87 end113 if isempty(htmldir) 114 [xx,htmldir] = fileparts(fileparts(file)); 115 end 116 % if isempty(strmatch(subdir,char('prtools','@dataset','@datafile','@mapping'),'exact')) 117 % % disp([name ' Not PRTools']) 118 % out = []; 119 % return 120 % end 88 121 89 122 disp(file) … … 295 328 state = 'seealso'; 296 329 if ~single 297 s = [s commandrefs(posttok,recreate )];330 s = [s commandrefs(posttok,recreate,htmldir)]; 298 331 end 299 332 else % undefined lines 300 333 if examplestate 301 334 if length(u) > 3 && strcmpi(u(1:4),'see ') 302 s = [s '</p>' commandrefs(u(5:end),recreate ) '<p>'];335 s = [s '</p>' commandrefs(u(5:end),recreate,fileparts(htmldir)) '<p>']; 303 336 else 304 337 s = [s strrep(code(strrep(r,' ','#$!'),0,3),'#$!',' ') '<br>']; … … 316 349 s = [s '<strong><font size="4">' findmakecode(u(3:end)) '</font></strong><br>']; 317 350 else 318 s = [s commandrefs(u,recreate )];351 s = [s commandrefs(u,recreate,htmldir)]; 319 352 end 320 353 elseif tabstartspace && tabstate && (colpos1 > colpos0) ... … … 377 410 s = [s '</p>' content_manual '</body></html>']; 378 411 [qq,name] = fileparts(name); % allows for names like dataset/show 379 if exist(['./' subdir],'file') ~= 7 380 mkdir(subdir); 381 end 382 writf([fullfile(subdir,name) '.html'],s); 412 % if exist(fullfile(htmldir,name),'file') == 2 413 % htmlname = fullfile(htmldir,name); 414 % else 415 % %htmlname = [tok '.html']; 416 % file = which(name); 417 % pp = fileparts(file); 418 % [qq,subdir] = fileparts(pp); 419 % htmldir = fullfile(fileparts(htmldir),subdir); 420 % htmlname = fullfile(htmldir,name); 421 % end 422 423 if exist([htmldir],'file') ~= 7 424 mkdir(htmldir); 425 end 426 writf([fullfile(htmldir,name) '.html'],s); 383 427 disp([int2str(recreate) ' ' name ' html created']) 384 428 if nargout > 0 … … 456 500 end 457 501 458 function s = commandrefs(r,recreate) 459 if nargin < 2, recreate = 0; end 502 function s = commandrefs(r,recreate,htmldir) 503 if nargin < 3, htmldir = cd; end 504 if nargin < 2 | isempty(recreate), recreate = 0; end 460 505 s = []; 461 506 r_debug = r; … … 467 512 pp = fileparts(file); 468 513 [qq,subdir] = fileparts(pp); 469 htmlname = fullfile(subdir,htmlname); 470 if exist(htmlname,'file') == 2 471 s = [s '<a href="../' htmlname '">' tok '</a>, ']; 514 % htmlname = fullfile(subdir,htmlname); 515 htmlfullname1 = fullfile(htmldir,htmlname); 516 htmlfullname2 = fullfile(fullfile(fileparts(htmldir),subdir),htmlname); 517 if exist(htmlfullname1,'file') == 2 % check whether command is in htmldir 518 s = [s '<a href="./' htmlname '">' tok '</a>, ']; 519 elseif exist(htmlfullname2,'file') == 2 % exists elsewhere? 520 s = [s '<a href="../' fullfile(subdir,htmlname) '">' tok '</a>, ']; 472 521 elseif isempty(tok) || ~isempty(regexp(tok,'^ *', 'once' )) 473 522 ; … … 554 603 return 555 604 556 function run_all_files(command )557 558 dirs = {'ldc','dataset','datafile','mapping'};605 function run_all_files(command,dirs,subdir) 606 607 %dirs = {'ldc','dataset','datafile','mapping'}; 559 608 for n=1:length(dirs) 560 609 prtools_dir = fileparts(which(dirs{n})); … … 564 613 [qq,name] = fileparts(ff{j}); 565 614 if n==1 566 feval(command,name ); % prtools main commands615 feval(command,name,[],fullfile(subdir,prtools_dirname)); % prtools main commands 567 616 else 568 feval(command,fullfile(prtools_dirname,name) ); % subdir commands617 feval(command,fullfile(prtools_dirname,name),[],fullfile(subdir,prtools_dirname)); % subdir commands 569 618 end 570 619 end
Note: See TracChangeset
for help on using the changeset viewer.