Merge: Nitiwiki next
authorJean Privat <jean@pryen.org>
Tue, 26 May 2015 12:37:54 +0000 (08:37 -0400)
committerJean Privat <jean@pryen.org>
Tue, 26 May 2015 12:37:54 +0000 (08:37 -0400)
Some fixes for `nitiwiki`.

Preparing for nitlanguage.org migration from ikiwiki to nitiwiki.

Pull-Request: #1367
Reviewed-by: Jean Privat <jean@pryen.org>
Reviewed-by: Lucas Bajolet <r4pass@hotmail.com>
Reviewed-by: Romain Chanoir <chanoir.romain@courrier.uqam.ca>

15 files changed:
contrib/nitiwiki/src/wiki_base.nit
contrib/nitiwiki/src/wiki_html.nit
contrib/nitiwiki/tests/res/wiki3_nitiwiki_render.res [new file with mode: 0644]
contrib/nitiwiki/tests/res/wiki3_nitiwiki_status.res [new file with mode: 0644]
contrib/nitiwiki/tests/wiki3/config.ini [new file with mode: 0644]
contrib/nitiwiki/tests/wiki3/pages/contact.mdwn [new file with mode: 0644]
contrib/nitiwiki/tests/wiki3/pages/index.mdwn [new file with mode: 0644]
contrib/nitiwiki/tests/wiki3/pages/other_page.mdwn [new file with mode: 0644]
contrib/nitiwiki/tests/wiki3/templates/footer.html [new file with mode: 0644]
contrib/nitiwiki/tests/wiki3/templates/header.html [new file with mode: 0644]
contrib/nitiwiki/tests/wiki3/templates/menu.html [new file with mode: 0644]
contrib/nitiwiki/tests/wiki3/templates/template.html [new file with mode: 0644]
contrib/nitiwiki/tests/wiki3_nitiwiki_render.args [new file with mode: 0644]
contrib/nitiwiki/tests/wiki3_nitiwiki_status.args [new file with mode: 0644]
lib/markdown/decorators.nit

index 56cbbcb..b250071 100644 (file)
@@ -115,11 +115,11 @@ class Nitiwiki
        # List markdown source files from a directory.
        fun list_md_files(dir: String): Array[String] do
                var files = new Array[String]
-               var pipe = new ProcessReader("find", dir, "-name", "*.md")
+               var pipe = new ProcessReader("find", dir, "-name", "*.{config.md_ext}")
                while not pipe.eof do
                        var file = pipe.read_line
                        if file == "" then break # last line
-                       var name = file.basename(".md")
+                       var name = file.basename(".{config.md_ext}")
                        if name == "header" or name == "footer" or name == "menu" then continue
                        files.add file
                end
@@ -188,7 +188,10 @@ class Nitiwiki
        #
        # REQUIRE: `has_template`
        fun load_template(name: String): TemplateString do
-               assert has_template(name)
+               if not has_template(name) then
+                       message("Error: can't load template `{name}`", 0)
+                       exit 1
+               end
                var file = expand_path(config.root_dir, config.templates_dir, name)
                var tpl = new TemplateString.from_file(file)
                if tpl.has_macro("ROOT_URL") then
@@ -520,7 +523,7 @@ class WikiArticle
        # Create a new article using a markdown source file.
        init from_source(wiki: Nitiwiki, md_file: String) do
                src_full_path = md_file
-               init(wiki, md_file.basename(".md"))
+               init(wiki, md_file.basename(".{wiki.config.md_ext}"))
                content = md
        end
 
@@ -599,6 +602,14 @@ class WikiConfig
        # * default: `http://localhost/`
        var root_url: String is lazy do return value_or_default("wiki.root_url", "http://localhost/")
 
+       # Markdown extension recognized by this wiki.
+       #
+       # We allow only one kind of extension per wiki.
+       # Files with other markdown extensions will be treated as resources.
+       #
+       # * key: `wiki.md_ext`
+       # * default: `md`
+       var md_ext: String is lazy do return value_or_default("wiki.md_ext", "md")
 
        # Root directory of the wiki.
        #
index 461e9e5..46518aa 100644 (file)
@@ -16,6 +16,7 @@
 module wiki_html
 
 import wiki_links
+import markdown::decorators
 
 redef class Nitiwiki
 
