Changeset 29


Ignore:
Timestamp:
03/31/12 18:05:01 (13 years ago)
Author:
bduin
Message:
 
Location:
prextra
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • prextra/prcontent2html.m

    r14 r29  
    11%PRCONTENT2HTML Construct HTML file from PRTools Contents file
    22%
    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
     6function out = prcontent2html(name,recreate,htmldir)
     7
     8if nargin < 3, htmldir = cd; end
     9if nargin < 2 | isempty(recreate), recreate = 0; end
    910
    1011if exist([name '/Contents.m']) == 2
     
    6364                pp = fileparts(file);
    6465                [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>'];
    6667                s = [s '<td>' posttok '</td></tr>'];
    6768        end
     
    6970s = [s '</table>'];
    7071s = [s '</p></body></html>'];
    71 writf([name '.html'],s);
     72writf([fullfile(htmldir,name) '.html'],s);
    7273if nargout > 0
    7374        out = s;
     
    130131return
    131132
    132 function s = commandrefs(r,recreate,subdir)
     133function s = commandrefs(r,recreate,subdir,htmldir)
    133134        if nargin < 2, recreate = 0; end
    134135        if regexp(r,'^ *$')
     
    143144        end
    144145       
    145         if exist(htmlname,'file') == 2
     146        if exist(fullfile(htmldir,htmlname),'file') == 2
    146147                s = [s '<a href="' htmlname '">' tok '</a>, '];
    147148        elseif isempty(tok) | regexp(tok,'^ *')
  • prextra/prhelp2html.m

    r15 r29  
    11%PRHELP2HTML Construct HTML file from help part of PRTools routine
    22%
    3 %               S = PRHELP2HTML(COMMAND,RECREATE,SUBDIR)
     3%               S = PRHELP2HTML(COMMAND,RECREATE,HTMLDIR)
     4%               S = PRHELP2HTML(TOOLBOX,RECREATE,HTMLDIR)
    45%
    56% INPUT
    67%   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 '/'.
    711%   RECREATE   0/1 flag indicating whether non-existing references
    812%              in the SEE ALSO section should be created as well
    9 %   SUBDIR     String with desired sub-directory in which the HTML
     13%   HTMLDIR     String with desired directory in which the HTML
    1014%              file should be stored
    1115%
     
    5660
    5761
    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
     81function out = prhelp2html(name,recreate,htmldir)
     82
     83if nargin < 3, htmldir = cd; end
     84if nargin < 2 | isempty(recreate), recreate = 0; end
     85if 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);
    6789        if nargout > 0
    6890                out = s;
    6991        end
    7092        return;
     93else
     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
    71104end
    72105
     
    78111end
    79112%[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         return
    87 end
     113if isempty(htmldir)
     114        [xx,htmldir] = fileparts(fileparts(file));
     115end
     116% if isempty(strmatch(subdir,char('prtools','@dataset','@datafile','@mapping'),'exact'))
     117% %     disp([name ' Not PRTools'])
     118%       out = [];
     119%       return
     120% end
    88121
    89122disp(file)
     
    295328                state = 'seealso';
    296329                if ~single
    297                         s = [s commandrefs(posttok,recreate)];
     330                        s = [s commandrefs(posttok,recreate,htmldir)];
    298331                end
    299332        else % undefined lines
    300333                if examplestate
    301334                        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>'];
    303336                        else
    304337                                s = [s strrep(code(strrep(r,' ','#$!'),0,3),'#$!','&nbsp;') '<br>'];
     
    316349                                s = [s '<strong><font size="4">' findmakecode(u(3:end)) '</font></strong><br>'];
    317350                        else
    318                                 s = [s commandrefs(u,recreate)];               
     351                                s = [s commandrefs(u,recreate,htmldir)];               
    319352                        end
    320353                elseif tabstartspace && tabstate && (colpos1 > colpos0) ...
     
    377410s = [s '</p>' content_manual '</body></html>'];
    378411[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       
     423if exist([htmldir],'file') ~= 7
     424        mkdir(htmldir);
     425end
     426writf([fullfile(htmldir,name) '.html'],s);
    383427disp([int2str(recreate) ' ' name ' html created'])
    384428if nargout > 0
     
    456500end
    457501
    458 function s = commandrefs(r,recreate)
    459         if nargin < 2, recreate = 0; end
     502function s = commandrefs(r,recreate,htmldir)
     503        if nargin < 3, htmldir = cd; end
     504        if nargin < 2 | isempty(recreate), recreate = 0; end
    460505        s = [];
    461506        r_debug = r;
     
    467512                pp = fileparts(file);
    468513                [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>, '];
    472521                elseif isempty(tok) || ~isempty(regexp(tok,'^ *', 'once' ))
    473522                        ;
     
    554603return
    555604
    556 function run_all_files(command)
    557 
    558 dirs = {'ldc','dataset','datafile','mapping'};
     605function run_all_files(command,dirs,subdir)
     606
     607%dirs = {'ldc','dataset','datafile','mapping'};
    559608for n=1:length(dirs)
    560609        prtools_dir = fileparts(which(dirs{n}));
     
    564613                [qq,name] = fileparts(ff{j});
    565614                if n==1
    566                         feval(command,name); % prtools main commands
     615                        feval(command,name,[],fullfile(subdir,prtools_dirname)); % prtools main commands
    567616                else
    568                         feval(command,fullfile(prtools_dirname,name)); % subdir commands
     617                        feval(command,fullfile(prtools_dirname,name),[],fullfile(subdir,prtools_dirname)); % subdir commands
    569618                end
    570619        end
Note: See TracChangeset for help on using the changeset viewer.