# HG changeset patch
# User Julien Bect <julien.bect@supelec.fr>
# Date 1408546484 -7200
#      mer. août 20 16:54:44 2014 +0200
# Node ID 27384cfd9f699b8820ce1000229c852ed701b753
# Parent  6f5d8380413b4b10f74b6e9245917ce28950f0d7
Fix broken links on the NEWS, COPYING and overview pages.

* inst/generate_package_html.m: For the NEWS and COPYING pages, use
  the header and footer of the overview page. Also, updates all calls
  to private functions html_help_text, get_index_header_title_and_footer,
  and get_overview_header_title_and_footer (which now have an additional
  argument)
* inst/get_html_options.m: Provide overview_foot and index_footer.
* inst/html_help_text.m: Add additional input arguments pkgroot and pkgname.
* inst/private/get_header_title_and_footer.m: Idem.
* inst/private/get_index_header_title_and_footer.m: Idem.
* inst/private/get_overview_header_title_and_footer.m: Idem.

diff -r 6f5d8380413b -r 27384cfd9f69 inst/generate_package_html.m
--- a/inst/generate_package_html.m	lun. août 18 22:46:53 2014 +0200
+++ b/inst/generate_package_html.m	mer. août 20 16:54:44 2014 +0200
@@ -1,3 +1,4 @@
+## Copyright (C) 2014 Julien Bect <julien.bect@supelec.fr>
 ## Copyright (C) 2008 Soren Hauberg <soren@hauberg.org>
 ##
 ## This program is free software; you can redistribute it and/or modify it
@@ -117,8 +118,6 @@
     endif
   endif
 
-  options.footer = strrep (options.footer, "%package", packname);
-
   num_categories = length (desc.provides);
   anchors = implemented = cell (1, num_categories);
   for k = 1:num_categories
@@ -131,22 +130,17 @@
     implemented {k} = cell (1, num_functions);
     for l = 1:num_functions
       fun = F {l};
-      if (any (fun == filesep ()))
+      if (fun(1) == "@")
         at_dir = fileparts (fun);
         mkdir (fullfile (fundir, at_dir));
-        r = "../../../";
+        pkgroot = "../../";        
       else
-        r = "../../";
+        pkgroot = "../";
       endif
+      root = ["../" pkgroot];
       outname = fullfile (fundir, sprintf ("%s.html", fun));
       try
-        opts = options;
-        ## object methods of @class type will be one level above the others
-        if (strcmp (fun(1), "@"))
-          opts.footer = strrep (opts.footer, 'href="../index.html"',
-                                             'href="../../index.html"');
-        endif
-        html_help_text (fun, outname, opts, r);
+        html_help_text (fun, outname, options, root, pkgroot, packname);
         implemented {k}{l} = true;
       catch
         warning ("marking '%s' as not implemented", fun);
@@ -167,7 +161,8 @@
       error ("generate_package_html: couldn't open overview file for writing");
     endif
   
-    [header, title, footer] = get_overview_header_title_and_footer (options, desc.name, "../");
+    [header, title, footer] = get_overview_header_title_and_footer ...
+      (options, desc.name, "../", "", packname);
 
     fprintf (fid, "%s\n", header);  
     fprintf (fid, "<h2 class=\"tbdesc\">%s</h2>\n\n", desc.name);
@@ -301,9 +296,11 @@
         error ("generate_package_html: couldn't open NEWS file for writing");
       endif
 
+      ## For the NEWS page, use the header and footer of the overview page
+      [header, title, footer] = get_overview_header_title_and_footer ...
+        (options, desc.name, "../", "", packname);
+
       ## Write output
-      [header, title, footer] = get_index_header_title_and_footer (options, desc.name, "../");
-
       fprintf (fid, "%s\n", header);
       fprintf (fid, "<h2 class=\"tbdesc\">NEWS for '%s' Package</h2>\n\n", desc.name);
       fprintf (fid, "<p><a href=\"index.html\">Return to the '%s' package</a></p>\n\n", desc.name);
@@ -351,7 +348,8 @@
     endif
   
     ## Write output
-    [header, title, footer] = get_index_header_title_and_footer (options, desc.name, "../");
+    [header, title, footer] = get_index_header_title_and_footer ...
+      (options, desc.name, "../", "", packname);
 
     fprintf (fid, "%s\n", header);
     fprintf (fid, "<h2 class=\"tbdesc\">%s</h2>\n\n", desc.name);
@@ -516,9 +514,11 @@
       error ("generate_package_html: couldn't open COPYING file for writing");
     endif
   
+    ## For the COPYING page, use the header and footer of the overview page    
+    [header, title, footer] = get_overview_header_title_and_footer ...
+      (options, desc.name, "../", "", packname);
+    
     ## Write output
