# HG changeset patch
# User Julien Bect <julien.bect@supelec.fr>
# Date 1408551724 -7200
#      mer. août 20 18:22:04 2014 +0200
# Node ID eae7f6eecac670c29887e5693012a0e74f4e94f0
# Parent  27384cfd9f699b8820ce1000229c852ed701b753
Overhaul private functions related to headers, footers, etc.

* inst/private/get_header_title_and_footer.m: Make it a "generic"
  function that can handle all page types (index, overview,
  functions).
* inst/private/get_index_header_title_and_footer.m: Not needed
  anymore, use get_header_title_and_footer instead.
* inst/private/get_overview_header_title_and_footer.m: Not needed
  anymore, use get_header_title_and_footer instead.
* inst/generate_alphabet.m: Use get_header_title_and_footer.
* inst/generate_operators.m: Use get_header_title_and_footer.
* inst/generate_package_html.m: Use get_header_title_and_footer.
  Rename pack_body_cmd to overview_body_command.
* inst/get_html_options.m: Rename pack_body_cmd to
  overview_body_command.
* inst/html_help_text.m: Adapt to the new syntax for
  get_header_title_and_footer.m (additional input argument).
* inst/texi2html.m: Adapt to the new syntax for
  get_header_title_and_footer.m (additional input argument).
* inst/private/get_default_body_command.m: New function that
  provides a default "body_command" value.
* inst/private/get_default_footer.m: New function that
  provides a default "footer" value.
* inst/private/get_default_header.m: New function that
  provides a default "header" value.
* inst/private/get_default_title.m: New function that
  provides a default "title" value.
* inst/private/get_feature.m: New function that returns the value
  of a given feature (header, footer, etc.) for a given page_type.

diff -r 27384cfd9f69 -r eae7f6eecac6 inst/generate_alphabet.m
--- a/inst/generate_alphabet.m	mer. août 20 16:54:44 2014 +0200
+++ b/inst/generate_alphabet.m	mer. août 20 18:22:04 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
@@ -97,7 +98,7 @@
   
   options.body_command = 'onload="javascript:fix_top_menu (); javascript:alphabetical_menu ();"';
   title = sprintf ("Alphabetical List of Functions: %s", current);
-  [header, title, footer] = get_overview_header_title_and_footer (options, title, "../");
+  [header, title, footer] = get_header_title_and_footer ("overview", options, title, "../");
 
   fprintf (fid, "%s\n", header);
   fprintf (fid, "<h2><a name=\"%s\">%s</a></h2>\n<div>\n", current, current);
diff -r 27384cfd9f69 -r eae7f6eecac6 inst/generate_operators.m
--- a/inst/generate_operators.m	mer. août 20 16:54:44 2014 +0200
+++ b/inst/generate_operators.m	mer. août 20 18:22:04 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
@@ -41,7 +42,7 @@
   ## Generate html
   title = "Operators and Keywords";
   options.body_command = 'onload="javascript:fix_top_menu ();"';
-  [header, title, footer] = get_overview_header_title_and_footer (options, title);
+  [header, title, footer] = get_header_title_and_footer ("overview", options, title);
 
   fid = fopen (name, "w");
   if (fid < 0)
diff -r 27384cfd9f69 -r eae7f6eecac6 inst/generate_package_html.m
--- a/inst/generate_package_html.m	mer. août 20 16:54:44 2014 +0200
+++ b/inst/generate_package_html.m	mer. août 20 18:22:04 2014 +0200
@@ -111,8 +111,8 @@
 
   ## Set javascript startup
   if (!isfield (options, "body_command"))
-    if (isfield (options, "pack_body_cmd"))
-      options.body_command = options.pack_body_cmd;
+    if (isfield (options, "overview_body_command"))
+      options.body_command = options.overview_body_command;
     else
       options.body_command = "";
     endif
@@ -161,8 +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, "../", "", packname);
+    [header, title, footer] = get_header_title_and_footer ...
+      ("overview", options, desc.name, "../", "", packname);
 
     fprintf (fid, "%s\n", header);  
     fprintf (fid, "<h2 class=\"tbdesc\">%s</h2>\n\n", desc.name);
@@ -297,8 +297,8 @@
       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);
+      [header, title, footer] = get_header_title_and_footer ...
+        ("overview", options, desc.name, "../", "", packname);
 
       ## Write output
       fprintf (fid, "%s\n", header);
@@ -348,8 +348,8 @@
     endif
   
     ## Write output
-    [header, title, footer] = get_index_header_title_and_footer ...
-      (options, desc.name, "../", "", packname);
+    [header, title, footer] = get_header_title_and_footer ...
+      ("index", options, desc.name, "../", "", packname);
 
     fprintf (fid, "%s\n", header);
     fprintf (fid, "<h2 class=\"tbdesc\">%s</h2>\n\n", desc.name);