@@ -45,6 +46,18 @@ redef class Nitiwiki
                sitemap.is_dirty = true
                return sitemap
        end
+
+       # Markdown processor used for inline element such as titles in TOC.
+       private var inline_processor: MarkdownProcessor is lazy do
+               var proc = new MarkdownProcessor
+               proc.emitter.decorator = new InlineDecorator
+               return proc
+       end
+
+       # Inline markdown (remove h1, p, ... elements).
+       private fun inline_md(md: Writable): Writable do
+               return inline_processor.process(md.write_to_string)
+       end
 end
 
 redef class WikiEntry
@@ -218,8 +231,7 @@ redef class WikiArticle
                while iter.is_ok do
                        var hl = iter.item
                        # parse title as markdown
-                       var title = hl.title.md_to_html.to_s
-                       title = title.substring(3, title.length - 8)
+                       var title = wiki.inline_md(hl.title)
                        tpl.add "<li><a href=\"#{hl.id}\">{title}</a>"
                        iter.next
                        if iter.is_ok then
diff --git a/contrib/nitiwiki/tests/res/wiki3_nitiwiki_render.res b/contrib/nitiwiki/tests/res/wiki3_nitiwiki_render.res
new file mode 100644 (file)
index 0000000..adf25a7
--- /dev/null
@@ -0,0 +1 @@
+Render section out
diff --git a/contrib/nitiwiki/tests/res/wiki3_nitiwiki_status.res b/contrib/nitiwiki/tests/res/wiki3_nitiwiki_status.res
new file mode 100644 (file)
index 0000000..2451916
--- /dev/null
@@ -0,0 +1,12 @@
+nitiWiki
+name: wiki3
+config: wiki3/config.ini
+url: http://localhost/
+
+There is modified files:
+ + pages
+ + /pages/contact.mdwn
+ + /pages/index.mdwn
+ + /pages/other_page.mdwn
+
+Use nitiwiki --render to render modified files
diff --git a/contrib/nitiwiki/tests/wiki3/config.ini b/contrib/nitiwiki/tests/wiki3/config.ini
new file mode 100644 (file)
index 0000000..111f22b
--- /dev/null
@@ -0,0 +1,3 @@
+wiki.name=wiki3
+wiki.root_dir=wiki3
+wiki.md_ext=mdwn
diff --git a/contrib/nitiwiki/tests/wiki3/pages/contact.mdwn b/contrib/nitiwiki/tests/wiki3/pages/contact.mdwn
new file mode 100644 (file)
index 0000000..09f7129
--- /dev/null
@@ -0,0 +1 @@
+# Contact
diff --git a/contrib/nitiwiki/tests/wiki3/pages/index.mdwn b/contrib/nitiwiki/tests/wiki3/pages/index.mdwn
new file mode 100644 (file)
index 0000000..8b013d6
--- /dev/null
@@ -0,0 +1 @@
+# Index
diff --git a/contrib/nitiwiki/tests/wiki3/pages/other_page.mdwn b/contrib/nitiwiki/tests/wiki3/pages/other_page.mdwn
new file mode 100644 (file)
index 0000000..a1ca7d9
--- /dev/null
@@ -0,0 +1 @@
+# Other Page
diff --git a/contrib/nitiwiki/tests/wiki3/templates/footer.html b/contrib/nitiwiki/tests/wiki3/templates/footer.html
new file mode 100644 (file)
index 0000000..7506b39
--- /dev/null
@@ -0,0 +1,10 @@
+<div class="row footer">
+       <div class="container-fluid">
+               <div class="well well-sm">
+                       <p><strong>%TITLE% &copy; %YEAR%</strong></p>
+                       <p class="text-muted"><em>last modification %GEN_TIME%</em></p>
+                       <p class="text-muted">Proudly powered by
+                               <a href="http://nitlanguage.org">nit</a>!</p>
+               </div>
+       </div>
+</div>
diff --git a/contrib/nitiwiki/tests/wiki3/templates/header.html b/contrib/nitiwiki/tests/wiki3/templates/header.html
new file mode 100644 (file)
index 0000000..1cb06bf
--- /dev/null
@@ -0,0 +1,9 @@
+<div class="container-fluid header">
+       <div class="container">
+               <div class="header">
+                       <a href="http://uqam.ca"><img src="%ROOT_URL%/%LOGO%" alt="logo" /></a>
+                       <h2>%SUBTITLE%</h2>
+                       <h1>%TITLE%</h1>
+               </div>
+       </div>
+</div>
diff --git a/contrib/nitiwiki/tests/wiki3/templates/menu.html b/contrib/nitiwiki/tests/wiki3/templates/menu.html
new file mode 100644 (file)
index 0000000..1ff832e
--- /dev/null
@@ -0,0 +1,20 @@
+<nav class="menu" role="navigation">
+       <div class="container">
+               <!-- Brand and toggle get grouped for better mobile display -->
+               <div class="navbar-header">
+                       <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
+                               <span class="sr-only">Toggle navigation</span>
+                               <span class="icon-bar"></span>
+                               <span class="icon-bar"></span>
+                               <span class="icon-bar"></span>
+                       </button>
+                       <a class="navbar-brand" href="%ROOT_URL%index.html">%TITLE%</a>
+               </div>
+               <!-- Collect the nav links, forms, and other content for toggling -->
+               <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
+                       <ul class="nav navbar-nav">
+                       %MENUS%
+                       </ul>
+               </div><!-- /.navbar-collapse -->
+       </div>
+</nav>
diff --git a/contrib/nitiwiki/tests/wiki3/templates/template.html b/contrib/nitiwiki/tests/wiki3/templates/template.html
new file mode 100644 (file)
index 0000000..6b3b126
--- /dev/null
@@ -0,0 +1,32 @@
+<!DOCTYPE html>
+<html lang="en">
+       <head>
+               <meta charset="utf-8">
+               <meta http-equiv="X-UA-Compatible" content="IE=edge">
+               <meta name="viewport" content="width=device-width, initial-scale=1">
+               <title>%TITLE%</title>
+
+               <link href="%ROOT_URL%/assets/vendors/bootstrap/bootstrap-3.2.0-dist/css/bootstrap.min.css" rel="stylesheet">
+               <link href="%ROOT_URL%/assets/css/main.css" rel="stylesheet">
+
+               <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
+               <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
+               <!--[if lt IE 9]>
+               <script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
+               <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
+               <![endif]-->
+       </head>
+       <body>
+               %HEADER%
+               %TOP_MENU%
+               <div class="container">
+                       <div class="row">
+                               %BODY%
+                       </div>
+                       %FOOTER%
+               </div>
+
+               <script src="%ROOT_URL%/vendors/jquery/jquery-1.11.1.min.js"></script>
+               <script src="%ROOT_URL%/vendors/bootstrap/bootstrap-3.2.0-dist/js/bootstrap.min.js"></script>
+       </body>
+</html>
diff --git a/contrib/nitiwiki/tests/wiki3_nitiwiki_render.args b/contrib/nitiwiki/tests/wiki3_nitiwiki_render.args
new file mode 100644 (file)
index 0000000..75ceb1c
--- /dev/null
@@ -0,0 +1 @@
+../bin/nitiwiki --config wiki3/config.ini --clean --render -v
diff --git a/contrib/nitiwiki/tests/wiki3_nitiwiki_status.args b/contrib/nitiwiki/tests/wiki3_nitiwiki_status.args
new file mode 100644 (file)
index 0000000..c148644
--- /dev/null
@@ -0,0 +1 @@
+../bin/nitiwiki --config wiki3/config.ini --clean --status
index 1a83394..f33302f 100644 (file)
@@ -1,4 +1,5 @@
 # This file is part of NIT ( http://www.nitlanguage.org ).
+#
 # Licensed under the Apache License, Version 2.0 (the "License");
 # you may not use this file except in compliance with the License.
 # You may obtain a copy of the License at
@@ -184,3 +185,19 @@ class MdDecorator
 
        private var allowed_id_chars: Array[Char] = ['-', '_', ':', '.']
 end
+
+# Decorator for span elements.
+#
+# InlineDecorator does not decorate things like paragraphs or headers.
+class InlineDecorator
+       super HTMLDecorator
+
+       redef fun add_paragraph(v, block) do v.emit_in block
+       redef fun add_headline(v, block) do v.emit_in block
+
+       redef fun add_code(v, block) do
+               v.add "<code>"
+               v.emit_in block
+               v.add "</code>"
+       end
+end