-    [header, title, footer] = get_index_header_title_and_footer (options, desc.name, "../");
-    
     fprintf (fid, "%s\n", header);
     fprintf (fid, "<h2 class=\"tbdesc\">License for '%s' Package</h2>\n\n", desc.name);
     fprintf (fid, "<p><a href=\"index.html\">Return to the '%s' package</a></p>\n\n", desc.name);
diff -r 6f5d8380413b -r 27384cfd9f69 inst/get_html_options.m
--- a/inst/get_html_options.m	lun. août 18 22:46:53 2014 +0200
+++ b/inst/get_html_options.m	mer. août 20 16:54:44 2014 +0200
@@ -1,3 +1,4 @@
+## Copyright (C) 2014 Julien Bect <julien.bect@supelec.fr>
 ## Copyright (C) 2008 Soren Hauberg <soren@hauberg.org>
 ##
 ## This program is free software; you can redistribute it and/or modify it
@@ -127,11 +128,19 @@
       ## Options for individual function pages
       options.pack_body_cmd = 'onload="javascript:fix_top_menu (); javascript:show_left_menu ();"';
       options.header = strrep (hh, "%date", date ());
-      options.footer = "<p>Package: <a href=\"../index.html\">%package</a></p>\n<div id=\"sf_logo\">\n\
-         <a href=\"http://sourceforge.net\">\
-         <img src=\"http://sourceforge.net/sflogo.php?group_id=2888&amp;type=1\"\
-         width=\"88\" height=\"31\" style=\"border: 0;\" alt=\"SourceForge.net Logo\"/>\
-         </a>\n</div>\n</div>\n</body>\n</html>\n";
+      options.index_footer = ...
+        "<div id=\"sf_logo\">\n\
+           <a href=\"http://sourceforge.net\">\
+           <img src=\"http://sourceforge.net/sflogo.php?group_id=2888&amp;type=1\"\
+            width=\"88\" height=\"31\" style=\"border: 0;\" alt=\"SourceForge.net Logo\"/>\
+           </a>\n\
+         </div>\n</div>\n</body>\n</html>\n";
+      options.overview_footer = [ ...
+        "<p>Package: <a href=\"index.html\">%package</a></p>\n" ...
+        options.index_footer];
+      options.footer = [ ...
+        "<p>Package: <a href=\"%pkgrootindex.html\">%package</a></p>\n" ...
+        options.index_footer];
       options.title = "Function Reference: %name";
       options.include_demos = true;
       options.seealso = @octave_forge_seealso;
diff -r 6f5d8380413b -r 27384cfd9f69 inst/html_help_text.m
--- a/inst/html_help_text.m	lun. août 18 22:46:53 2014 +0200
+++ b/inst/html_help_text.m	mer. août 20 16:54:44 2014 +0200
@@ -1,3 +1,4 @@
+## Copyright (C) 2014 Julien Bect <julien.bect@supelec.fr>
 ## Copyright (C) 2008 Soren Hauberg <soren@hauberg.org>
 ##
 ## This program is free software; you can redistribute it and/or modify it
@@ -42,7 +43,9 @@
 ## @seealso{get_html_options, generate_package_html}
 ## @end deftypefn
 
-function html_help_text (name, outname, options = struct (), root = "")
+function html_help_text ...
+  (name, outname, options = struct (), root = "", pkgroot = "", pkgname = "")
+  
   ## Get the help text of the function
   [text, format] = get_help_text (name);
   
@@ -94,7 +97,8 @@
   endswitch
 
   ## Read 'options' input argument
-  [header, title, footer] = get_header_title_and_footer (options, name, root);
+  [header, title, footer] = get_header_title_and_footer ...
+    (options, name, root, pkgroot, pkgname);
   
   ## Add demo:// links if requested
   if (isfield (options, "include_demos") && options.include_demos)
diff -r 6f5d8380413b -r 27384cfd9f69 inst/private/get_header_title_and_footer.m
--- a/inst/private/get_header_title_and_footer.m	lun. août 18 22:46:53 2014 +0200
+++ b/inst/private/get_header_title_and_footer.m	mer. août 20 16:54:44 2014 +0200
@@ -1,3 +1,4 @@
+## Copyright (C) 2014 Julien Bect <julien.bect@supelec.fr>
 ## Copyright (C) 2008 Soren Hauberg <soren@hauberg.org>
 ##
 ## This program is free software; you can redistribute it and/or modify it
@@ -14,7 +15,9 @@
 ## along with this program; see the file COPYING.  If not, see
 ## <http://www.gnu.org/licenses/>.
 
