get html header from file
authorJean-Philippe Orsini <jeanfi@gmail.com>
Tue, 8 May 2012 11:03:35 +0000 (11:03 +0000)
committerJean-Philippe Orsini <jeanfi@gmail.com>
Tue, 8 May 2012 11:03:35 +0000 (11:03 +0000)
NEWS
src/html.c
www/Makefile.am
www/Makefile.in
www/header.tpl [new file with mode: 0644]

diff --git a/NEWS b/NEWS
index f2dd688..978910b 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -1,9 +1,12 @@
 * v0.0.7
-* More crash-resistant on network failure (patch from Lekensteyn).
-* Retry HTTP request on LP Oops (patch from Lekensteyn).
+* More crash-resistant on network failure (patch from Peter
+  Lekensteyn).
+* Retry HTTP request on LP Oops (patch from Peter Lekensteyn).
 * Added intl support.
 * Increased HTTP requests performance: group result for
-  getPublishedBinaries by 300 instead of 75
+  getPublishedBinaries by 300 instead of 75 (patch from Peter
+  Lekensteyn).
+* HTML template pages are now in [prefix]/share/psensor/www
 
 * v0.0.6
 ** added support of ie < 9.
index b2e9e34..965a565 100644 (file)
@@ -39,6 +39,7 @@
 static char *footer;
 static char *ppa_body;
 static char *pkg_body;
+static char *header;
 
 #define HTML_VERSION_TEMPLATE \
 "<html>\n\
@@ -81,34 +82,6 @@ src=\"js/excanvas.js\"></script><![endif]-->\n\
       </div>\n\
     </div>\n"
 
-#define HTML_HEADER \
-"<html>\n\
-       <head>\n\
-               <title>%s</title>\n\
-               <link type=\"text/css\"\n\
-                     rel=\"stylesheet\"\n\
-                     href=\
-\"http://fonts.googleapis.com/css?family=Ubuntu:regular,bold&subset=Latin\">\n\
-               <link type=\"text/css\" href=\"css/ppastats.css\"\n\
-                     rel=\"stylesheet\"/>\n\
-               <link type=\"text/css\" href=\"css/jquery.jqplot.min.css\"\n\
-                     rel=\"stylesheet\" />\n\
-<!--[if lt IE 9]><script \
-language=\"javascript\" \
-type=\"text/javascript\" \
-src=\"js/excanvas.js\"></script><![endif]-->\n\
-               <script type=\"text/javascript\"\n\
-                       src=\"js/jquery.min.js\"></script>\n\
-               <script type=\"text/javascript\"\n\
-                       src=\"js/jquery.jqplot.min.js\"></script>\n\
-               <script type=\"text/javascript\"\n\
-                       src=\"js/jqplot.dateAxisRenderer.min.js\"></script>\n\
-               <script type=\"text/javascript\"\n\
-                       src=\"js/ppastats.js\"></script>\n\
-               <script>%s</script>\n\
-       </head>\n\
-       <body>\n"
-
 static char *path_new(const char *dir, const char *file, const char *suffixe)
 {
        char *path;
@@ -127,6 +100,21 @@ static char *path_new(const char *dir, const char *file, const char *suffixe)
        return path;
 }
 
+static const char *get_header()
+{
+       const char *path;
+
+       if (!header) {
+               path = DEFAULT_WWW_DIR"/header.tpl";
+               header = file_get_content(path);
+
+               if (!header)
+                       log_err("Failed to read header template: %s", path);
+       }
+
+       return header;
+}
+
 static const char *get_footer()
 {
        const char *path;
@@ -430,6 +418,11 @@ create_html(const char *path,
 {
        FILE *f;
        const char *footer;
+       const char *header;
+
+       header = get_header();
+       if (!header)
+               return ;
 
        f = fopen(path, "w");
 
@@ -438,7 +431,7 @@ create_html(const char *path,
                return ;
        }
 
-       fprintf(f, HTML_HEADER, title, script);
+       fprintf(f, header, title, script);
        fputs(body_template, f);
 
        footer = get_footer();
index 786daba..7489d23 100644 (file)
@@ -1,6 +1,7 @@
 defaultwwwdir = $(pkgdatadir)/www
 defaultwww_DATA = \
        footer.tpl\
+       header.tpl\
        js/excanvas.js\
        js/jquery.min.js\
        js/ppastats.js\
index f70e3f8..5c98628 100644 (file)
@@ -206,6 +206,7 @@ top_srcdir = @top_srcdir@
 defaultwwwdir = $(pkgdatadir)/www
 defaultwww_DATA = \
        footer.tpl\
+       header.tpl\
        js/excanvas.js\
        js/jquery.min.js\
        js/ppastats.js\
diff --git a/www/header.tpl b/www/header.tpl
new file mode 100644 (file)
index 0000000..c9f3552
--- /dev/null
@@ -0,0 +1,17 @@
+<html> 
+  <head>
+    <title>%s</title>
+    <link type="text/css"
+         rel="stylesheet"
+         href="http://fonts.googleapis.com/css?family=Ubuntu:regular,bold&subset=Latin">
+    <link type="text/css" href="css/ppastats.css" rel="stylesheet"/>
+    <link type="text/css" href="css/jquery.jqplot.min.css" rel="stylesheet" />
+    <!--[if lt IE 9]><script language="javascript" type="text/javascript" src="js/excanvas.js"></script><![endif]-->
+    <script type="text/javascript" src="js/jquery.min.js"></script>
+    <script type="text/javascript" src="js/jquery.jqplot.min.js"></script>
+    <script type="text/javascript" src="js/jqplot.dateAxisRenderer.min.js"></script>
+    <script type="text/javascript" src="js/ppastats.js"></script>
+    <script>%s</script>
+  </head>
+  <body>
+