1
0
mirror of https://github.com/lxsang/antd-web-apps synced 2024-11-20 10:18:21 +01:00
antd-web-apps/doc/views/default/toc/index.ls

44 lines
1.2 KiB
Plaintext
Raw Normal View History

2020-06-22 22:14:52 +02:00
<?lua
2020-06-24 19:00:41 +02:00
local gentree
gentree = function(data, controller, cpath)
2020-06-22 22:14:52 +02:00
if not data then
return ""
end
local caret = ''
if data.entries then
caret = '<span class = "caret"></span>'
end
2020-06-24 19:00:41 +02:00
local active = ""
local selected = ""
local highlight = ""
if data.tpath and cpath then
if cpath:match("^"..data.tpath) then
active = "active"
highlight = "class = 'highlight'"
end
if data.path == cpath then
selected = "class = 'selected'"
end
end
local markup = '<li '..selected..'>'..caret..'<a '..highlight..' href="'..HTTP_ROOT..'/'..controller..'/'..std.b64encode(data.path):gsub("=","")..'/'..data.name:gsub(" ", "_")..'.md">'..data.name.."</a>"
2020-06-22 22:14:52 +02:00
if data.entries then
2020-06-24 19:00:41 +02:00
markup = markup.."<ul class='nested "..active.."'>"
2020-06-22 22:14:52 +02:00
for k,v in pairs(data.entries) do
2020-06-24 19:00:41 +02:00
markup = markup..gentree(v, controller, cpath)
2020-06-22 22:14:52 +02:00
end
markup = markup.."</ul>"
end
markup = markup.."</li>"
return markup
end
?>
<ul id = "toc">
<?lua
if data.error then
2020-06-24 19:00:41 +02:00
return echo("<li>Unable to read TOC</li>")
2020-06-22 22:14:52 +02:00
end
for k,v in pairs(data.data.entries) do
2020-06-24 19:00:41 +02:00
echo(gentree(v, data.controller, data.cpath))
2020-06-22 22:14:52 +02:00
end
?>
</ul>