Merge: nitiwiki: fix multiple trails
authorJean Privat <jean@pryen.org>
Sat, 28 Nov 2015 23:04:07 +0000 (18:04 -0500)
committerJean Privat <jean@pryen.org>
Sat, 28 Nov 2015 23:04:07 +0000 (18:04 -0500)
Fix a bug where independent trails could have been merged into a big one.

Pull-Request: #1854
Reviewed-by: Alexandre Terrasa <alexandre@moz-code.org>

contrib/nitiwiki/examples/nitiwiki/pages/section/other_section/first.md [new file with mode: 0644]
contrib/nitiwiki/examples/nitiwiki/pages/section/other_section/index.md [new file with mode: 0644]
contrib/nitiwiki/examples/nitiwiki/pages/section/other_section/second.md [new file with mode: 0644]
contrib/nitiwiki/src/wiki_html.nit

diff --git a/contrib/nitiwiki/examples/nitiwiki/pages/section/other_section/first.md b/contrib/nitiwiki/examples/nitiwiki/pages/section/other_section/first.md
new file mode 100644 (file)
index 0000000..c61423f
--- /dev/null
@@ -0,0 +1 @@
+first page
diff --git a/contrib/nitiwiki/examples/nitiwiki/pages/section/other_section/index.md b/contrib/nitiwiki/examples/nitiwiki/pages/section/other_section/index.md
new file mode 100644 (file)
index 0000000..0a918d5
--- /dev/null
@@ -0,0 +1,3 @@
+# A independant trail
+
+a [[trail: first]] and a [[trail: second]] page.
diff --git a/contrib/nitiwiki/examples/nitiwiki/pages/section/other_section/second.md b/contrib/nitiwiki/examples/nitiwiki/pages/section/other_section/second.md
new file mode 100644 (file)
index 0000000..ce04f0f
--- /dev/null
@@ -0,0 +1 @@
+a second page
index 05c06f9..8042af6 100644 (file)
@@ -313,17 +313,21 @@ redef class WikiArticle
 
                var res = new Template
                res.add "<ul class=\"trail\">"
-               if pos > 0 then
-                       var target = flat[pos-1]
-                       res.add "<li>{target.a_from(self, "prev")}</li>"
-               end
                var parent = wiki.trails.parent(self)
+               # Up and prev are disabled on a root
                if parent != null then
+                       if pos > 0 then
+                               var target = flat[pos-1]
+                               res.add "<li>{target.a_from(self, "prev")}</li>"
+                       end
                        res.add "<li>{parent.a_from(self, "up")}</li>"
                end
                if pos < flat.length - 1 then
                        var target = flat[pos+1]
-                       res.add "<li>{target.a_from(self, "next")}</li>"
+                       # Only print the next if it is not a root
+                       if target.parent != null then
+                               res.add "<li>{target.a_from(self, "next")}</li>"
+                       end
                end
                res.add "</ul>"