pull/335/merge
sammyette 2024-12-24 22:59:35 +00:00 committed by GitHub
commit b74db7b822
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 153 additions and 41 deletions

View File

@ -1,6 +1,6 @@
local fs = require 'fs' local fs = require 'fs'
local emmyPattern = '^%-%-%- (.+)' local emmyPattern = '^%-%-%- (.+)'
local modpattern = '^%-+ @module (%w+)' local modpattern = '^%-+ @module (.+)'
local pieces = {} local pieces = {}
local files = fs.readdir 'nature' local files = fs.readdir 'nature'
@ -19,6 +19,8 @@ for _, fname in ipairs(files) do
local docPiece = {} local docPiece = {}
local lines = {} local lines = {}
local lineno = 0 local lineno = 0
local tocPos
local tocSearch = false
for line in f:lines() do for line in f:lines() do
lineno = lineno + 1 lineno = lineno + 1
lines[lineno] = line lines[lineno] = line
@ -81,29 +83,68 @@ description: %s
layout: doc layout: doc
menu: menu:
docs: docs:
parent: "Nature" parent: "%s"
--- ---
]] ]]
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('docs/%s/%s.md', mod, iface) local docParent = 'Nature'
path = string.format('docs/%s/%s.md', mod, iface)
if mod ~= 'nature' then
docParent = "API"
path = string.format('docs/api/%s/%s.md', mod, iface)
end
fs.mkdir(fs.dir(path), true) fs.mkdir(fs.dir(path), true)
local f <close> = io.open(path, 'w')
f:write(string.format(header, 'Module', iface, 'No description.')) local exists = pcall(fs.stat, path)
local newOrNotNature = exists and mod ~= 'nature'
local f <close> = io.open(path, newOrNotNature and 'r+' or 'w+')
if not newOrNotNature then
f:write(string.format(header, 'Module', iface, 'No description.', docParent))
end
print(f) print(f)
print(mod, path) print('mod and path:', mod, path)
local tocSearch = false
local tocPos
for line in f:lines() do
if line:match '^## Functions' then
tocSearch = true
end
if tocSearch and line == '' then
tocSearch = false
tocPos = f:seek() - 1
end
end
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) local sig = string.format('%s.%s(', iface, func)
local params = ''
for idx, param in ipairs(docs.params) do for idx, param in ipairs(docs.params) do
sig = sig .. ((param.name:gsub('%?$', ''))) sig = sig .. param.name:gsub('%?$', '')
if idx ~= #docs.params then sig = sig .. ', ' end params = params .. param.name:gsub('%?$', '')
if idx ~= #docs.params then
sig = sig .. ', '
params = params .. ', '
end
end end
sig = sig .. ')' sig = sig .. ')'
if tocPos then
local pos = f:seek()
f:seek('set', tocPos)
f:write(string.format('|<a href="#%s">%s</a>|%s|\n', func, string.format('%s(%s)', func, params), docs.description[1]))
tocPos = f:seek()
f:seek('set', pos)
end
f:write(string.format('<hr>\n<div id=\'%s\'>\n', func))
f:write(string.format([[ f:write(string.format([[
<h4 class='heading'> <h4 class='heading'>
%s %s

View File

@ -57,31 +57,13 @@ end)
|<a href="#runner.setMode">setMode(cb)</a>|This is the same as the `hilbish.runnerMode` function.| |<a href="#runner.setMode">setMode(cb)</a>|This is the same as the `hilbish.runnerMode` function.|
|<a href="#runner.lua">lua(cmd)</a>|Evaluates `cmd` as Lua input. This is the same as using `dofile`| |<a href="#runner.lua">lua(cmd)</a>|Evaluates `cmd` as Lua input. This is the same as using `dofile`|
|<a href="#runner.sh">sh(cmd)</a>|Runs a command in Hilbish's shell script interpreter.| |<a href="#runner.sh">sh(cmd)</a>|Runs a command in Hilbish's shell script interpreter.|
|<a href="#getCurrent">getCurrent()</a>|Returns the current runner by name.|
<hr> |<a href="#setCurrent">setCurrent(name)</a>|Sets the current interactive/command line runner mode.|
<div id='runner.setMode'> |<a href="#add">add(name, runner)</a>|Adds a runner to the table of available runners. If runner is a table,|
<h4 class='heading'> |<a href="#get">get(name)</a>|Get a runner by name.|
hilbish.runner.setMode(cb) |<a href="#set">set(name, runner)</a>|Sets a runner by name. The runner table must have the run function in it.|
<a href="#runner.setMode" class='heading-link'> |<a href="#exec">exec(cmd, runnerName)</a>|Executes cmd with a runner. If runnerName isn't passed, it uses|
<i class="fas fa-paperclip"></i> d)
</a>
</h4>
This is the same as the `hilbish.runnerMode` function.
It takes a callback, which will be used to execute all interactive input.
In normal cases, neither callbacks should be overrided by the user,
as the higher level functions listed below this will handle it.
#### Parameters
`function` **`cb`**
</div>
<hr>
<div id='runner.lua'>
<h4 class='heading'>
hilbish.runner.lua(cmd)
<a href="#runner.lua" class='heading-link'> <a href="#runner.lua" class='heading-link'>
<i class="fas fa-paperclip"></i> <i class="fas fa-paperclip"></i>
</a> </a>
@ -114,3 +96,92 @@ This is the equivalent of using `source`.
</div> </div>
<hr>
<div id='getCurrent'>
<h4 class='heading'>
hilbish.runner.getCurrent()
<a href="#getCurrent" class='heading-link'>
<i class="fas fa-paperclip"></i>
</a>
</h4>
Returns the current runner by name.
#### Parameters
This function has no parameters.
</div>
<hr>
<div id='setCurrent'>
<h4 class='heading'>
hilbish.runner.setCurrent(name)
<a href="#setCurrent" class='heading-link'>
<i class="fas fa-paperclip"></i>
</a>
</h4>
Sets the current interactive/command line runner mode.
#### Parameters
`name` **`string`**
</div>
<hr>
<div id='add'>
<h4 class='heading'>
hilbish.runner.add(name, runner)
<a href="#add" class='heading-link'>
<i class="fas fa-paperclip"></i>
</a>
</h4>
Adds a runner to the table of available runners. If runner is a table,
it must have the run function in it.
#### Parameters
`name` **`string`**
`runner` **`function`**
</div>
<hr>
<div id='get'>
<h4 class='heading'>
hilbish.runner.get(name)
<a href="#get" class='heading-link'>
<i class="fas fa-paperclip"></i>
</a>
</h4>
Get a runner by name.
#### Parameters
`name` **`string`**
</div>
<hr>
<div id='set'>
<h4 class='heading'>
hilbish.runner.set(name, runner)
<a href="#set" class='heading-link'>
<i class="fas fa-paperclip"></i>
</a>
</h4>
Sets a runner by name. The runner table must have the run function in it.
#### Parameters
`name` **`string`**
`runner` **`table`**
</div>
<hr>
<div id='exec'>
<h4 class='heading'>
hilbish.runner.exec(cmd, runnerName)
<a href="#exec" class='heading-link'>
<i class="fas fa-paperclip"></i>
</a>
</h4>
Executes cmd with a runner. If runnerName isn't passed, it uses
the user's current runner.
#### Parameters
`cmd` **`string`**
`runnerName` **`string?`**
</div>

View File

@ -1,4 +1,4 @@
--- hilbish.runner -- @module hilbish.runner
local currentRunner = 'hybrid' local currentRunner = 'hybrid'
local runners = {} local runners = {}