forked from enlightenment/efl
docs: move write_include out of the writer backend
This is a large chunk shared between backends.
This commit is contained in:
parent
dbf48bf9f5
commit
c48cde4aed
|
@ -22,8 +22,8 @@ M.nspace_to_path = function(ns)
|
||||||
return ns:gsub(":", path_sep):gsub(rep_sep, path_sep):lower()
|
return ns:gsub(":", path_sep):gsub(rep_sep, path_sep):lower()
|
||||||
end
|
end
|
||||||
|
|
||||||
M.make_page = function(path)
|
M.make_page = function(path, ext)
|
||||||
return M.path_join(doc_root, "auto", path .. ".txt")
|
return M.path_join(doc_root, "auto", path .. "." .. ext)
|
||||||
end
|
end
|
||||||
|
|
||||||
M.get_root_ns = function()
|
M.get_root_ns = function()
|
||||||
|
|
|
@ -63,6 +63,79 @@ local Buffer = {
|
||||||
end
|
end
|
||||||
}
|
}
|
||||||
|
|
||||||
|
local write_include = function(self, tp, name, flags)
|
||||||
|
local it_to_tp = {
|
||||||
|
[self.INCLUDE_PAGE] = "page",
|
||||||
|
[self.INCLUDE_SECTION] = "section",
|
||||||
|
[self.INCLUDE_NAMESPACE] = "namespace",
|
||||||
|
[self.INCLUDE_TAG] = "tagtopic"
|
||||||
|
}
|
||||||
|
if type(name) == "table" then
|
||||||
|
if name[#name] == true then
|
||||||
|
name[#name] = nil
|
||||||
|
name = ":" .. root_nspace .. ":auto:"
|
||||||
|
.. table.concat(name, ":")
|
||||||
|
elseif name[#name] == false then
|
||||||
|
name[#name] = nil
|
||||||
|
name = ":" .. root_nspace .. ":user:"
|
||||||
|
.. table.concat(name, ":")
|
||||||
|
else
|
||||||
|
name = table.concat(name, ":")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
self:write_raw("{{", it_to_tp[tp], ">", name);
|
||||||
|
if flags then
|
||||||
|
if tp == self.INCLUDE_SECTION and flags.section then
|
||||||
|
self:write_raw("#", flags.section)
|
||||||
|
end
|
||||||
|
flags.section = nil
|
||||||
|
local flstr = {}
|
||||||
|
for k, v in pairs(flags) do
|
||||||
|
local allow = allowed_incflags[k]
|
||||||
|
if allow ~= nil then
|
||||||
|
if type(allow) == "boolean" then
|
||||||
|
flstr[#flstr + 1] = k
|
||||||
|
elseif type(allow) == "number" or type(allow) == "string" then
|
||||||
|
if type(v) ~= type(allow) then
|
||||||
|
error("invalid value type for flag " .. k)
|
||||||
|
end
|
||||||
|
flstr[#flstr + 1] = k .. "=" .. v
|
||||||
|
elseif type(allow) == "table" then
|
||||||
|
if type(allow[1]) == "table" then
|
||||||
|
local valid = false
|
||||||
|
for i, vv in ipairs(allow[1]) do
|
||||||
|
if v == vv then
|
||||||
|
flstr[#flstr + 1] = k .. "=" .. v
|
||||||
|
valid = true
|
||||||
|
break
|
||||||
|
end
|
||||||
|
end
|
||||||
|
if not valid then
|
||||||
|
error("invalid value " .. v .. " for flag " .. k)
|
||||||
|
end
|
||||||
|
elseif type(allow[1]) == "string" and
|
||||||
|
type(allow[2]) == "string" then
|
||||||
|
if v then
|
||||||
|
flstr[#flstr + 1] = allow[1]
|
||||||
|
else
|
||||||
|
flstr[#flstr + 1] = allow[2]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
else
|
||||||
|
error("invalid include flag: " .. tostring(k))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
flstr = table.concat(flstr, "&")
|
||||||
|
if #flstr > 0 then
|
||||||
|
self:write_raw("&", flstr)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
self:write_raw("}}")
|
||||||
|
self:write_nl()
|
||||||
|
return self
|
||||||
|
end
|
||||||
|
|
||||||
M.set_backend = function(bend)
|
M.set_backend = function(bend)
|
||||||
M.Writer = assert(writers[bend], "invalid generation backend")
|
M.Writer = assert(writers[bend], "invalid generation backend")
|
||||||
M.Buffer = M.Writer:clone(Buffer)
|
M.Buffer = M.Writer:clone(Buffer)
|
||||||
|
@ -82,7 +155,7 @@ writers["dokuwiki"] = util.Object:clone {
|
||||||
subs = dutil.nspace_to_path(path)
|
subs = dutil.nspace_to_path(path)
|
||||||
end
|
end
|
||||||
dutil.mkdir_p(subs)
|
dutil.mkdir_p(subs)
|
||||||
self.file = assert(io.open(dutil.make_page(subs), "w"))
|
self.file = assert(io.open(dutil.make_page(subs, "txt"), "w"))
|
||||||
if title then
|
if title then
|
||||||
if M.has_feature("title") then
|
if M.has_feature("title") then
|
||||||
self:write_raw("<title>", title, "</title>")
|
self:write_raw("<title>", title, "</title>")
|
||||||
|
@ -112,79 +185,8 @@ writers["dokuwiki"] = util.Object:clone {
|
||||||
return self
|
return self
|
||||||
end,
|
end,
|
||||||
|
|
||||||
write_include = function(self, tp, name, flags, nonl)
|
write_include = function(self, tp, name, flags)
|
||||||
local it_to_tp = {
|
return write_include(self, tp, name, flags)
|
||||||
[self.INCLUDE_PAGE] = "page",
|
|
||||||
[self.INCLUDE_SECTION] = "section",
|
|
||||||
[self.INCLUDE_NAMESPACE] = "namespace",
|
|
||||||
[self.INCLUDE_TAG] = "tagtopic"
|
|
||||||
}
|
|
||||||
if type(name) == "table" then
|
|
||||||
if name[#name] == true then
|
|
||||||
name[#name] = nil
|
|
||||||
name = ":" .. root_nspace .. ":auto:"
|
|
||||||
.. table.concat(name, ":")
|
|
||||||
elseif name[#name] == false then
|
|
||||||
name[#name] = nil
|
|
||||||
name = ":" .. root_nspace .. ":user:"
|
|
||||||
.. table.concat(name, ":")
|
|
||||||
else
|
|
||||||
name = table.concat(name, ":")
|
|
||||||
end
|
|
||||||
end
|
|
||||||
self:write_raw("{{", it_to_tp[tp], ">", name);
|
|
||||||
if flags then
|
|
||||||
if tp == self.INCLUDE_SECTION and flags.section then
|
|
||||||
self:write_raw("#", flags.section)
|
|
||||||
end
|
|
||||||
flags.section = nil
|
|
||||||
local flstr = {}
|
|
||||||
for k, v in pairs(flags) do
|
|
||||||
local allow = allowed_incflags[k]
|
|
||||||
if allow ~= nil then
|
|
||||||
if type(allow) == "boolean" then
|
|
||||||
flstr[#flstr + 1] = k
|
|
||||||
elseif type(allow) == "number" or type(allow) == "string" then
|
|
||||||
if type(v) ~= type(allow) then
|
|
||||||
error("invalid value type for flag " .. k)
|
|
||||||
end
|
|
||||||
flstr[#flstr + 1] = k .. "=" .. v
|
|
||||||
elseif type(allow) == "table" then
|
|
||||||
if type(allow[1]) == "table" then
|
|
||||||
local valid = false
|
|
||||||
for i, vv in ipairs(allow[1]) do
|
|
||||||
if v == vv then
|
|
||||||
flstr[#flstr + 1] = k .. "=" .. v
|
|
||||||
valid = true
|
|
||||||
break
|
|
||||||
end
|
|
||||||
end
|
|
||||||
if not valid then
|
|
||||||
error("invalid value " .. v .. " for flag " .. k)
|
|
||||||
end
|
|
||||||
elseif type(allow[1]) == "string" and
|
|
||||||
type(allow[2]) == "string" then
|
|
||||||
if v then
|
|
||||||
flstr[#flstr + 1] = allow[1]
|
|
||||||
else
|
|
||||||
flstr[#flstr + 1] = allow[2]
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
else
|
|
||||||
error("invalid include flag: " .. tostring(k))
|
|
||||||
end
|
|
||||||
end
|
|
||||||
flstr = table.concat(flstr, "&")
|
|
||||||
if #flstr > 0 then
|
|
||||||
self:write_raw("&", flstr)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
self:write_raw("}}")
|
|
||||||
if not nonl then
|
|
||||||
self:write_nl()
|
|
||||||
end
|
|
||||||
return self
|
|
||||||
end,
|
end,
|
||||||
|
|
||||||
write_editable = function(self, ns, name)
|
write_editable = function(self, ns, name)
|
||||||
|
|
Loading…
Reference in New Issue