Skip to content

Commit

Permalink
doc: Add missing spaces at the beginning of documentation to ensure p…
Browse files Browse the repository at this point in the history
…roper processing by Sphinx
  • Loading branch information
gliga committed Jan 26, 2024
1 parent 17bf3e7 commit 89363e5
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 11 deletions.
24 changes: 13 additions & 11 deletions src/tools/bdoc.sh
Original file line number Diff line number Diff line change
Expand Up @@ -41,21 +41,23 @@ function _bdoc_file() {
local n=$(strings_len "${path}")
local assigns=$(strings_repeat "=" "${n}")

cat << END
${path}
${assigns}
${brief}
END
echo "${path}"
echo "${assigns}"
echo
echo "${brief}"
echo

local fun
for fun in $(sys_functions_in_file "${pathf}"); do
[[ "${fun}" = "_"* ]] && continue
echo ".. py:function:: ${fun}"
echo
sys_function_doc "${pathf}" "${fun}" || \

local tmpf=$(os_mktemp_file)
sys_function_doc "${pathf}" "${fun}" > "${tmpf}" || \
{ ctx_w $ctx "cannot get doc for ${fun}"; return $EC; }
file_prefix_each_line "${tmpf}" " "
$X_CAT "${tmpf}"
echo
done
}
Expand All @@ -76,10 +78,10 @@ function bdoc_main() {
local content=""
local f
# TODO: pick files from flags.
for f in $(find "$(sys_repo_path)/src" -name "*.sh" | grep -v '_test.sh'); do
for f in $(find "$(sys_repo_path)/src" -name "*.sh" | $X_GREP -v '_test.sh'); do
local package_file=${f#"$(sys_repo_path)/src/"*}
local package="${package_file%/*}"
local file=$(echo "${package_file}" | awk -F"/" '{print $NF}')
local file=$(echo "${package_file}" | $X_AWK -F"/" '{print $NF}')
[ "${file}" = "p.sh" ] && continue

local name=$(basename "${file}" .sh)
Expand All @@ -90,7 +92,7 @@ function bdoc_main() {
done

# Make api.rst file.
cat << END > "${docd}/api.rst"
$X_CAT << END > "${docd}/api.rst"
API
===
Expand Down
20 changes: 20 additions & 0 deletions src/util/file.sh
Original file line number Diff line number Diff line change
Expand Up @@ -172,3 +172,23 @@ function file_squeeze_blank_lines() {
cat -s "${path}" > "${tmpf}"
mv "${tmpf}" "${path}"
}

function file_prefix_each_line() {
# Prefix each line in a file with a string.
local ctx; is_ctx "${1}" && ctx="${1}" && shift
[ $# -ne 2 ] && { ctx_wn $ctx; return $EC; }
local -r path="${1}"
local -r str="${2}"
shift 2 || { ctx_wn $ctx; return $EC; }

[ -z "${path}" ] && { ctx_wa $ctx "path"; return $EC; }
[ ! -f "${path}" ] && { ctx_wa $ctx "path"; return $EC; }
[ -z "${str}" ] && { ctx_wa $ctx "str"; return $EC; }

local -r os=$(os_name)
if [ "${os}" = "${OS_MAC}" ]; then
$X_SED -i '' 's/^/'"${str}"'/' "${path}" || return $EC
else
$X_SED -i 's/^/'"${str}"'/' "${path}" || return $EC
fi
}
17 changes: 17 additions & 0 deletions src/util/file_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -179,3 +179,20 @@ END
assert_fail
}
readonly -f test_file_squeeze_blank_lines

function test_file_prefix_each_line() {
local tmpf=$(os_mktemp_file)

cat << END > "${tmpf}"
one
two
three
END
file_prefix_each_line "${tmpf}" "abc"

local n=$(grep '^abc' "${tmpf}" | wc -l)
[ "${n}" -ne 4 ] && return $EC
return 0
}
readonly -f test_file_prefix_each_line

0 comments on commit 89363e5

Please sign in to comment.