From 2bddb4be3ac08455ff7ba923755f4dc401204b28 Mon Sep 17 00:00:00 2001 From: Emma Date: Sun, 4 Aug 2024 09:10:07 -0400 Subject: [PATCH] Add non-working love2d documentation tooling and integrate with get-docs.fnl --- tools/get-docs.fnl | 44 ++++++++++++++++++++++++--------------- tools/get-docs/love2d.fnl | 22 ++++++++++++++++++++ 2 files changed, 49 insertions(+), 17 deletions(-) create mode 100644 tools/get-docs/love2d.fnl diff --git a/tools/get-docs.fnl b/tools/get-docs.fnl index e1cd8ad..b83d0ef 100644 --- a/tools/get-docs.fnl +++ b/tools/get-docs.fnl @@ -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) diff --git a/tools/get-docs/love2d.fnl b/tools/get-docs/love2d.fnl new file mode 100644 index 0000000..568cd03 --- /dev/null +++ b/tools/get-docs/love2d.fnl @@ -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}