* luci/contrib: fixed anchors in virtual module documentation, only render parameters to html which have a corresponding @param tag

This commit is contained in:
Jo-Philipp Wich 2008-08-09 16:36:16 +00:00
parent e4f0c97551
commit d8ed736906
2 changed files with 33 additions and 22 deletions

View file

@ -1,11 +1,11 @@
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
-- Doclet that generates HTML output. This doclet generates a set of html files -- Doclet that generates HTML output. This doclet generates a set of html files
-- based on a group of templates. The main templates are: -- based on a group of templates. The main templates are:
-- <ul> -- <ul>
-- <li>index.lp: index of modules and files;</li> -- <li>index.lp: index of modules and files;</li>
-- <li>file.lp: documentation for a lua file;</li> -- <li>file.lp: documentation for a lua file;</li>
-- <li>module.lp: documentation for a lua module;</li> -- <li>module.lp: documentation for a lua module;</li>
-- <li>function.lp: documentation for a lua function. This is a -- <li>function.lp: documentation for a lua function. This is a
-- sub-template used by the others.</li> -- sub-template used by the others.</li>
-- </ul> -- </ul>
-- --
@ -20,6 +20,7 @@ local luadoc = require"luadoc"
local package = package local package = package
local string = require"string" local string = require"string"
local table = require"table" local table = require"table"
local luciutil = require "luci.util"
module "luadoc.doclet.html" module "luadoc.doclet.html"
@ -48,12 +49,12 @@ end
function include (template, env) function include (template, env)
-- template_dir is relative to package.path -- template_dir is relative to package.path
local templatepath = options.template_dir .. template local templatepath = options.template_dir .. template
-- search using package.path (modified to search .lp instead of .lua -- search using package.path (modified to search .lp instead of .lua
local search_path = string.gsub(package.path, "%.lua", "") local search_path = string.gsub(package.path, "%.lua", "")
local templatepath = search(search_path, templatepath) local templatepath = search(search_path, templatepath)
assert(templatepath, string.format("template `%s' not found", template)) assert(templatepath, string.format("template `%s' not found", template))
env = env or {} env = env or {}
env.table = table env.table = table
env.io = io env.io = io
@ -64,7 +65,7 @@ function include (template, env)
env.type = type env.type = type
env.luadoc = luadoc env.luadoc = luadoc
env.options = options env.options = options
return lp.include(templatepath, env) return lp.include(templatepath, env)
end end
@ -93,12 +94,12 @@ function module_link (modulename, doc, from)
assert(modulename) assert(modulename)
assert(doc) assert(doc)
from = from or "" from = from or ""
if doc.modules[modulename] == nil then if doc.modules[modulename] == nil then
-- logger:error(string.format("unresolved reference to module `%s'", modulename)) -- logger:error(string.format("unresolved reference to module `%s'", modulename))
return return
end end
local href = "modules/" .. modulename .. ".html" local href = "modules/" .. modulename .. ".html"
string.gsub(from, "/", function () href = "../" .. href end) string.gsub(from, "/", function () href = "../" .. href end)
return href return href
@ -116,7 +117,7 @@ end
function file_link (to, from) function file_link (to, from)
assert(to) assert(to)
from = from or "" from = from or ""
local href = to local href = to
href = string.gsub(href, "lua$", "html") href = string.gsub(href, "lua$", "html")
href = string.gsub(href, "luadoc$", "html") href = string.gsub(href, "luadoc$", "html")
@ -136,7 +137,9 @@ function link_to (fname, doc, module_doc, file_doc, from, kind)
assert(doc) assert(doc)
from = from or "" from = from or ""
kind = kind or "functions" kind = kind or "functions"
--luciutil.dumptable( module_doc )
if file_doc then if file_doc then
for _, func_name in pairs(file_doc[kind]) do for _, func_name in pairs(file_doc[kind]) do
if func_name == fname then if func_name == fname then
@ -144,7 +147,15 @@ function link_to (fname, doc, module_doc, file_doc, from, kind)
end end
end end
end end
if module_doc and module_doc[kind] then
for func_name, tbl in pairs(module_doc[kind]) do
if func_name == fname then
return "#" .. fname
end
end
end
local _, _, modulename, fname = string.find(fname, "^(.-)[%.%:]?([^%.%:]*)$") local _, _, modulename, fname = string.find(fname, "^(.-)[%.%:]?([^%.%:]*)$")
assert(fname) assert(fname)
@ -158,13 +169,13 @@ function link_to (fname, doc, module_doc, file_doc, from, kind)
-- logger:error(string.format("unresolved reference to function `%s': module `%s' not found", fname, modulename)) -- logger:error(string.format("unresolved reference to function `%s': module `%s' not found", fname, modulename))
return return
end end
for _, func_name in pairs(module_doc[kind]) do for _, func_name in pairs(module_doc[kind]) do
if func_name == fname then if func_name == fname then
return module_link(modulename, doc, from) .. "#" .. fname return module_link(modulename, doc, from) .. "#" .. fname
end end
end end
-- logger:error(string.format("unresolved reference to function `%s' of module `%s'", fname, modulename)) -- logger:error(string.format("unresolved reference to function `%s' of module `%s'", fname, modulename))
end end
@ -174,17 +185,17 @@ end
function symbol_link (symbol, doc, module_doc, file_doc, from) function symbol_link (symbol, doc, module_doc, file_doc, from)
assert(symbol) assert(symbol)
assert(doc) assert(doc)
local href = local href =
-- file_link(symbol, from) or -- file_link(symbol, from) or
module_link(symbol, doc, from) or module_link(symbol, doc, from) or
link_to(symbol, doc, module_doc, file_doc, from, "functions") or link_to(symbol, doc, module_doc, file_doc, from, "functions") or
link_to(symbol, doc, module_doc, file_doc, from, "tables") link_to(symbol, doc, module_doc, file_doc, from, "tables")
if not href then if not href then
logger:error(string.format("unresolved reference to symbol `%s'", symbol)) logger:error(string.format("unresolved reference to symbol `%s'", symbol))
end end
return href or "" return href or ""
end end
@ -226,7 +237,7 @@ function start (doc)
include("index.lp", { doc = doc }) include("index.lp", { doc = doc })
f:close() f:close()
end end
-- Process modules -- Process modules
if not options.nomodules then if not options.nomodules then
for _, modulename in ipairs(doc.modules) do for _, modulename in ipairs(doc.modules) do
@ -234,7 +245,7 @@ function start (doc)
-- assembly the filename -- assembly the filename
local filename = out_module(modulename) local filename = out_module(modulename)
logger:info(string.format("generating file `%s'", filename)) logger:info(string.format("generating file `%s'", filename))
local f = posix.open(filename, "w") local f = posix.open(filename, "w")
assert(f, string.format("could not open `%s' for writing", filename)) assert(f, string.format("could not open `%s' for writing", filename))
io.output(f) io.output(f)
@ -250,7 +261,7 @@ function start (doc)
-- assembly the filename -- assembly the filename
local filename = out_file(file_doc.name) local filename = out_file(file_doc.name)
logger:info(string.format("generating file `%s'", filename)) logger:info(string.format("generating file `%s'", filename))
local f = posix.open(filename, "w") local f = posix.open(filename, "w")
assert(f, string.format("could not open `%s' for writing", filename)) assert(f, string.format("could not open `%s' for writing", filename))
io.output(f) io.output(f)
@ -258,7 +269,7 @@ function start (doc)
f:close() f:close()
end end
end end
-- copy extra files -- copy extra files
local f = posix.open(options.output_dir.."luadoc.css", "w") local f = posix.open(options.output_dir.."luadoc.css", "w")
io.output(f) io.output(f)

View file

@ -55,7 +55,7 @@ local function check_function (line)
return { return {
name = id, name = id,
private = (l == "local"), private = (l == "local"),
param = util.split("%s*,%s*", param), param = { } --util.split("%s*,%s*", param),
} }
end end
end) end)