fixed font size
[pnews.git] / src / main / java / pnews / HTML.java
index 5f089cc..78d584d 100644 (file)
@@ -3,10 +3,16 @@ package pnews;
 import java.util.List;
 
 public class HTML {
-       private static void appendA(StringBuffer buf, String child, String href) {
+       private static void appendA(StringBuffer buf, String child, String href, String cl) {
                buf.append("<a href='");
                buf.append(href);
-               buf.append("'>");
+               buf.append("'");
+               if (cl != null) {
+                       buf.append(" class='");
+                       buf.append(cl);
+                       buf.append('\'');
+               }
+               buf.append('>');
                buf.append(child);
                buf.append("</a>");
        }
@@ -24,31 +30,43 @@ public class HTML {
        }
        
        private static void append(StringBuffer buf, Article a) {               
-               buf.append("<section>\n");
+               buf.append("<div class='article'>\n");
+               
                buf.append("<h2>");
-               appendA(buf, a.title, a.link);
+               if (a.thumbnail != null) {
+                       buf.append("<img class='left' src='");
+                       buf.append(a.thumbnail);
+                       buf.append("'/>\n");
+               }
+               appendA(buf, a.title, a.link, null);
                buf.append("</h2>\n");
-                               
-               buf.append("<img class='left' src='");
-               buf.append(a.thumbnail);
-               buf.append("'/>\n");
                
-               buf.append("<p>" + a.website + " - " + a.publicationDate + "</p>");
+               buf.append("<div class='article-info'>" + a.website + " - " + a.publicationDate + "</div>");
                
-               buf.append("<p>");
-               buf.append(a.description);
-               buf.append("</p>");
+               if (a.description != null) {
+                       buf.append("<p>");
+                       buf.append(a.description);
+                       buf.append("</p>");
+               }
                
-               buf.append("</section>\n");             
+               buf.append("</div>\n");         
        }
        
-       private static void appendMenu(StringBuffer buf) {
+       private static void appendMenu(StringBuffer buf, Category catActive) {
+               String cl;
+               
                buf.append("<nav>\n");
                buf.append("<ul>\n");
 
                for (Category cat: Category.values()) {
                        buf.append("<li>");
-                       appendA(buf, cat.getId(), cat.getId() + ".html");
+                       
+                       if (cat.equals(catActive))
+                               cl = "active";
+                       else
+                               cl = null;
+                       
+                       appendA(buf, cat.getId(), cat.getId() + ".html", cl);
                        buf.append("</li>");
                }
                
@@ -56,7 +74,7 @@ public class HTML {
                buf.append("</nav>\n");
        }
        
-       public static String toHTML(List<Article> articles) {
+       public static String toHTML(List<Article> articles, Category catActive) {
                StringBuffer buf;
                
                buf = new StringBuffer();
@@ -69,7 +87,7 @@ public class HTML {
                buf.append("</head>\n");
                buf.append("<body>\n");
                
-               appendMenu(buf);
+               appendMenu(buf, catActive);
                
                for (Article e: articles)
                        append(buf, e);