Add non-working love2d documentation tooling and integrate with get-docs.fnl

This commit is contained in:
Emma 2024-08-04 09:10:07 -04:00
parent 41a92088f8
commit 2bddb4be3a
2 changed files with 49 additions and 17 deletions

View File

@ -1,33 +1,43 @@
"Script to generate /src/fennel-ls/docs/lua54.fnl and friends automatically"
(local {: sh} (require :tools.util.sh))
(fn curl-cached [url]
(let [filename (.. "build/" (url:gsub "[/:]" "_"))
(let [filename (.. :build/ (url:gsub "[/:]" "_"))
file (io.open filename :r)]
(if file
file
(do
(sh "curl" url [">"] filename)
(sh :curl url [">"] filename)
(io.open filename :r)))))
(fn write-doc-file! [out-filename doc-src doc-tbl]
(with-open [file (io.open (.. :src/fennel-ls/docs/generated/ out-filename) :w)]
(file:write ";; auto-generated by `make docs` from fennel-ls. Contents come from "
doc-src "\n" doc-tbl "\n")))
(fn derive-docs-from-url [url out-filename convert]
(let [result
(convert
(with-open [file (curl-cached url)]
(file:read "*a")))]
(with-open [file (io.open (.. "src/fennel-ls/docs/generated/" out-filename) :w)]
(file:write ";; auto-generated by `make docs` from fennel-ls. Contents come from " url "\n"
result "\n"))))
(write-doc-file! out-filename url
(convert (with-open [file (curl-cached url)]
(file:read :*a)))))
(fn main []
(sh :mkdir :-p "build/")
(sh :mkdir :-p "src/fennel-ls/docs/generated/")
(sh :mkdir :-p :build/)
(sh :mkdir :-p :src/fennel-ls/docs/generated/)
(let [{:convert lua-manual} (require :tools.get-docs.lua-manual)
{:convert tic-manual} (require :tools.get-docs.tic80)]
(derive-docs-from-url "https://www.lua.org/manual/5.1/manual.html" "lua51.fnl" lua-manual)
(derive-docs-from-url "https://www.lua.org/manual/5.2/manual.html" "lua52.fnl" lua-manual)
(derive-docs-from-url "https://www.lua.org/manual/5.3/manual.html" "lua53.fnl" lua-manual)
(derive-docs-from-url "https://www.lua.org/manual/5.4/manual.html" "lua54.fnl" lua-manual)
(derive-docs-from-url "https://tic80.com/learn" "tic80.fnl" tic-manual)))
{:convert tic80-manual} (require :tools.get-docs.tic80)
{:convert download-and-convert-love2d-manual!} (require :tools.get-docs.love2d)]
(derive-docs-from-url "https://www.lua.org/manual/5.1/manual.html"
:lua51.fnl lua-manual)
(derive-docs-from-url "https://www.lua.org/manual/5.2/manual.html"
:lua52.fnl lua-manual)
(derive-docs-from-url "https://www.lua.org/manual/5.3/manual.html"
:lua53.fnl lua-manual)
(derive-docs-from-url "https://www.lua.org/manual/5.4/manual.html"
:lua54.fnl lua-manual)
(derive-docs-from-url "https://tic80.com/learn" :tic80.fnl tic80-manual)
(write-doc-file! :love2d.fnl
"https://github.com/love2d-community/love-api/"
(download-and-convert-love2d-manual!))))
(main)

22
tools/get-docs/love2d.fnl Normal file
View File

@ -0,0 +1,22 @@
(local fennel (require :deps.fennel))
(local {:clone git-clone} (require :tools.util.git))
(fn download-love-api-tooling! []
"Clones the LÖVE-API git repository that contains tooling to scrape and
convert the LÖVE Wiki into a Lua table."
(when (not (io.open :build/love-api))
(git-clone :build/love-api "https://github.com/love2d-community/love-api")))
; EXAMPLE SHAPE
;
; {:love {:binding :love
; :fields {:callbacks {:binding :love.callbacks
; :fields {:mousepressed {:binding :mousepressed
; :metadata {:fnl/arglist [""]
; :fnl/docstring "..."}}}}}}}
(fn convert [_contents]
(download-love-api-tooling!)
(fennel.view {:love "I did it\\!"}))
{: convert}