forked from enlightenment/efl
docgen: move all path handling stuff to a single location
This commit is contained in:
parent
e9899fcf70
commit
d199a27000
30
gendoc.lua
30
gendoc.lua
|
@ -9,17 +9,31 @@ local verbose = false
|
||||||
|
|
||||||
-- utils
|
-- utils
|
||||||
|
|
||||||
|
local path_sep = "/"
|
||||||
|
|
||||||
|
local path_join = function(...)
|
||||||
|
return table.concat({ ... }, path_sep)
|
||||||
|
end
|
||||||
|
|
||||||
|
local path_to_nspace = function(p)
|
||||||
|
return p:gsub(path_sep, ":"):lower()
|
||||||
|
end
|
||||||
|
|
||||||
|
local nspace_to_path = function(ns)
|
||||||
|
return ns:gsub(":", path_sep):lower()
|
||||||
|
end
|
||||||
|
|
||||||
local make_page = function(path)
|
local make_page = function(path)
|
||||||
return doc_root .. "/" .. path .. ".txt"
|
return path_join(doc_root, path .. ".txt")
|
||||||
end
|
end
|
||||||
|
|
||||||
local mkdir_r = function(dirn)
|
local mkdir_r = function(dirn)
|
||||||
local fullp = dirn and (doc_root .. "/" .. dirn) or doc_root
|
local fullp = dirn and path_join(doc_root, dirn) or doc_root
|
||||||
local prev
|
local prev
|
||||||
for x in fullp:gmatch("[^/]+") do
|
for x in fullp:gmatch("[^" .. path_sep .. "]+") do
|
||||||
local p
|
local p
|
||||||
if prev then
|
if prev then
|
||||||
p = prev .. "/" .. x
|
p = path_join(prev, x)
|
||||||
else
|
else
|
||||||
p = x
|
p = x
|
||||||
end
|
end
|
||||||
|
@ -33,7 +47,7 @@ local mkdir_r = function(dirn)
|
||||||
end
|
end
|
||||||
|
|
||||||
local mkdir_p = function(path)
|
local mkdir_p = function(path)
|
||||||
mkdir_r(path:match("(.+)/([^/]+)"))
|
mkdir_r(path:match("(.+)" .. path_sep .. "([^" .. path_sep .. "]+)"))
|
||||||
end
|
end
|
||||||
|
|
||||||
local str_split = function(str, delim)
|
local str_split = function(str, delim)
|
||||||
|
@ -477,9 +491,9 @@ local Writer = util.Object:clone {
|
||||||
__ctor = function(self, path)
|
__ctor = function(self, path)
|
||||||
local subs
|
local subs
|
||||||
if type(path) == "table" then
|
if type(path) == "table" then
|
||||||
subs = table.concat(path, "/")
|
subs = path_join(unpack(path))
|
||||||
else
|
else
|
||||||
subs = path:gsub(":", "/"):lower()
|
subs = nspace_to_path(path)
|
||||||
end
|
end
|
||||||
mkdir_p(subs)
|
mkdir_p(subs)
|
||||||
self.file = assert(io.open(make_page(subs), "w"))
|
self.file = assert(io.open(make_page(subs), "w"))
|
||||||
|
@ -1238,7 +1252,7 @@ getopt.parse {
|
||||||
if not opts["r"] then
|
if not opts["r"] then
|
||||||
error("no documentation root supplied")
|
error("no documentation root supplied")
|
||||||
end
|
end
|
||||||
doc_root = opts["r"] .. "/" .. root_nspace:gsub(":", "/")
|
doc_root = path_join(opts["r"], nspace_to_path(root_nspace))
|
||||||
if not args[1] then
|
if not args[1] then
|
||||||
if not eolian.system_directory_scan() then
|
if not eolian.system_directory_scan() then
|
||||||
error("failed scanning system directory")
|
error("failed scanning system directory")
|
||||||
|
|
Loading…
Reference in New Issue