diff --git a/.github/workflows/reference.yml b/.github/workflows/reference.yml index 383bc73..e411f1c 100644 --- a/.github/workflows/reference.yml +++ b/.github/workflows/reference.yml @@ -22,10 +22,8 @@ jobs: run: luarocks install --only-deps https://raw.githubusercontent.com/lunarmodules/LDoc/master/ldoc-scm-3.rockspec - name: Setup LDoc run: git clone --single-branch --branch=custom https://github.com/AntumDeluge/ldoc.git .ldoc/ldoc && chmod +x .ldoc/ldoc/ldoc.lua - - name: Generate temp files - run: chmod +x .ldoc/parse_*.py && ./.ldoc/parse_src.py && ./.ldoc/parse_settings.py && ./.ldoc/parse_crafts.py - name: Generate docs - run: ./.ldoc/ldoc/ldoc.lua --UNSAFE_NO_SANDBOX -c .ldoc/config.ld -d 3d_armor/docs/reference "$(pwd)" + run: chmod +x .ldoc/gendoc.sh && ./.ldoc/gendoc.sh - name: Deploy uses: peaceiris/actions-gh-pages@v3 with: diff --git a/.ldoc/config.ld b/.ldoc/config.ld index 615935f..f814f98 100644 --- a/.ldoc/config.ld +++ b/.ldoc/config.ld @@ -1,4 +1,5 @@ --- Place this file in mod "docs" directory + +-- place this file in mod ".ldoc" directory local print, type, string, table, tostring, tonumber, error, pairs, ipairs if import then @@ -29,7 +30,8 @@ file = { ".ldoc/chestplates.luadoc", ".ldoc/leggings.luadoc", ".ldoc/boots.luadoc", - ".ldoc/shields.luadoc", + --".ldoc/shields.luadoc", + "shields/init.lua", ".ldoc/crafting.luadoc", } @@ -75,18 +77,9 @@ custom_tags = { { -- specify image basename only "img", - title = "Image", + title = "Inventory Image", format = function(value) - local img = "" + return "" end, }, { @@ -223,6 +216,11 @@ local registered = { } local function setting_handler(item) + -- avoid parsing again + if registered.settings[item.name] then + return item + end + if not ipairs or not type then return item end @@ -275,15 +273,7 @@ end function custom_display_name_handler(item, default_handler) if item.type == "setting" then - -- avoid parsing again - if not registered.settings[item.name] then - item = setting_handler(item) - end - elseif item.type == "armor" and string then - -- HACK: not sure why "shields:" is being trimmed from item name - if string.find(item.name, "shield_") == 1 then - item.name = "shields:" .. item.name - end + item = setting_handler(item) end if item then diff --git a/.ldoc/gendoc.sh b/.ldoc/gendoc.sh new file mode 100755 index 0000000..df70dc8 --- /dev/null +++ b/.ldoc/gendoc.sh @@ -0,0 +1,88 @@ +#!/usr/bin/env bash + +# Place this file in mod ".ldoc" directory. +# +# To change output directory set the `d_export` environment variable. +# Example: +# $ d_export=/custom/path ./gendoc.sh + + +d_ldoc="$(dirname $(readlink -f $0))" +f_config="${d_ldoc}/config.ld" + +cd "${d_ldoc}/.." + +d_root="$(pwd)" +d_export="${d_export:-${d_root}/3d_armor/docs/reference}" +d_data="${d_export}/data" + +cmd_ldoc="${d_ldoc}/ldoc/ldoc.lua" +if test -f "${cmd_ldoc}"; then + if test ! -x "${cmd_ldoc}"; then + chmod +x "${cmd_ldoc}" + fi +else + cmd_ldoc="ldoc" +fi + + +# clean old files +rm -rf "${d_export}" + +# generate items, settings, & crafts topics temp files +echo -e "\ngenerating temp files ..." +for script in "src" "settings" "crafts"; do + script="${d_ldoc}/parse_${script}.py" + if test ! -f "${script}"; then + echo "ERROR: script doesn't exist: ${script}" + else + # check script's executable bit + if test ! -x "${script}"; then + chmod +x "${script}" + fi + # execute script + "${script}" + fi +done + +echo + +# generate new doc files +"${cmd_ldoc}" --UNSAFE_NO_SANDBOX -c "${f_config}" -d "${d_export}" "${d_root}"; retval=$? + +# check exit status +if test ${retval} -ne 0; then + echo -e "\nan error occurred (ldoc return code: ${retval})" + exit ${retval} +fi + +echo -e "\ncleaning temp files ..." +rm -vf "${d_ldoc}/"*.luadoc + +# HACK: ldoc does not seem to like the "shields:" prefix +echo -e "\ncompensating for LDoc's issue with \"shields:\" prefix ..." +sed -i \ + -e 's/shield_/shields:shield_/' \ + -e 's/shields:shield_/' \ + -e 's/