X-Git-Url: http://nitlanguage.org
diff --git a/contrib/nitiwiki/src/wiki_html.nit b/contrib/nitiwiki/src/wiki_html.nit
index 8bb91f8..ab79f09 100644
--- a/contrib/nitiwiki/src/wiki_html.nit
+++ b/contrib/nitiwiki/src/wiki_html.nit
@@ -36,7 +36,7 @@ redef class Nitiwiki
var src = expand_path(config.root_dir, config.assets_dir)
var out = expand_path(config.root_dir, config.out_dir)
if need_render(src, expand_path(out, config.assets_dir)) then
- if src.file_exists then sys.system "cp -R {src} {out}"
+ if src.file_exists then sys.system "cp -R -- {src.escape_to_sh} {out.escape_to_sh}"
end
end
@@ -83,18 +83,21 @@ redef class WikiSection
if is_new then
out_full_path.mkdir
else
- sys.system "touch {out_full_path}"
+ sys.system "touch -- {out_full_path.escape_to_sh}"
end
if has_source then
- wiki.message("Render section {out_path}", 1)
+ wiki.message("Render section {name} -> {out_path}", 1)
copy_files
end
var index = self.index
if index isa WikiSectionIndex then
- wiki.message("Render auto-index for section {out_path}", 1)
+ wiki.message("Render auto-index for section {name} -> {out_path}", 1)
index.is_dirty = true
add_child index
end
+ # Hack: Force the rendering of `index` first so that trails are collected
+ # TODO: Add first-pass analysis to collect global information before doing the rendering
+ index.render
super
end
@@ -109,7 +112,7 @@ redef class WikiSection
var src = wiki.expand_path(dir, name)
var out = wiki.expand_path(out_full_path, name)
if not wiki.need_render(src, out) then continue
- sys.system "cp -R {src} {out_full_path}"
+ sys.system "cp -R -- {src.escape_to_sh} {out_full_path.escape_to_sh}"
end
end
@@ -133,15 +136,15 @@ redef class WikiSection
#
# ~~~
fun tpl_tree(limit: Int): Template do
- return tpl_tree_intern(limit, 1)
+ return tpl_tree_intern(limit, 1, self)
end
# Build the template tree for this section recursively.
- protected fun tpl_tree_intern(limit, count: Int): Template do
+ protected fun tpl_tree_intern(limit, count: Int, context: WikiEntry): Template do
var out = new Template
var index = index
out.add "
"
- out.add tpl_link(self)
+ out.add tpl_link(context)
if (limit < 0 or count < limit) and
(children.length > 1 or (children.length == 1)) then
out.add " "
@@ -149,10 +152,10 @@ redef class WikiSection
if child == index then continue
if child isa WikiArticle then
out.add "- "
- out.add child.tpl_link(self)
+ out.add child.tpl_link(context)
out.add "
"
else if child isa WikiSection and not child.is_hidden then
- out.add child.tpl_tree_intern(limit, count + 1)
+ out.add child.tpl_tree_intern(limit, count + 1, context)
end
end
out.add "
"
@@ -175,8 +178,8 @@ redef class WikiArticle
redef fun render do
super
if not is_dirty and not wiki.force_render then return
- wiki.message("Render article {name}", 2)
var file = out_full_path
+ wiki.message("Render article {name} -> {file}", 1)
file.dirname.mkdir
tpl_page.write_to_file file
end
@@ -185,6 +188,9 @@ redef class WikiArticle
# Load a template and resolve page-related macros
fun load_template(template_file: String): TemplateString do
var tpl = wiki.load_template(template_file)
+ if tpl.has_macro("ROOT_URL") then
+ tpl.replace("ROOT_URL", root_href)
+ end
return tpl
end
@@ -203,6 +209,9 @@ redef class WikiArticle
if tpl.has_macro("FOOTER") then
tpl.replace("FOOTER", tpl_footer)
end
+ if tpl.has_macro("TRAIL") then
+ tpl.replace("TRAIL", tpl_trail)
+ end
return tpl
end
@@ -287,6 +296,41 @@ redef class WikiArticle
return tpl
end
+ # Generate navigation links for the trail of this article, if any.
+ #
+ # A trail is generated if the article include or is included in a trail.
+ # See `wiki.trails` for details.
+ fun tpl_trail: Writable do
+ if not wiki.trails.has(self) then return ""
+
+ # Get the position of `self` in the trail
+ var flat = wiki.trails.to_a
+ var pos = flat.index_of(self)
+ assert pos >= 0
+
+ var res = new Template
+ res.add ""
+ var parent = wiki.trails.parent(self)
+ # Up and prev are disabled on a root
+ if parent != null then
+ if pos > 0 then
+ var target = flat[pos-1]
+ res.add "- {target.a_from(self, "prev")}
"
+ end
+ res.add "- {parent.a_from(self, "up")}
"
+ end
+ if pos < flat.length - 1 then
+ var target = flat[pos+1]
+ # Only print the next if it is not a root
+ if target.parent != null then
+ res.add "- {target.a_from(self, "next")}
"
+ end
+ end
+ res.add "
"
+
+ return res
+ end
+
# Generate the HTML footer for this article.
fun tpl_footer: Writable do
var file = footer_file