summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid A. Madore <david+git@madore.org>2018-09-07 11:47:44 (GMT)
committerDavid A. Madore <david+git@madore.org>2018-09-07 11:47:44 (GMT)
commitb127db40f8fe70dabd1fa3830fb98e63763d6775 (patch)
treee50ebd32bf4920136cb3552ebc334e9169a4f0b4
parent2ef34be07b699e7a802078d1d5b952347f2cffa7 (diff)
downloaddamlengine-b127db40f8fe70dabd1fa3830fb98e63763d6775.zip
damlengine-b127db40f8fe70dabd1fa3830fb98e63763d6775.tar.gz
damlengine-b127db40f8fe70dabd1fa3830fb98e63763d6775.tar.bz2
Add a navigation bar before and after every single blog entry.
-rw-r--r--org/madore/damlengine/TodoEntryElement.java136
-rw-r--r--org/madore/damlengine/TodoWrefAttr.java10
2 files changed, 142 insertions, 4 deletions
diff --git a/org/madore/damlengine/TodoEntryElement.java b/org/madore/damlengine/TodoEntryElement.java
index c41237b..9210373 100644
--- a/org/madore/damlengine/TodoEntryElement.java
+++ b/org/madore/damlengine/TodoEntryElement.java
@@ -28,16 +28,26 @@ public final class TodoEntryElement extends TodoDefaultElement {
|| caller instanceof TodoWeblogSelectElement ) )
throw new IllegalArgumentException("entry node can only be child of weblog node");
+ // A container <div> that contains everything
+ Element containerDiv = ctx.doc.createElementNS(DamlEngine.XHTML_NS, "div");
+ node.getParentNode().replaceChild(containerDiv, node);
+ Element beforeP = ctx.doc.createElementNS(DamlEngine.XHTML_NS, "p");
+ Element afterP = ctx.doc.createElementNS(DamlEngine.XHTML_NS, "p");
+
+ // The <article> element containing the entry itself
Element article = ctx.doc.createElementNS(DamlEngine.XHTML_NS, "article");
String lang = LangHelper.getLangRec(node);
String explicitLang = LangHelper.getLangNorec(node);
if ( explicitLang != null )
LangHelper.setLangNorec(article, explicitLang);
- node.getParentNode().replaceChild(article, node);
+ containerDiv.appendChild(beforeP);
+ containerDiv.appendChild(article);
+ containerDiv.appendChild(afterP);
final String entryNumberStr = node.getAttributeNS(null, "number");
if ( ! Pattern.matches("^\\d{4}$", entryNumberStr) )
throw new IllegalArgumentException("entry number attribute must be of the form NNNN");
+ final int entryNumber = Integer.parseInt(entryNumberStr);
final String entryDateStr = node.getAttributeNS(null, "date");
final Matcher entryDateMatcher = Pattern.compile("^(\\d{4})-(\\d{2})-(\\d{2})$").matcher(entryDateStr);
if ( ! entryDateMatcher.matches() )
@@ -124,6 +134,7 @@ public final class TodoEntryElement extends TodoDefaultElement {
if ( ! entryDowStr.equals("") )
headlink.appendChild(ctx.doc.createTextNode(" ("+entryDowStr+")"));
+ // The <div> that contains the entry's body (content)
Element mainDiv = ctx.doc.createElementNS(DamlEngine.XHTML_NS, "div");
article.appendChild(mainDiv);
article.appendChild(ctx.doc.createTextNode("\n"));
@@ -141,6 +152,7 @@ public final class TodoEntryElement extends TodoDefaultElement {
ArrayList<Node> childList = getChildList(this.node);
ArrayList<TodoElement> toProcess = new ArrayList<TodoElement>(childList.size()+8);
+ toProcess.add(TodoElement.getTodoElement(beforeP, ctx2, this));
for ( Node child : childList ) {
if ( child.getNodeType() == Node.TEXT_NODE
|| child.getNodeType() == Node.CDATA_SECTION_NODE ) {
@@ -158,6 +170,7 @@ public final class TodoEntryElement extends TodoDefaultElement {
toProcess.add(it);
}
}
+
Element footer = ctx.doc.createElementNS(DamlEngine.XHTML_NS, "footer");
article.appendChild(footer);
article.appendChild(ctx.doc.createTextNode("\n"));
@@ -176,7 +189,128 @@ public final class TodoEntryElement extends TodoDefaultElement {
footer.appendChild(ctx.doc.createTextNode("\n"));
toProcess.add(new TodoComments(token, ctx2, this));
}
+ toProcess.add(TodoElement.getTodoElement(afterP, ctx2, this));
+
+ // Before and after <p>'s
+ {
+ final WeblogSummary wsum = WeblogSummary.getSummary(ctx.dc);
+ final class DoLink {
+ Element parent; int num; String text; boolean permalink;
+ public DoLink(Element parent, int num, String text) {
+ this.parent = parent;
+ this.num = num;
+ this.text = text;
+ this.permalink = false;
+ }
+ public DoLink(Element parent, int num, String text, boolean permalink) {
+ this.parent = parent;
+ this.num = num;
+ this.text = text;
+ this.permalink = permalink;
+ }
+ public Element doit() {
+ final WeblogSummary.EntrySummary esum;
+ if ( wsum != null && wsum.entries != null )
+ esum = wsum.entries.get(num);
+ else
+ esum = null;
+ Element a;
+ if ( esum != null ) {
+ a = ctx.doc.createElementNS(DamlEngine.XHTML_NS, "a");
+ a.setAttributeNS(DamlEngine.DAML_NS, "d:wref",
+ "#d." + esum.date + "."
+ + String.format("%04d", esum.id));
+ if ( permalink )
+ // TodoWrefAttr handles this attribute:
+ a.setAttributeNS(DamlEngine.DAML_NS,
+ "d:wrefcat", "@force-single");
+ } else {
+ a = ctx.doc.createElementNS(DamlEngine.XHTML_NS, "del");
+ }
+ a.appendChild(ctx.doc.createTextNode(text));
+ parent.appendChild(a);
+ return a;
+ }
+ }
+
+ Element span, tmp;
+ span = ctx.doc.createElementNS(DamlEngine.XHTML_NS, "span");
+ beforeP.appendChild(span);
+ LangHelper.setLangRec(span, "en");
+ span.appendChild(ctx.doc.createTextNode("\u2193Entry #"+entryNumberStr));
+ span.appendChild(ctx.doc.createTextNode(" ["));
+ new DoLink(span, entryNumber-1, "older").doit();
+ span.appendChild(ctx.doc.createTextNode("|"));
+ tmp = new DoLink(span, entryNumber, "\u203b").doit();
+ tmp.setAttributeNS(null, "style", "opacity: 0.1");
+ span.appendChild(ctx.doc.createTextNode(" "));
+ new DoLink(span, entryNumber, "permalink", true).doit();
+ span.appendChild(ctx.doc.createTextNode("|"));
+ tmp = new DoLink(span, entryNumber+1, "newer").doit();
+ if ( ctx.wsc != null && ctx.wsc.sel != null
+ && ctx.wsc.sel.contains(entryNumber+1) )
+ tmp.setAttributeNS(null, "style", "opacity: 0.1");
+ span.appendChild(ctx.doc.createTextNode("]"));
+ beforeP.appendChild(ctx.doc.createTextNode(" / "));
+ span = ctx.doc.createElementNS(DamlEngine.XHTML_NS, "span");
+ beforeP.appendChild(span);
+ LangHelper.setLangRec(span, "fr");
+ span.appendChild(ctx.doc.createTextNode("\u2193Entr\u00e9e #"+entryNumberStr));
+ span.appendChild(ctx.doc.createTextNode(" ["));
+ new DoLink(span, entryNumber-1, "pr\u00e9c\u00e9dente").doit();
+ span.appendChild(ctx.doc.createTextNode("|"));
+ tmp = new DoLink(span, entryNumber, "\u203b").doit();
+ tmp.setAttributeNS(null, "style", "opacity: 0.1");
+ span.appendChild(ctx.doc.createTextNode(" "));
+ new DoLink(span, entryNumber, "permalien", true).doit();
+ span.appendChild(ctx.doc.createTextNode("|"));
+ tmp = new DoLink(span, entryNumber+1, "suivante").doit();
+ if ( ctx.wsc != null && ctx.wsc.sel != null
+ && ctx.wsc.sel.contains(entryNumber+1) )
+ tmp.setAttributeNS(null, "style", "opacity: 0.1");
+ span.appendChild(ctx.doc.createTextNode("]"));
+ beforeP.appendChild(ctx.doc.createTextNode("\u2001\u2193"));
+
+ span = ctx.doc.createElementNS(DamlEngine.XHTML_NS, "span");
+ afterP.appendChild(span);
+ LangHelper.setLangRec(span, "en");
+ span.appendChild(ctx.doc.createTextNode("\u2191Entry #"+entryNumberStr));
+ span.appendChild(ctx.doc.createTextNode(" ["));
+ tmp = new DoLink(span, entryNumber-1, "older").doit();
+ if ( ctx.wsc != null && ctx.wsc.sel != null
+ && ctx.wsc.sel.contains(entryNumber-1) )
+ tmp.setAttributeNS(null, "style", "opacity: 0.1");
+ span.appendChild(ctx.doc.createTextNode("|"));
+ tmp = new DoLink(span, entryNumber, "\u203b").doit();
+ tmp.setAttributeNS(null, "title", "(Jump to top of entry)");
+ span.appendChild(ctx.doc.createTextNode(" "));
+ new DoLink(span, entryNumber, "permalink", true).doit();
+ span.appendChild(ctx.doc.createTextNode("|"));
+ new DoLink(span, entryNumber+1, "newer").doit();
+ span.appendChild(ctx.doc.createTextNode("]"));
+ afterP.appendChild(ctx.doc.createTextNode(" / "));
+ span = ctx.doc.createElementNS(DamlEngine.XHTML_NS, "span");
+ afterP.appendChild(span);
+ LangHelper.setLangRec(span, "fr");
+ span.appendChild(ctx.doc.createTextNode("\u2191Entr\u00e9e #"+entryNumberStr));
+ span.appendChild(ctx.doc.createTextNode(" ["));
+ tmp = new DoLink(span, entryNumber-1, "pr\u00e9c\u00e9dente").doit();
+ if ( ctx.wsc != null && ctx.wsc.sel != null
+ && ctx.wsc.sel.contains(entryNumber-1) )
+ tmp.setAttributeNS(null, "style", "opacity: 0.1");
+ span.appendChild(ctx.doc.createTextNode("|"));
+ tmp = new DoLink(span, entryNumber, "\u203b").doit();
+ tmp.setAttributeNS(null, "title", "(Retourner du d\u00e9but de l'entr\u00e9e)");
+ span.appendChild(ctx.doc.createTextNode(" "));
+ new DoLink(span, entryNumber, "permalien", true).doit();
+ span.appendChild(ctx.doc.createTextNode("|"));
+ new DoLink(span, entryNumber+1, "suivante").doit();
+ span.appendChild(ctx.doc.createTextNode("]"));
+ afterP.appendChild(ctx.doc.createTextNode("\u2001\u2191"));
+ }
+
this.ownerDeque.registerAtStart(toProcess);
+
}
}
diff --git a/org/madore/damlengine/TodoWrefAttr.java b/org/madore/damlengine/TodoWrefAttr.java
index 9bde003..977af18 100644
--- a/org/madore/damlengine/TodoWrefAttr.java
+++ b/org/madore/damlengine/TodoWrefAttr.java
@@ -53,8 +53,8 @@ public class TodoWrefAttr extends TodoAttr {
if ( ! ((wrefYearStr+"-"+wrefMonthStr+"-"+wrefDayStr)
.equals(esum.date)) )
throw new IllegalArgumentException("date mismatch for reference to entry "+wrefNumberStr);
- if ( wrefCat != null && ! wrefCat.equals("@month")
- && ! wrefCat.equals("@single") ) {
+ if ( wrefCat != null && wrefCat.length() != 0
+ && wrefCat.charAt(0) != '@' ) {
if ( esum.catSet == null || ! esum.catSet.contains(wrefCat) )
throw new IllegalArgumentException("reference to entry "+wrefNumberStr+" in wrong category "+wrefCat);
}
@@ -86,7 +86,11 @@ public class TodoWrefAttr extends TodoAttr {
onThisPage = false;
}
// Choose file portion of link target
- if ( onThisPage )
+ if ( wrefCat != null && wrefCat.equals("@force-single") )
+ lk.setTypeSingle();
+ else if ( wrefCat != null && wrefCat.equals("@force-month") )
+ lk.setTypeMonth();
+ else if ( onThisPage )
lk.setTypeRelative();
else if ( wrefCat == null )
lk.setTypeStandard();