You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tomee.apache.org by db...@apache.org on 2018/12/02 11:06:59 UTC

[2/3] tomee-site-generator git commit: Smarter grouping for large sections

Smarter grouping for large sections


Project: http://git-wip-us.apache.org/repos/asf/tomee-site-generator/repo
Commit: http://git-wip-us.apache.org/repos/asf/tomee-site-generator/commit/11df0fda
Tree: http://git-wip-us.apache.org/repos/asf/tomee-site-generator/tree/11df0fda
Diff: http://git-wip-us.apache.org/repos/asf/tomee-site-generator/diff/11df0fda

Branch: refs/heads/master
Commit: 11df0fda60233d6d2040eb60bd8ac7e093b0beb2
Parents: 190bf1f
Author: dblevins <da...@gmail.com>
Authored: Sun Dec 2 02:53:41 2018 -0800
Committer: dblevins <da...@gmail.com>
Committed: Sun Dec 2 02:53:41 2018 -0800

----------------------------------------------------------------------
 .../org/apache/tomee/website/AddGroups.java     |  47 ++++++++
 .../org/apache/tomee/website/GroupedIndex.java  | 109 ++++++++++++++-----
 src/main/jbake/assets/css/cardio.css            |   1 +
 src/main/jbake/templates/examples-index.gsp     |   2 +-
 4 files changed, 130 insertions(+), 29 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tomee-site-generator/blob/11df0fda/src/main/java/org/apache/tomee/website/AddGroups.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/tomee/website/AddGroups.java b/src/main/java/org/apache/tomee/website/AddGroups.java