-function [header, title, footer] = get_header_title_and_footer (options, name = "", root = "")
+function [header, title, footer] = get_header_title_and_footer ...
+  (options, name = "", root = "", pkgroot = "", pkgname = "")
+  
   if (isfield (options, "header"))
     header = options.header;
   else
@@ -49,5 +52,10 @@
     footer = options.footer;
   else
     footer = "</body></html>";
-  endif  
+  endif
+  
+  footer = strrep (footer, "%root", root);
+  footer = strrep (footer, "%pkgroot", pkgroot);
+  footer = strrep (footer, "%package", pkgname);
+  
 endfunction
diff -r 6f5d8380413b -r 27384cfd9f69 inst/private/get_index_header_title_and_footer.m
--- a/inst/private/get_index_header_title_and_footer.m	lun. août 18 22:46:53 2014 +0200
+++ b/inst/private/get_index_header_title_and_footer.m	mer. août 20 16:54:44 2014 +0200
@@ -1,3 +1,4 @@
+## Copyright (C) 2014 Julien Bect <julien.bect@supelec.fr>
 ## Copyright (C) 2008 Soren Hauberg <soren@hauberg.org>
 ##
 ## This program is free software; you can redistribute it and/or modify it
@@ -14,7 +15,9 @@
 ## along with this program; see the file COPYING.  If not, see
 ## <http://www.gnu.org/licenses/>.
 
-function [header, title, footer] = get_index_header_title_and_footer (options, name, root = "")
+function [header, title, footer] = get_index_header_title_and_footer ...
+  (options, name, root = "", pkgroot = "", pkgname = "")
+  
   if (isfield (options, "index_header"))
     header = options.index_header;
   elseif (isfield (options, "header"))
@@ -51,12 +54,17 @@
     header = strrep (header, "%title", title);
   endif
 
-    ## Write footer of index page
-    if (isfield (options, "index_footer"))
-      footer = options.index_footer;
-    elseif (isfield (options, "footer"))
-      footer = options.footer;
-    else
-      footer = "</body></html>";
-    endif
+  ## Write footer of index page
+  if (isfield (options, "index_footer"))
+    footer = options.index_footer;
+  elseif (isfield (options, "footer"))
+    footer = options.footer;
+  else
+    footer = "</body></html>";
+  endif
+
+  footer = strrep (footer, "%root", root);
+  footer = strrep (footer, "%pkgroot", pkgroot);
+  footer = strrep (footer, "%package", pkgname);
+  
 endfunction
diff -r 6f5d8380413b -r 27384cfd9f69 inst/private/get_overview_header_title_and_footer.m
--- a/inst/private/get_overview_header_title_and_footer.m	lun. août 18 22:46:53 2014 +0200
+++ b/inst/private/get_overview_header_title_and_footer.m	mer. août 20 16:54:44 2014 +0200
@@ -1,3 +1,4 @@
+## Copyright (C) 2014 Julien Bect <julien.bect@supelec.fr>
 ## Copyright (C) 2008 Soren Hauberg <soren@hauberg.org>
 ##
 ## This program is free software; you can redistribute it and/or modify it
@@ -14,7 +15,9 @@
 ## along with this program; see the file COPYING.  If not, see
 ## <http://www.gnu.org/licenses/>.
 
-function [header, title, footer] = get_overview_header_title_and_footer (options, name, root = "")
+function [header, title, footer] = get_overview_header_title_and_footer ...
+  (options, name, root = "", pkgroot = "", pkgname = "")
+  
   if (isfield (options, "overview_header"))
     header = options.overview_header;
   elseif (isfield (options, "header"))
@@ -28,6 +31,7 @@
   endif
   
   header = strrep (header, "%root", root);
+  
   if (isfield (options, "pack_body_cmd"))
     header = strrep (header, "%body_command", options.pack_body_cmd);
   elseif (isfield (options, "body_command"))
@@ -51,12 +55,18 @@
     header = strrep (header, "%title", title);
   endif
 
-    ## Write footer of overview page
-    if (isfield (options, "overview_footer"))
-      footer = options.overview_footer;
-    elseif (isfield (options, "footer"))
-      footer = options.footer;
-    else
-      footer = "</body></html>";
-    endif
+  ## Write footer of overview page
+  if (isfield (options, "overview_footer"))
+    footer = options.overview_footer;
+  elseif (isfield (options, "footer"))
+    footer = options.footer;
+  else
+    footer = "</body></html>";
+  endif
+  
+  footer = strrep (footer, "%root", root);
+  footer = strrep (footer, "%pkgroot", pkgroot);
+  footer = strrep (footer, "%package", pkgname);
+  
 endfunction
+
