Merge: More keep going
[nit.git] / contrib / nitiwiki / src / wiki_base.nit
index dd1e2d6..b250071 100644 (file)
@@ -16,7 +16,6 @@
 module wiki_base
 
 import template::macro
-import markdown
 import opts
 import ini
 
@@ -116,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
@@ -189,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
@@ -516,18 +518,13 @@ class WikiArticle
        # Page content.
        #
        # What you want to be displayed in the page.
-       var content: nullable Writable = null
-
-       # Headlines ids and titles.
-       var headlines = new ArrayMap[String, HeadLine]
+       var content: nullable Writable = null is writable
 
-       # Create a new articleu sing a markdown source file.
+       # 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"))
-               var md_proc = new MarkdownProcessor
-               content = md_proc.process(md)
-               headlines = md_proc.emitter.decorator.headlines
+               init(wiki, md_file.basename(".{wiki.config.md_ext}"))
+               content = md
        end
 
        redef var src_full_path: nullable String = null
@@ -542,8 +539,8 @@ class WikiArticle
        # Extract the markdown text from `source_file`.
        #
        # REQUIRE: `has_source`.
-       var md: String is lazy do
-               assert has_source
+       var md: nullable String is lazy do
+               if not has_source then return null
                var file = new FileReader.open(src_full_path.to_s)
                var md = file.read_all
                file.close
@@ -605,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.
        #