# HG changeset patch
# User Julien Bect <julien.bect@supelec.fr>
# Date 1408394813 -7200
#      lun. août 18 22:46:53 2014 +0200
# Node ID 6f5d8380413b4b10f74b6e9245917ce28950f0d7
# Parent  033a346385cbb0dee7a8baf4e353181dbcc0cdca
generate_package_html.m: Omit the "News" link if there is no NEWS file

* inst/generate_package_html.m: Omit the news link if there is no NEWS file.

diff -r 033a346385cb -r 6f5d8380413b inst/generate_package_html.m
--- a/inst/generate_package_html.m	dim. août 17 20:42:13 2014 +0100
+++ b/inst/generate_package_html.m	lun. août 18 22:46:53 2014 +0200
@@ -242,7 +242,7 @@
       fclose (name_fid);
       fclose (desc_fid);
     endfor
-  endif  
+  endif
   
   #####################################################
   ## Write short description for forge overview page ##
@@ -265,6 +265,56 @@
     endif
   endif
 
+  #####################
+  ## Write NEWS file ##
+  #####################
+  if (isfield (options, "include_package_news") && options.include_package_news)
+    ## Get detailed information about the package
+    all_list = pkg ("list");
+    list = [];
+    for k = 1:length (all_list)
+      if (strcmp (all_list {k}.name, packname))
+        list = all_list {k};
+      endif
+    endfor
+    if (isempty (list))
+      error ("generate_package_html: couldn't locate package '%s'", packname);
+    endif
+
+    ## Read news
+    filename = fullfile (list.dir, "packinfo", "NEWS");
+    fid = fopen (filename, "r");
+    if (fid < 0)
+      warning ("generate_package_html: couldn't open NEWS for reading");
+      write_package_news = false;
+    else
+      write_package_news = true;
+
+      news_content = char (fread (fid).');
+      fclose (fid);
+
+      ## Open output file
+      news_filename = "NEWS.html";
+
+      fid = fopen (fullfile (packdir, news_filename), "w");
+      if (fid < 0)
+        error ("generate_package_html: couldn't open NEWS file for writing");
+      endif
+
+      ## 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);
+
+      fprintf (fid, "<pre>%s</pre>\n\n", news_content);
+
+      fprintf (fid, "\n%s\n", footer);
+      fclose (fid);
+    endif
+  endif
+
   ######################
   ## Write index file ##
   ######################
@@ -303,7 +353,7 @@
     ## Write output
     [header, title, footer] = get_index_header_title_and_footer (options, desc.name, "../");
 
-    fprintf (fid, "%s\n", header); 
+    fprintf (fid, "%s\n", header);
     fprintf (fid, "<h2 class=\"tbdesc\">%s</h2>\n\n", desc.name);
 
     fprintf (fid, "<table>\n");
@@ -359,14 +409,16 @@
     fprintf (fid, "    </a>\n");
     fprintf (fid, "  </td></tr></table>\n");
     fprintf (fid, "</div>\n");
-    fprintf (fid, "<div class=\"news_file\">\n");
-    fprintf (fid, "  <table><tr><td>\n");
-    fprintf (fid, "  </td><td>\n");
-    fprintf (fid, "    <a href=\"NEWS.html\" class=\"news_file\">\n");
-    fprintf (fid, "      NEWS\n");
-    fprintf (fid, "    </a>\n");
-    fprintf (fid, "  </td></tr></table>\n");
-    fprintf (fid, "</div>\n");
+    if (write_package_news)
+      fprintf (fid, "<div class=\"news_file\">\n");
+      fprintf (fid, "  <table><tr><td>\n");
+      fprintf (fid, "  </td><td>\n");
+      fprintf (fid, "    <a href=\"NEWS.html\" class=\"news_file\">\n");
+      fprintf (fid, "      NEWS\n");
+      fprintf (fid, "    </a>\n");
+      fprintf (fid, "  </td></tr></table>\n");
+      fprintf (fid, "</div>\n");
+    endif
     if (write_package_documentation)
       fprintf (fid, "<div class=\"package_doc\">\n");
       fprintf (fid, "  <table><tr><td>\n");
@@ -467,7 +519,7 @@
     ## Write output
     [header, title, footer] = get_index_header_title_and_footer (options, desc.name, "../");
     
-    fprintf (fid, "%s\n", header); 
+    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);
 
@@ -477,52 +529,6 @@
     fclose (fid);
   endif
 
-  #####################
-  ## Write NEWS file ##
-  #####################
-  if (isfield (options, "include_package_news") && options.include_package_news)
-    ## Get detailed information about the package
-    all_list = pkg ("list");
-    list = [];
-    for k = 1:length (all_list)
-      if (strcmp (all_list {k}.name, packname))
-        list = all_list {k};
-      endif
-    endfor
-    if (isempty (list))
-      error ("generate_package_html: couldn't locate package '%s'", packname);
-    endif
-
-    ## Read news
-    filename = fullfile (list.dir, "packinfo", "NEWS");
-    fid = fopen (filename, "r");
-    if (fid < 0)
-      error ("generate_package_html: couldn't open NEWS for reading");
-    endif
-    contents = char (fread (fid).');
-    fclose (fid);
-
-    ## Open output file
-    news_filename = "NEWS.html";
-
-    fid = fopen (fullfile (packdir, news_filename), "w");
-    if (fid < 0)
-      error ("generate_package_html: couldn't open NEWS file for writing");
-    endif
-  
-    ## 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);
-
-    fprintf (fid, "<pre>%s</pre>\n\n", contents);
-    
-    fprintf (fid, "\n%s\n", footer);
-    fclose (fid);
-  endif
-
   #################################
   ## Write package documentation ##
   #################################
