nitiwiki: change position of sidebar from config
authorAlexandre Terrasa <alexandre@moz-code.org>
Tue, 2 Jun 2015 02:50:59 +0000 (22:50 -0400)
committerAlexandre Terrasa <alexandre@moz-code.org>
Wed, 10 Jun 2015 00:39:03 +0000 (20:39 -0400)
Signed-off-by: Alexandre Terrasa <alexandre@moz-code.org>

contrib/nitiwiki/src/wiki_base.nit
contrib/nitiwiki/src/wiki_html.nit

index b250071..c8df2d5 100644 (file)
@@ -702,6 +702,17 @@ class WikiConfig
                return value_or_default("wiki.footer", "footer.html")
        end
 
+       # Sidebar position.
+       #
+       # Position of the sidebar between `left`, `right` and `none`. Any other value
+       # will be considered as `none`.
+       #
+       # * key: `wiki.sidebar`
+       # * default: `left`
+       var sidebar: String is lazy do
+               return value_or_default("wiki.sidebar", "left")
+       end
+
        # Directory used by rsync to upload wiki files.
        #
        # This information is used to update your distant wiki files (like the webserver).
index 46518aa..1b582ab 100644 (file)
@@ -214,6 +214,7 @@ redef class WikiArticle
                article.breadcrumbs = new TplBreadcrumbs(self)
                tpl_sidebar.blocks.add tpl_summary
                article.sidebar = tpl_sidebar
+               article.sidebar_pos = wiki.config.sidebar
                return article
        end
 
@@ -327,6 +328,11 @@ class TplArticle
        # Sidebar of this article (if any).
        var sidebar: nullable TplSidebar = null
 
+       # Position of the sidebar.
+       #
+       # See `WikiConfig::sidebar`.
+       var sidebar_pos: String = "left"
+
        # Breadcrumbs from wiki root to this article.
        var breadcrumbs: nullable TplBreadcrumbs = null
 
@@ -336,13 +342,11 @@ class TplArticle
        end
 
        redef fun rendering do
-               if sidebar != null then
-                       add "<div class=\"col-sm-3 sidebar\">"
-                       add sidebar.as(not null)
-                       add "</div>"
-                       add "<div class=\"col-sm-9 content\">"
-               else
+               if sidebar_pos == "left" then render_sidebar
+               if sidebar == null then
                        add "<div class=\"col-sm-12 content\">"
+               else
+                       add "<div class=\"col-sm-9 content\">"
                end
                if body != null then
                        add "<article>"
@@ -358,6 +362,14 @@ class TplArticle
                        add " </article>"
                end
                add "</div>"
+               if sidebar_pos == "right" then render_sidebar
+       end
+
+       private fun render_sidebar do
+               if sidebar == null then return
+               add "<div class=\"col-sm-3 sidebar\">"
+               add sidebar.as(not null)
+               add "</div>"
        end
 end