@@ -515,8 +515,8 @@
     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);
+    [header, title, footer] = get_header_title_and_footer ...
+      ("overview", options, desc.name, "../", "", packname);
     
     ## Write output
     fprintf (fid, "%s\n", header);
diff -r 27384cfd9f69 -r eae7f6eecac6 inst/get_html_options.m
--- a/inst/get_html_options.m	mer. août 20 16:54:44 2014 +0200
+++ b/inst/get_html_options.m	mer. août 20 18:22:04 2014 +0200
@@ -126,7 +126,7 @@
       options.include_alpha = true;
     
       ## Options for individual function pages
-      options.pack_body_cmd = 'onload="javascript:fix_top_menu (); javascript:show_left_menu ();"';
+      options.overview_body_command = 'onload="javascript:fix_top_menu (); javascript:show_left_menu ();"';
       options.header = strrep (hh, "%date", date ());
       options.index_footer = ...
         "<div id=\"sf_logo\">\n\
diff -r 27384cfd9f69 -r eae7f6eecac6 inst/html_help_text.m
--- a/inst/html_help_text.m	mer. août 20 16:54:44 2014 +0200
+++ b/inst/html_help_text.m	mer. août 20 18:22:04 2014 +0200
@@ -98,7 +98,7 @@
 
   ## Read 'options' input argument
   [header, title, footer] = get_header_title_and_footer ...
-    (options, name, root, pkgroot, pkgname);
+    ("function", options, name, root, pkgroot, pkgname);
   
   ## Add demo:// links if requested
   if (isfield (options, "include_demos") && options.include_demos)
diff -r 27384cfd9f69 -r eae7f6eecac6 inst/private/get_default_body_command.m
--- /dev/null	jeu. janv. 01 00:00:00 1970 +0000
+++ b/inst/private/get_default_body_command.m	mer. août 20 18:22:04 2014 +0200
@@ -0,0 +1,23 @@
+## Copyright (C) 2014 Julien Bect
+## 
+## This program is free software; you can redistribute it and/or modify it
+## under the terms of the GNU General Public License as published by
+## the Free Software Foundation; either version 3 of the License, or
+## (at your option) any later version.
+## 
+## This program is distributed in the hope that it will be useful,
+## but WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+## GNU General Public License for more details.
+## 
+## You should have received a copy of the GNU General Public License
+## along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+## Author: Julien Bect <bect@bect-laptop>
+## Created: 2014-08-20
+
+function body_command = get_default_body_command (page_type)
+
+body_command = "";
+
+endfunction
diff -r 27384cfd9f69 -r eae7f6eecac6 inst/private/get_default_footer.m
--- /dev/null	jeu. janv. 01 00:00:00 1970 +0000
+++ b/inst/private/get_default_footer.m	mer. août 20 18:22:04 2014 +0200
@@ -0,0 +1,24 @@
+## Copyright (C) 2014 Julien Bect
+## Copyright (C) 2008 Soren Hauberg <soren@hauberg.org>
+## 
+## This program is free software; you can redistribute it and/or modify it
+## under the terms of the GNU General Public License as published by
+## the Free Software Foundation; either version 3 of the License, or
+## (at your option) any later version.
+## 
+## This program is distributed in the hope that it will be useful,
+## but WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+## GNU General Public License for more details.
+## 
+## You should have received a copy of the GNU General Public License
+## along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+## Author: Julien Bect <bect@bect-laptop>
+## Created: 2014-08-20
+
+function footer = get_default_footer (page_type, options)
+
+footer = "</body></html>";
+
+endfunction
diff -r 27384cfd9f69 -r eae7f6eecac6 inst/private/get_default_header.m
--- /dev/null	jeu. janv. 01 00:00:00 1970 +0000
+++ b/inst/private/get_default_header.m	mer. août 20 18:22:04 2014 +0200
@@ -0,0 +1,24 @@
+## Copyright (C) 2014 Julien Bect
+## Copyright (C) 2008 Soren Hauberg <soren@hauberg.org>
+## 
+## This program is free software; you can redistribute it and/or modify it
+## under the terms of the GNU General Public License as published by
+## the Free Software Foundation; either version 3 of the License, or
+## (at your option) any later version.
+## 
+## This program is distributed in the hope that it will be useful,
+## but WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+## GNU General Public License for more details.
+## 
+## You should have received a copy of the GNU General Public License
+## along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+## Author: Julien Bect <bect@bect-laptop>
+## Created: 2014-08-20
+
+function header = get_default_header (page_type, options)
+
+header = "<html><head><title></title><head><body>";
+
+endfunction
diff -r 27384cfd9f69 -r eae7f6eecac6 inst/private/get_default_title.m
--- /dev/null	jeu. janv. 01 00:00:00 1970 +0000
+++ b/inst/private/get_default_title.m	mer. août 20 18:22:04 2014 +0200
@@ -0,0 +1,41 @@
+## Copyright (C) 2014 Julien Bect
+## Copyright (C) 2008 Soren Hauberg <soren@hauberg.org>
+## 
+## This program is free software; you can redistribute it and/or modify it
+## under the terms of the GNU General Public License as published by
+## the Free Software Foundation; either version 3 of the License, or
+## (at your option) any later version.
+## 
+## This program is distributed in the hope that it will be useful,
+## but WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+## GNU General Public License for more details.
+## 
+## You should have received a copy of the GNU General Public License
+## along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+## Author: Julien Bect <bect@bect-laptop>
+## Created: 2014-08-20
+
+function title = get_default_title (page_type)
+
+switch page_type
+
+  case 'overview'
+    title = "List of Functions for the '%name' package";
+
+  case 'index'
+    title = "The '%name' package";  
+    
+  case 'function'
+    title = "%name";
+  
+  otherwise
+    error (sprintf ("Unknown page_type: %s", page_type));
+    
+endswitch
+    
+## Note: %name stands for the package name in the first two cases, and for
+## the function name in the last one. There is a risk of confusion. 
+
+endfunction
diff -r 27384cfd9f69 -r eae7f6eecac6 inst/private/get_feature.m
--- /dev/null	jeu. janv. 01 00:00:00 1970 +0000
+++ b/inst/private/get_feature.m	mer. août 20 18:22:04 2014 +0200
@@ -0,0 +1,32 @@
+## Copyright (C) 2014 Julien Bect
+## Copyright (C) 2008 Soren Hauberg <soren@hauberg.org>
+## 
+## This program is free software; you can redistribute it and/or modify it
+## under the terms of the GNU General Public License as published by
+## the Free Software Foundation; either version 3 of the License, or
+## (at your option) any later version.
+## 
+## This program is distributed in the hope that it will be useful,
+## but WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+## GNU General Public License for more details.
+## 
+## You should have received a copy of the GNU General Public License
+## along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+## Author: Julien Bect <bect@bect-laptop>
+## Created: 2014-08-20
+
+function s = get_feature (page_type, feature, options)
+
+page_specific_feature = [page_type "_" feature];
+
+if (isfield (options, page_specific_feature))
+  s = options.(page_specific_feature);
+elseif (isfield (options, feature))
+  s = options.(feature);
+else
+  s = eval (sprintf ('get_default_%s ()', feature));
+endif
+
+endfunction
diff -r 27384cfd9f69 -r eae7f6eecac6 inst/private/get_header_title_and_footer.m
--- a/inst/private/get_header_title_and_footer.m	mer. août 20 16:54:44 2014 +0200
+++ b/inst/private/get_header_title_and_footer.m	mer. août 20 18:22:04 2014 +0200
@@ -16,31 +16,24 @@
 ## <http://www.gnu.org/licenses/>.
 
 function [header, title, footer] = get_header_title_and_footer ...
