nitiwiki: add root_href if the wiki need it
authorJean Privat <jean@pryen.org>
Thu, 3 Dec 2015 02:09:44 +0000 (21:09 -0500)
committerJean Privat <jean@pryen.org>
Thu, 3 Dec 2015 20:55:00 +0000 (15:55 -0500)
Signed-off-by: Jean Privat <jean@pryen.org>

contrib/nitiwiki/src/wiki_html.nit
contrib/nitiwiki/src/wiki_links.nit

index 1288d3c..ab79f09 100644 (file)
@@ -189,10 +189,7 @@ redef class WikiArticle
        fun load_template(template_file: String): TemplateString do
                var tpl = wiki.load_template(template_file)
                if tpl.has_macro("ROOT_URL") then
-                       var root_dir = dhref.relpath("")
-                       # Avoid issues if the macro is just followed by a `/` (as with url prefix)
-                       if root_dir == "" then root_dir = "."
-                       tpl.replace("ROOT_URL", root_dir)
+                       tpl.replace("ROOT_URL", root_href)
                end
                return tpl
        end
index 89cc55a..c1785b2 100644 (file)
@@ -103,6 +103,14 @@ redef class WikiEntry
        # Relative path to the directory `self` from the target root_url
        fun dir_href: String do return href.dirname
 
+       # Relative path to the root url from `self`
+       fun root_href: String do
+               var root_dir = dir_href.relpath("")
+               # Avoid issues if used as a macro just followed by a `/` (as with url prefix)
+               if root_dir == "" then root_dir = "."
+               return root_dir
+       end
+
        # A relative `href` to `self` from the page `context`.
        #
        # Should be used to navigate between documents.