-------------------------------------------------------------------------------
-- 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>
-- <li>index.lp: index of modules and files;</li>
-- <li>file.lp: documentation for a lua file;</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>
-- </ul>
--
local package = package
local string = require"string"
local table = require"table"
+local luciutil = require "luci.util"
module "luadoc.doclet.html"
function include (template, env)
-- template_dir is relative to package.path
local templatepath = options.template_dir .. template
-
+
-- search using package.path (modified to search .lp instead of .lua
local search_path = string.gsub(package.path, "%.lua", "")
local templatepath = search(search_path, templatepath)
assert(templatepath, string.format("template `%s' not found", template))
-
+
env = env or {}
env.table = table
env.io = io
env.type = type
env.luadoc = luadoc
env.options = options
-
+
return lp.include(templatepath, env)
end
assert(modulename)
assert(doc)
from = from or ""
-
+
if doc.modules[modulename] == nil then
-- logger:error(string.format("unresolved reference to module `%s'", modulename))
return
end
-
+
local href = "modules/" .. modulename .. ".html"
string.gsub(from, "/", function () href = "../" .. href end)
return href
function file_link (to, from)
assert(to)
from = from or ""
-
+
local href = to
href = string.gsub(href, "lua$", "html")
href = string.gsub(href, "luadoc$", "html")
assert(doc)
from = from or ""
kind = kind or "functions"
-
+
+ --luciutil.dumptable( module_doc )
+
if file_doc then
for _, func_name in pairs(file_doc[kind]) do
if func_name == fname then
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, "^(.-)[%.%:]?([^%.%:]*)$")
assert(fname)
-- logger:error(string.format("unresolved reference to function `%s': module `%s' not found", fname, modulename))
return
end
-
+
for _, func_name in pairs(module_doc[kind]) do
if func_name == fname then
return module_link(modulename, doc, from) .. "#" .. fname
end
end
-
+
-- logger:error(string.format("unresolved reference to function `%s' of module `%s'", fname, modulename))
end
function symbol_link (symbol, doc, module_doc, file_doc, from)
assert(symbol)
assert(doc)
-
- local href =
+
+ local href =
-- 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, "tables")
-
+
if not href then
logger:error(string.format("unresolved reference to symbol `%s'", symbol))
end
-
+
return href or ""
end
include("index.lp", { doc = doc })
f:close()
end
-
+
-- Process modules
if not options.nomodules then
for _, modulename in ipairs(doc.modules) do
-- assembly the filename
local filename = out_module(modulename)
logger:info(string.format("generating file `%s'", filename))
-
+
local f = posix.open(filename, "w")
assert(f, string.format("could not open `%s' for writing", filename))
io.output(f)
-- assembly the filename
local filename = out_file(file_doc.name)
logger:info(string.format("generating file `%s'", filename))
-
+
local f = posix.open(filename, "w")
assert(f, string.format("could not open `%s' for writing", filename))
io.output(f)
f:close()
end
end
-
+
-- copy extra files
local f = posix.open(options.output_dir.."luadoc.css", "w")
io.output(f)