-  (options, name = "", root = "", pkgroot = "", pkgname = "")
+  (page_type, options, name, root = "", pkgroot = "", pkgname = "")
   
-  if (isfield (options, "header"))
-    header = options.header;
-  else
-    header = "<html><head><title></title><head><body>";
-  endif
-  
+  header = get_feature (page_type, "header", options);
+    
   if (isfield (options, "css"))
     header = strrep (header, "%css", options.css);
   endif
 
   header = strrep (header, "%root", root);
-  if (isfield (options, "body_command"))
-    header = strrep (header, "%body_command", options.body_command);
-  endif
   
-  if (isfield (options, "title"))
-    title = options.title;
-  else
-    title = "%name";
-  endif
+  body_command = get_feature (page_type, "body_command", options);
+  header = strrep (header, "%body_command", body_command);
+  
+  title = get_feature (page_type, "title", options);  
   title = strrep (title, "%name", name);
   title_start_idx = strfind (lower (header), "<title>");
   title_stop_idx = strfind (lower (header), "</title>");
+  
   if (!isempty (title_start_idx) && !isempty (title_stop_idx))
     header = sprintf ("%s<title>%s%s", header (1:title_start_idx-1), title, 
                       header (title_stop_idx:end));
@@ -48,12 +41,7 @@
     header = strrep (header, "%title", title);
   endif
   
-  if (isfield (options, "footer"))
-    footer = options.footer;
-  else
-    footer = "</body></html>";
-  endif
-  
+  footer = get_feature (page_type, "footer", options);  
   footer = strrep (footer, "%root", root);
   footer = strrep (footer, "%pkgroot", pkgroot);
   footer = strrep (footer, "%package", pkgname);
