docs: move write_include out of the writer backend

This is a large chunk shared between backends.
This commit is contained in:
Daniel Kolesa 2017-10-20 14:29:04 +02:00
parent dbf48bf9f5
commit c48cde4aed
2 changed files with 78 additions and 76 deletions

View File

@ -22,8 +22,8 @@ M.nspace_to_path = function(ns)
return ns:gsub(":", path_sep):gsub(rep_sep, path_sep):lower()
end
M.make_page = function(path)
return M.path_join(doc_root, "auto", path .. ".txt")
M.make_page = function(path, ext)
return M.path_join(doc_root, "auto", path .. "." .. ext)
end
M.get_root_ns = function()

View File

@ -63,56 +63,7 @@ local Buffer = {
end
}
M.set_backend = function(bend)
M.Writer = assert(writers[bend], "invalid generation backend")
M.Buffer = M.Writer:clone(Buffer)
end
writers["dokuwiki"] = util.Object:clone {
INCLUDE_PAGE = 0,
INCLUDE_SECTION = 1,
INCLUDE_NAMESPACE = 2,
INCLUDE_TAG = 3,
__ctor = function(self, path, title)
local subs
if type(path) == "table" then
subs = dutil.path_join(unpack(path))
else
subs = dutil.nspace_to_path(path)
end
dutil.mkdir_p(subs)
self.file = assert(io.open(dutil.make_page(subs), "w"))
if title then
if M.has_feature("title") then
self:write_raw("<title>", title, "</title>")
self:write_nl()
else
self:write_h(title, 1)
end
end
end,
write_raw = function(self, ...)
self.file:write(...)
return self
end,
write_nl = function(self, n)
self:write_raw(("\n"):rep(n or 1))
return self
end,
write_h = function(self, heading, level, nonl)
local s = ("="):rep(7 - level)
self:write_raw(s, " ", heading, " ", s, "\n")
if not nonl then
self:write_nl()
end
return self
end,
write_include = function(self, tp, name, flags, nonl)
local write_include = function(self, tp, name, flags)
local it_to_tp = {
[self.INCLUDE_PAGE] = "page",
[self.INCLUDE_SECTION] = "section",
@ -181,12 +132,63 @@ writers["dokuwiki"] = util.Object:clone {
end
end
self:write_raw("}}")
self:write_nl()
return self
end
M.set_backend = function(bend)
M.Writer = assert(writers[bend], "invalid generation backend")
M.Buffer = M.Writer:clone(Buffer)
end
writers["dokuwiki"] = util.Object:clone {
INCLUDE_PAGE = 0,
INCLUDE_SECTION = 1,
INCLUDE_NAMESPACE = 2,
INCLUDE_TAG = 3,
__ctor = function(self, path, title)
local subs
if type(path) == "table" then
subs = dutil.path_join(unpack(path))
else
subs = dutil.nspace_to_path(path)
end
dutil.mkdir_p(subs)
self.file = assert(io.open(dutil.make_page(subs, "txt"), "w"))
if title then
if M.has_feature("title") then
self:write_raw("<title>", title, "</title>")
self:write_nl()
else
self:write_h(title, 1)
end
end
end,
write_raw = function(self, ...)
self.file:write(...)
return self
end,
write_nl = function(self, n)
self:write_raw(("\n"):rep(n or 1))
return self
end,
write_h = function(self, heading, level, nonl)
local s = ("="):rep(7 - level)
self:write_raw(s, " ", heading, " ", s, "\n")
if not nonl then
self:write_nl()
end
return self
end,
write_include = function(self, tp, name, flags)
return write_include(self, tp, name, flags)
end,
write_editable = function(self, ns, name)
ns[#ns + 1] = name
ns[#ns + 1] = false