Hide empty rows (r8, r7, r6, r5)
Strip empty rows from HTML output tables. Max width 10 columns. |hide-empty-rows| must be present in corresponding rst file. This is a post-build clean-up step for tables with conditional content that renders as empty rows. Add missing bash dep. Signed-off-by: Ron Stone <ronald.stone@windriver.com> Change-Id: Ia65cc0a945d0ed8955c2a5d9bb68649d2280d27d
This commit is contained in:
parent
45e6579736
commit
8529479e6f
|
@ -0,0 +1,55 @@
|
|||
|
||||
declare RED='\033[0;31m'
|
||||
declare GR='\033[0;32m'
|
||||
declare NC='\033[0m'
|
||||
|
||||
# Output functions. Colorize various types of messages.
|
||||
message () { echo -e "$@" 1>&2; }
|
||||
confirmation () { message $GR$@$NC; }
|
||||
warn () { message $RED$@$NC; }
|
||||
error () { message $RED$@$NC; exit 1; }
|
||||
|
||||
# Check for and exit if file dependancies are not met. Takes a list of full or
|
||||
# relative paths.
|
||||
check_file_deps () {
|
||||
for filereq in $@
|
||||
do
|
||||
if [ ! -f "${filereq}" ] && [ ! -L "${filereq}" ]; then error "${filereq} not found. Quiting."; exit 1; fi
|
||||
done
|
||||
}
|
||||
|
||||
# Check for and exit if command dependancies are not met. Takes a list of
|
||||
# executables.
|
||||
check_util_deps () {
|
||||
for dep in $@
|
||||
do
|
||||
if ! hash $dep 2>/dev/null; then
|
||||
error >&2 "... $dep dependency not met. Please install."
|
||||
exit 1
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
# Creates an rST title over/underscore string of the same length
|
||||
# as the argument. Section strings are not supported. Returned output
|
||||
# is a sequence of equal signs (=).
|
||||
make_strike () {
|
||||
local _title="$1"
|
||||
local _strike
|
||||
_strike=$(for ((i=1; i<=${#_title}; i++)); do
|
||||
printf '=%.0s' "$i"
|
||||
done)
|
||||
echo $_strike
|
||||
}
|
||||
|
||||
# Trim leading and trailing whitespaces from string.
|
||||
trimspaces () {
|
||||
local _s=$1
|
||||
|
||||
_s="${_s#"${_s%%[![:space:]]*}"}"
|
||||
_s="${_s#"${_s%%[![:space:]]*}"}"
|
||||
|
||||
echo $_s
|
||||
}
|
||||
|
||||
declare utils_loaded=1
|
|
@ -50,3 +50,10 @@
|
|||
|
|
||||
|
||||
.. |optional| replace:: **Optional step:**
|
||||
|
||||
.. Flag to mark an output html file for post-build step to hide empty rows
|
||||
in tables. This is mostly useful where some rows are conditionalized.
|
||||
|
||||
.. |hide-empty-rows| raw:: html
|
||||
|
||||
<!-- post-build-hide-empty-table-rows -->
|
|
@ -0,0 +1,40 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
# strip empty rows from HTML output tables. Max width 10 columns.
|
||||
# |hide-empty-rows| must be present in corresponding rst file.
|
||||
|
||||
. $(pwd)/_utils.sh
|
||||
if [[ -z ${utils_loaded+x} ]]; then echo "Could not load utilities"; exit 1; fi
|
||||
|
||||
if [ "$#" -ne 1 ]; then
|
||||
error "Usage: $0 <htmlPath>"
|
||||
elif [[ ! -e "$1" ]]; then
|
||||
error "$0: Directory \"$1\" not found"
|
||||
fi
|
||||
|
||||
declare htmlPath=$1
|
||||
declare flag="post-build-hide-empty-table-rows"
|
||||
declare td="\n*<td>[\n\s]*</td>\n*"
|
||||
declare td_p=${td}
|
||||
|
||||
message "Cleaning up empty table rows in flagged files"
|
||||
|
||||
declare flagged_files=( $(grep -rl --include="*.html" "${flag}" ${htmlPath}) )
|
||||
|
||||
for _html in ${flagged_files[@]}; do
|
||||
|
||||
confirmation "... $_html"
|
||||
|
||||
sed -i -E -e ':a;N;$!ba;s/\n(<\/tr>)/\1/g' ${_html}
|
||||
sed -i -E -e ':a;N;$!ba;s/\n(<td><\/td>+)(<\/tr>)/\1\2/g' ${_html}
|
||||
|
||||
# sed has no non-greedy mode
|
||||
for i in {1..10}; do
|
||||
sed -i -E "s:^<tr class=(\"row-odd\"|\"row-even\")>${td_p}</tr>::g" ${_html}
|
||||
td_p="$td_p$td"
|
||||
done
|
||||
|
||||
# sed -i -E "s:^<tr class=\"row-odd\">(<td></td>+)(</tr>):<tr hidden>\1\2:g" ${_html}
|
||||
done
|
||||
|
||||
confirmation "... Done"
|
3
tox.ini
3
tox.ini
|
@ -30,6 +30,7 @@ commands =
|
|||
git clean -dfx doc/source/fault-mgmt/
|
||||
git restore doc/source/dist_cloud/kubernetes/*
|
||||
# bash hw-updates.sh
|
||||
bash hide-empty-rows.sh doc/build/html
|
||||
bash htmlChecks.sh doc/build/html
|
||||
|
||||
[testenv:docs]
|
||||
|
@ -42,6 +43,7 @@ commands =
|
|||
{[testenv:postbuild-docs]commands}
|
||||
# Note: The dev env for the docs team uses a version of tox that does not yet support allowlist_externals
|
||||
whitelist_externals = bash
|
||||
hide-empty-rows.sh
|
||||
htmlChecks.sh
|
||||
get-remote-files.sh
|
||||
git
|
||||
|
@ -56,6 +58,7 @@ commands =
|
|||
sphinx-build -a -E -W --keep-going -d doc/build/doctrees -t starlingx -t openstack -b singlehtml doc/source doc/build/singlepage {posargs}
|
||||
{[testenv:postbuild-docs]commands}
|
||||
whitelist_externals = bash
|
||||
hide-empty-rows.sh
|
||||
htmlChecks.sh
|
||||
get-remote-files.sh
|
||||
git
|
||||
|
|
Loading…
Reference in New Issue