diff -r 27384cfd9f69 -r eae7f6eecac6 inst/private/get_index_header_title_and_footer.m
--- a/inst/private/get_index_header_title_and_footer.m	mer. août 20 16:54:44 2014 +0200
+++ /dev/null	jeu. janv. 01 00:00:00 1970 +0000
@@ -1,70 +0,0 @@
-## 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
-## under the terms of the GNU General Public License as published by
-## the Free Software Foundation; either version 3 of the License, or (at
-## your option) any later version.
-##
-## This program is distributed in the hope that it will be useful, but
-## WITHOUT ANY WARRANTY; without even the implied warranty of
-## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-## General Public License for more details.
-##
-## You should have received a copy of the GNU General Public License
-## 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 = "", pkgroot = "", pkgname = "")
-  
-  if (isfield (options, "index_header"))
-    header = options.index_header;
-  elseif (isfield (options, "header"))
-    header = options.header;
-  else
-    header = "<html><head><title></title><head><body>";
-  endif
-  
-  if (isfield (options, "css"))
-    header = strrep (header, "%css", options.css);
-  endif
-  
-  header = strrep (header, "%root", root);
-  if (isfield (options, "index_body_command"))
-    header = strrep (header, "%body_command", options.index_body_command);
-  elseif (isfield (options, "body_command"))
-    header = strrep (header, "%body_command", options.body_command);
-  endif
-  
-  if (isfield (options, "index_title"))
-    title = options.index_title;
-  elseif (isfield (options, "title"))
-    title = options.title;
-  else
-    title = "The '%name' package";
-  endif
-  title = strrep (title, "%name", name);
-  title_start_idx = strfind (lower (header), "<title>");
-  title_stop_idx = strfind (lower (header), "</title>");
-  if (!isempty (title_start_idx) && !isempty (title_stop_idx))
-    header = sprintf ("%s<title>%s%s", header (1:title_start_idx-1), title, 
-                      header (title_stop_idx:end));
-  else
-    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
-
-  footer = strrep (footer, "%root", root);
-  footer = strrep (footer, "%pkgroot", pkgroot);
-  footer = strrep (footer, "%package", pkgname);
-  
-endfunction
diff -r 27384cfd9f69 -r eae7f6eecac6 inst/private/get_overview_header_title_and_footer.m
--- a/inst/private/get_overview_header_title_and_footer.m	mer. août 20 16:54:44 2014 +0200
+++ /dev/null	jeu. janv. 01 00:00:00 1970 +0000
@@ -1,72 +0,0 @@
-## 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
-## under the terms of the GNU General Public License as published by
-## the Free Software Foundation; either version 3 of the License, or (at
-## your option) any later version.
-##
-## This program is distributed in the hope that it will be useful, but
-## WITHOUT ANY WARRANTY; without even the implied warranty of
-## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-## General Public License for more details.
-##
-## You should have received a copy of the GNU General Public License
-## 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 = "", pkgroot = "", pkgname = "")
-  
-  if (isfield (options, "overview_header"))
-    header = options.overview_header;
-  elseif (isfield (options, "header"))
-    header = options.header;
-  else
-    header = "<html><head><title></title><head><body>";
-  endif
-  
-  if (isfield (options, "css"))
-    header = strrep (header, "%css", options.css);
-  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"))
-    header = strrep (header, "%body_command", options.body_command);
-  endif
-  
-  if (isfield (options, "overview_title"))
-    title = options.overview_title;
-  elseif (isfield (options, "title"))
-    title = options.title;
-  else
-    title = "List of Functions for the '%name' package";
-  endif
-  title = strrep (title, "%name", name);
-  title_start_idx = strfind (lower (header), "<title>");
-  title_stop_idx = strfind (lower (header), "</title>");
-  if (!isempty (title_start_idx) && !isempty (title_stop_idx))
-    header = sprintf ("%s<title>%s%s", header (1:title_start_idx-1), title, 
-                      header (title_stop_idx:end));
-  else
-    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
-  
-  footer = strrep (footer, "%root", root);
-  footer = strrep (footer, "%pkgroot", pkgroot);
-  footer = strrep (footer, "%package", pkgname);
-  
-endfunction
-
diff -r 27384cfd9f69 -r eae7f6eecac6 inst/texi2html.m
--- a/inst/texi2html.m	mer. août 20 16:54:44 2014 +0200
+++ b/inst/texi2html.m	mer. août 20 18:22:04 2014 +0200
@@ -79,7 +79,9 @@
   text = strrep (text, "&mdash;", "<p class=\"functionfile\">");
             
   ## Read 'options' input argument
-  [header, title, footer] = get_header_title_and_footer (options, :, root);
+  [header, title, footer] = get_header_title_and_footer ...
+    ("function", options, :, root);
+  
 endfunction
 
 function expanded = html_see_also_with_prefix (prefix, varargin)