new file mode 100644
index 0000000..cce6566
--- /dev/null
+++ b/src/main/java/org/apache/tomee/website/AddGroups.java
@@ -0,0 +1,47 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package org.apache.tomee.website;
+
+import org.apache.openejb.loader.IO;
+
+import java.io.File;
+import java.io.IOException;
+
+public class AddGroups {
+
+    public static void main(String[] args) throws IOException {
+        final String[] lines = IO.slurp(new File("repos/tomee-8.0/examples/index.md")).split("\n");
+
+        String group = "";
+        for (final String line : lines) {
+            if (line.startsWith("###")) {
+                group = line.replace("###", "").trim();
+            }
+
+
+            if (line.startsWith("[")) {
+                final String s = line.replaceAll(".*\\(|\\).*", "").replaceAll(".html", ".md");
+
+                final File file = new File("repos/tomee-8.0/examples/" + s);
+                final String content = IO.slurp(file);
+                final String updated = content.replace("index-group=Unrevised", "index-group=" + group);
+
+                IO.copy(IO.read(updated), file);
+            }
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/tomee-site-generator/blob/11df0fda/src/main/java/org/apache/tomee/website/GroupedIndex.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/tomee/website/GroupedIndex.java b/src/main/java/org/apache/tomee/website/GroupedIndex.java
index b73e1ab..adcaa36 100644
--- a/src/main/java/org/apache/tomee/website/GroupedIndex.java
+++ b/src/main/java/org/apache/tomee/website/GroupedIndex.java
@@ -56,39 +56,86 @@ public class GroupedIndex {
         final List<Doc> docs = list(directory);
         final Map<String, List<Doc>> sections = docs.stream().collect(Collectors.groupingBy(Doc::getGroup));
 
-        for (final Map.Entry<String, List<Doc>> entry : sections.entrySet()) {
-            final ByteArrayOutputStream bytes = new ByteArrayOutputStream();
-            final PrintStream out = new PrintStream(bytes);
-
-            out.printf("            <div class=\"group-title\">%s</div>\n", entry.getKey());
-            out.printf("            <ul class=\"group\">\n");
-            entry.getValue().stream().sorted().forEach(doc -> {
-                out.printf("              <li class=\"group-item\"><span class=\"group-item-i\" ><i class=\"fa fa-angle-right\"></i></span><a href=\"%s\">%s</a></li>\n", doc.getHref(), doc.getTitle());
-            });
-            out.printf("            </ul>\n");
-
-            sectionsFormatted.add(new String(bytes.toByteArray()));
-        }
+        /**
+         * We want to sort the sections with the most entries towards the top.
+         * Unless it is crazy big, then we put it in a special section at the bottom.
+         */
+        sections.entrySet().stream()
+                .filter(entry -> entry.getValue().size() < 10)
+                .sorted((o1, o2) -> new Integer(o2.getValue().size()).compareTo(o1.getValue().size()))
+                .forEach(entry -> {
+
+                    final ByteArrayOutputStream bytes = new ByteArrayOutputStream();
+                    final PrintStream out = new PrintStream(bytes);
+
+                    out.printf("            <div class=\"group-title\">%s</div>\n", entry.getKey());
+                    out.printf("            <ul class=\"group\">\n");
+                    entry.getValue().stream().sorted().forEach(doc -> {
+                        out.printf("              <li class=\"group-item\"><span class=\"group-item-i\" ><i class=\"fa fa-angle-right\"></i></span><a href=\"%s\">%s</a></li>\n", doc.getHref(), doc.getTitle());
+                    });
+                    out.printf("            </ul>\n");
+
+                    sectionsFormatted.add(new String(bytes.toByteArray()));
+
+                });
 
         try (final PrintStream out = print(directory, "index.html")) {
             out.printf("type=%s\n", type);
             out.printf("status=published\n");
             out.printf("~~~~~~\n");
 
-            final ListIterator<String> iterator = sectionsFormatted.listIterator();
-            while (iterator.hasNext()) {
-                out.printf("        <div class=\"row\">\n");
-                out.printf("          <div class=\"col-md-4\">\n");
-                out.printf(iterator.hasNext() ? iterator.next() : "");
-                out.printf("          </div>\n");
-                out.printf("          <div class=\"col-md-4\">\n");
-                out.printf(iterator.hasNext() ? iterator.next() : "");
-                out.printf("          </div>\n");
-                out.printf("          <div class=\"col-md-4\">\n");
-                out.printf(iterator.hasNext() ? iterator.next() : "");
-                out.printf("          </div>\n");
-                out.printf("        </div>\n");
+            {
+                final ListIterator<String> iterator = sectionsFormatted.listIterator();
+                while (iterator.hasNext()) {
+                    out.printf("        <div class=\"row\">\n");
+                    out.printf("          <div class=\"col-md-4\">\n");
+                    out.printf(iterator.hasNext() ? iterator.next() : "");
+                    out.printf("          </div>\n");
+                    out.printf("          <div class=\"col-md-4\">\n");
+                    out.printf(iterator.hasNext() ? iterator.next() : "");
+                    out.printf("          </div>\n");
+                    out.printf("          <div class=\"col-md-4\">\n");
+                    out.printf(iterator.hasNext() ? iterator.next() : "");
+                    out.printf("          </div>\n");
+                    out.printf("        </div>\n");
+                }
             }
+
+            sections.entrySet().stream()
+                    .filter(entry -> entry.getValue().size() >= 10)
+                    .sorted((o1, o2) -> new Integer(o1.getValue().size()).compareTo(o2.getValue().size()))
+                    .forEach(entry -> {
+
+                        out.printf("        <div class=\"row\">\n");
+                        out.printf("          <div class=\"col-md-12\">\n");
+                        out.printf("            <div class=\"group-title large\">%s</div>\n", entry.getKey());
+                        out.printf("          </div>\n");
+                        out.printf("        </div>\n");
+
+                        final ListIterator<Doc> iterator = entry.getValue().stream()
+                                .sorted()
+                                .collect(Collectors.toList())
+                                .listIterator();
+
+                        final int i = (int) Math.ceil(entry.getValue().size() / 3f);
+
+                        out.printf("        <div class=\"row\">\n");
+                        while (iterator.hasNext()) {
+                            int count = 0;
+
+                            out.printf("          <div class=\"col-md-4\">\n");
+                            out.printf("            <ul class=\"group\">\n");
+                            while (iterator.hasNext() && count++ < i) {
+                                final Doc doc = iterator.next();
+                                out.printf("              <li class=\"group-item\"><span class=\"group-item-i\" ><i class=\"fa fa-angle-right\"></i></span><a href=\"%s\">%s</a></li>\n", doc.getHref(), doc.getTitle());
+
+                            }
+                            out.printf("            </ul>\n");
+                            out.printf("          </div>\n");
+                        }
+                        out.printf("        </div>\n");
+                    });
+
         }
     }
 
@@ -129,11 +176,17 @@ public class GroupedIndex {
     }
 
     private String getTitle(final Map<String, Object> map, final File file) {
-        if (map.get("short-title") != null) return map.get("short-title") + "";
-        if (map.get("title") != null) return map.get("title") + "";
+        if (hasValue(map.get("short-title"))) return map.get("short-title") + "";
+        if (hasValue(map.get("title"))) return map.get("title") + "";
         return Docs.simpleName(file);
     }
 
+    private boolean hasValue(final Object o) {
+        if (o == null) return false;
+        if ("".equals(o + ""))return false;
+        return true;
+    }
+
     public static class Doc implements Comparable<Doc> {
 
         private final String group;

http://git-wip-us.apache.org/repos/asf/tomee-site-generator/blob/11df0fda/src/main/jbake/assets/css/cardio.css
----------------------------------------------------------------------
diff --git a/src/main/jbake/assets/css/cardio.css b/src/main/jbake/assets/css/cardio.css
index 84cabc1..fe10969 100755
--- a/src/main/jbake/assets/css/cardio.css
+++ b/src/main/jbake/assets/css/cardio.css
@@ -1347,6 +1347,7 @@ span.icon > [class^="icon-"], span.icon > [class*=" icon-"] {
   font-size: 17px;
   padding-left: 0;
   list-style-type: none;
+  margin-bottom: 30px;
 }
 
 .group-title {

http://git-wip-us.apache.org/repos/asf/tomee-site-generator/blob/11df0fda/src/main/jbake/templates/examples-index.gsp
----------------------------------------------------------------------
diff --git a/src/main/jbake/templates/examples-index.gsp b/src/main/jbake/templates/examples-index.gsp
index c45b3e1..682c66a 100755
--- a/src/main/jbake/templates/examples-index.gsp
+++ b/src/main/jbake/templates/examples-index.gsp
@@ -5,7 +5,7 @@
         <div class="row title">
           <div class="col-md-12">
             <div class='page-header'>
-              <h1>Documentation</h1>
+              <h1>Examples</h1>
             </div>
           </div>
         </div>