nitiwiki: add a dhref helper function
authorJean Privat <jean@pryen.org>
Thu, 3 Dec 2015 02:08:24 +0000 (21:08 -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 8042af6..1288d3c 100644 (file)
@@ -189,7 +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 = href.dirname.relpath("")
+                       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)
index 03f21ca..89cc55a 100644 (file)
@@ -100,12 +100,15 @@ redef class WikiEntry
        # Relative path to `self` from the target root_url
        fun href: String do return breadcrumbs.join("/")
 
+       # Relative path to the directory `self` from the target root_url
+       fun dir_href: String do return href.dirname
+
        # A relative `href` to `self` from the page `context`.
        #
        # Should be used to navigate between documents.
        fun href_from(context: WikiEntry): String
        do
-               var res = context.href.dirname.relpath(href)
+               var res = context.dir_href.relpath(href)
                return res
        end
 
@@ -174,6 +177,8 @@ redef class WikiSection
                end
                return new WikiSectionIndex(wiki, "index", self)
        end
+
+       redef fun dir_href do return href
 end
 
 redef class WikiArticle
@@ -212,6 +217,8 @@ class WikiSectionIndex
        redef fun title do return section.title
 
        redef fun href do return section.href
+
+       redef fun dir_href do return section.dir_href
 end
 
 # A MarkdownProcessor able to parse wiki links.