* luci/contrib: added support for constants documentation in luadoc

This commit is contained in:
Jo-Philipp Wich 2008-08-09 18:38:16 +00:00
parent fa2d17a3f9
commit 7528812494
3 changed files with 87 additions and 2 deletions

View file

@ -0,0 +1,28 @@
<%
if module_doc then
from = "modules/"..module_doc.name
elseif file_doc then
from = "files/.."..file_doc.name
else
from = ""
end
%>
<dt><%=const.private and "local " or ""%><a name="<%=const.name%>"></a><strong><%=const.name:gsub(".+%.","")%></strong></dt>
<dd>
<%=const.description or ""%>
<%if type(const.see) == "string" then %>
<h3>See also:</h3>
<a href="<%=const.see%>"><%=const.see%></a>
<%elseif type(const.see) == "table" and #const.see > 0 then %>
<h3>See also:</h3>
<ul>
<%for i = 1, #const.see do%>
<li><a href="<%=luadoc.doclet.html.symbol_link(const.see[i], doc, module_doc, file_doc, from)%>">
<%=const.see[i]:gsub(".+%.","")%>
</a>
<%end%>
</ul
<%end%>
</dd>

View file

@ -45,6 +45,19 @@
<p><small><b>Release:</b> <%=module_doc.release%></small></p> <p><small><b>Release:</b> <%=module_doc.release%></small></p>
<%end%> <%end%>
<%if #module_doc.constants > 0 then %>
<h2>Constants</h2>
<table class="function_list">
<%for _, const_name in ipairs(module_doc.constants) do
local const_data = module_doc.constants[const_name]%>
<tr>
<td class="name" nowrap><code><%=const_data.private and "local " or ""%><%=(const_name:gsub(".+%.",""))%></code></td>
<td class="summary"><%=const_data.summary%></td>
</tr>
<%end%>
</table>
<%end%>
<%if #module_doc.functions > 0 then %> <%if #module_doc.functions > 0 then %>
<h2>Functions</h2> <h2>Functions</h2>
<table class="function_list"> <table class="function_list">
@ -75,7 +88,6 @@
<br/> <br/>
<br/> <br/>
<%if #module_doc.functions > 0 then%> <%if #module_doc.functions > 0 then%>
<h2><a name="functions"></a>Functions</h2> <h2><a name="functions"></a>Functions</h2>
<dl class="function"> <dl class="function">
@ -85,7 +97,6 @@
</dl> </dl>
<%end%> <%end%>
<%if #module_doc.tables > 0 then%> <%if #module_doc.tables > 0 then%>
<h2><a name="tables"></a>Tables</h2> <h2><a name="tables"></a>Tables</h2>
<dl class="table"> <dl class="table">

View file

@ -96,6 +96,38 @@ local function check_module (line, currentmodule)
return currentmodule return currentmodule
end end
-- Patterns for constant recognition
local constant_patterns = {
"^()%s*([A-Z][A-Z0-9_]*)%s*=",
"^%s*(local%s)%s*([A-Z][A-Z0-9_]*)%s*=",
}
-------------------------------------------------------------------------------
-- Checks if the line contains a constant definition
-- @param line string with line text
-- @return constant information or nil if no constant definition found
local function check_constant (line)
line = util.trim(line)
local info = table.foreachi(constant_patterns, function (_, pattern)
local r, _, l, id = string.find(line, pattern)
if r ~= nil then
return {
name = id,
private = (l == "local"),
}
end
end)
-- TODO: remove these assert's?
if info ~= nil then
assert(info.name, "constant name undefined")
end
return info
end
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
-- Extracts summary information from a description. The first sentence of each -- Extracts summary information from a description. The first sentence of each
-- doc comment should be a summary sentence, containing a concise but complete -- doc comment should be a summary sentence, containing a concise but complete
@ -172,11 +204,16 @@ local function parse_comment (block, first_line, modulename)
if code ~= nil then if code ~= nil then
local func_info = check_function(code) local func_info = check_function(code)
local module_name = check_module(code) local module_name = check_module(code)
local const_info = check_constant(code)
if func_info then if func_info then
block.class = "function" block.class = "function"
block.name = func_info.name block.name = func_info.name
block.param = func_info.param block.param = func_info.param
block.private = func_info.private block.private = func_info.private
elseif const_info then
block.class = "constant"
block.name = const_info.name
block.private = const_info.private
elseif module_name then elseif module_name then
block.class = "module" block.class = "module"
block.name = module_name block.name = module_name
@ -403,6 +440,15 @@ function parse_file (filepath, doc, handle, prev_line, prev_block, prev_modname)
doc.modules[modulename].tables[t.name] = t doc.modules[modulename].tables[t.name] = t
end end
end end
-- make constants table
doc.modules[modulename].constants = {}
for c in class_iterator(blocks, "constant")() do
if c and c.name then
table.insert(doc.modules[modulename].constants, c.name)
doc.modules[modulename].constants[c.name] = c
end
end
end end
if filepath then if filepath then