feat: add nature module docs

pull/260/head
sammyette 2023-12-25 18:50:27 -04:00
parent f312cc2cac
commit b0e05d4b16
Signed by: sammyette
GPG Key ID: 904FC49417B44DCD
5 changed files with 167 additions and 14 deletions

View File

@ -17,17 +17,53 @@ for _, fname in ipairs(files) do
pieces[mod] = {} pieces[mod] = {}
local docPiece = {} local docPiece = {}
local lines = {}
local lineno = 0
for line in f:lines() do for line in f:lines() do
lineno = lineno + 1
lines[lineno] = line
if line == header then goto continue2 end if line == header then goto continue2 end
if not line:match(emmyPattern) then if not line:match(emmyPattern) then
if line:match '^function' then if line:match '^function' then
local pattern = (string.format('^function %s%%.', mod) .. '(%w+)') local pattern = (string.format('^function %s%%.', mod) .. '(%w+)')
local funcName = line:match(pattern) local funcName = line:match(pattern)
if not funcName then goto continue2 end if not funcName then goto continue2 end
print(line)
print(pattern) local dps = {
print(funcName) description = {},
pieces[iface][funcName] = docPiece params = {}
}
local offset = 1
while true do
local prev = lines[lineno - offset]
local docline = prev:match '^%-+ (.+)'
if docline then
local emmy = docline:match '@(%w+)'
local cut = 0
if emmy then cut = emmy:len() + 3 end
local emmythings = string.split(docline:sub(cut), ' ')
if emmy then
if emmy == 'param' then
table.insert(dps.params, 1, {
name = emmythings[1],
type = emmythings[2]
})
end
else
table.insert(dps.description, 1, docline)
end
offset = offset + 1
else
break
end
end
pieces[mod][funcName] = dps
end end
docPiece = {} docPiece = {}
goto continue2 goto continue2
@ -39,20 +75,57 @@ for _, fname in ipairs(files) do
::continue:: ::continue::
end end
local header = [[---
title: %s %s
description: %s
layout: doc
menu:
docs:
parent: "Nature"
---
]]
for iface, dps in pairs(pieces) do for iface, dps in pairs(pieces) do
local mod = iface:match '(%w+)%.' or 'nature' local mod = iface:match '(%w+)%.' or 'nature'
local path = string.format('luadocs/api/%s/%s.md', mod, iface) local path = string.format('docs/%s/%s.md', mod, iface)
local f <close> = io.open(path, 'a+') fs.mkdir(fs.dir(path), true)
local f <close> = io.open(path, 'w')
f:write(string.format(header, 'Module', iface, 'No description.'))
print(f) print(f)
print(mod, path) print(mod, path)
fs.mkdir(fs.dir(path), true)
for func, docs in pairs(dps) do for func, docs in pairs(dps) do
f:write(string.format('<hr>\n<div id=\'%s\'>', func))
local sig = string.format('%s.%s(', iface, func)
for idx, param in ipairs(docs.params) do
sig = sig .. ((param.name:gsub('%?$', '')))
if idx ~= #docs.params then sig = sig .. ', ' end
end
sig = sig .. ')'
f:write(string.format([[
<h4 class='heading'>
%s
<a href="#%s" class='heading-link'>
<i class="fas fa-paperclip"></i>
</a>
</h4>
]], sig, func))
f:write(table.concat(docs.description, '\n') .. '\n')
f:write '#### Parameters\n'
if #docs.params == 0 then
f:write 'This function has no parameters. \n'
end
for _, param in ipairs(docs.params) do
f:write(string.format('`%s` **`%s`**\n', param.name:gsub('%?$', ''), param.type))
end
--[[
local params = table.filter(docs, function(t) local params = table.filter(docs, function(t)
return t:match '^%-%-%- @param' return t:match '^%-%-%- @param'
end) end)
f:write(string.format('## %s(', func))
for i, str in ipairs(params) do for i, str in ipairs(params) do
if i ~= 1 then if i ~= 1 then
f:write ', ' f:write ', '
@ -66,7 +139,8 @@ for iface, dps in pairs(pieces) do
f:write(str:match '^%-%-%- (.+)' .. '\n') f:write(str:match '^%-%-%- (.+)' .. '\n')
end end
end end
f:write('\n') ]]--
f:write('</div>')
f:write('\n\n')
end end
f:flush()
end end

View File

@ -0,0 +1,79 @@
---
title: Module dirs
description: No description.
layout: doc
menu:
docs:
parent: "Nature"
---
<hr>
<div id='setOld'>
<h4 class='heading'>
dirs.setOld(d)
<a href="#setOld" class='heading-link'>
<i class="fas fa-paperclip"></i>
</a>
</h4>
Sets the old directory string.
#### Parameters
`d` **`string`**
</div>
<hr>
<div id='push'>
<h4 class='heading'>
dirs.push()
<a href="#push" class='heading-link'>
<i class="fas fa-paperclip"></i>
</a>
</h4>
Add `d` to the recent directories list.
#### Parameters
This function has no parameters.
</div>
<hr>
<div id='peak'>
<h4 class='heading'>
dirs.peak(num)
<a href="#peak" class='heading-link'>
<i class="fas fa-paperclip"></i>
</a>
</h4>
Look at `num` amount of recent directories, starting from the latest.
#### Parameters
`num` **`number`**
</div>
<hr>
<div id='pop'>
<h4 class='heading'>
dirs.pop(num)
<a href="#pop" class='heading-link'>
<i class="fas fa-paperclip"></i>
</a>
</h4>
Remove the specified amount of dirs from the recent directories list.
#### Parameters
`num` **`number`**
</div>
<hr>
<div id='recent'>
<h4 class='heading'>
dirs.recent(idx)
<a href="#recent" class='heading-link'>
<i class="fas fa-paperclip"></i>
</a>
</h4>
Get entry from recent directories list based on index.
#### Parameters
`idx` **`number`**
</div>

View File

@ -40,7 +40,7 @@ function dirs.peak(num)
return dirRecents(num) return dirRecents(num)
end end
--- Add `d` to the recent directories. --- Add `d` to the recent directories list.
function dirs.push(d) function dirs.push(d)
dirs.recentDirs[dirs.recentSize + 1] = nil dirs.recentDirs[dirs.recentSize + 1] = nil
if dirs.recentDirs[#dirs.recentDirs - 1] ~= d then if dirs.recentDirs[#dirs.recentDirs - 1] ~= d then
@ -51,19 +51,19 @@ function dirs.push(d)
end end
end end
--- Remove `num` amount of dirs from the recent directories. --- Remove the specified amount of dirs from the recent directories list.
-- @param num number -- @param num number
function dirs.pop(num) function dirs.pop(num)
return dirRecents(num, true) return dirRecents(num, true)
end end
--- Get entry from recent directories. --- Get entry from recent directories list based on index.
-- @param idx number -- @param idx number
function dirs.recent(idx) function dirs.recent(idx)
return dirs.recentDirs[idx] return dirs.recentDirs[idx]
end end
--- Sets the old directory. --- Sets the old directory string.
-- @param d string -- @param d string
function dirs.setOld(d) function dirs.setOld(d)
ok, d = pcall(fs.abs, d) ok, d = pcall(fs.abs, d)