#!/bin/bash
# dev/docs/guide - package user guide support
set -e
lib_load 'dev/docs/rst'
lib_load 'net/tool/rsync'
######
# Package Guide Generation
package_docs_guide_clean() { run rm -rf "$package_docs_guidedir"; }
docs_gen_guide_list() {
local var=$1
local -a file_find_opts=( -type f )
run_pushd "$package_repodir"
file_find $1 "${DIST_docs[@]}"
run_popd
}
docs_gen_guide() {
local -a files=( "$@" )
[ "$*" ] || docs_gen_guide_list files
run_mkdir "$package_docs_guidedir"
local f
for f in "${files[@]}"; do
local src="$package_docs_srcdir/$f.rst" \
local dst="$package_docs_guidedir/$f.rst"
rsync_run -a "$src" "$dst"
done
}
docs_gen_html_guide() {
local -a package_guide_file_kinds=( rst )
for_each docs_gen_html_guide_kind "${package_guide_file_kinds[@]}"
}
docs_gen_html_guide_kind() {
local kind=$1
local func
case "$kind" in
rst) func=docs_gen_html_guide_rst ;;
*) error "$kind: unknown documentation file type" ;;
esac
local -a file_find_opts=( -type f -name "*.$kind" )
file_find files "$package_docs_guidedir"
for_each $func "${files[@]}"
}
docs_gen_html_guide_rst() {
local src=$1
local dst="${src%.rst}.html"
local name=${dst#$package_docs_guidedir}
info "$name: generating page..."
file_mkdir "$dst"
{
docs_rst_to_html "$src"
docs_gen_html_page_footer
} >"$dst"
}
######
# Package Guide Index
docs_gen_html_guide_index() {
run_mkdir "$package_docs_guidedir"
local tmp=$(cmd_tempfile)
docs_gen_guide_index_html > "$tmp"
local index="$package_docs_guidedir/contents.html"
run mv "$tmp" "$index"
}
docs_gen_guide_index_html() {
html_doc docs_gen_guide_index_head docs_gen_guide_index_body
}
docs_gen_guide_index_head() {
html_stylesheet "$(docs_css_filename)"
}
docs_gen_guide_index_body() {
html_anchor_func "top" \
html_h1 "<code>$PKG</code> User Guide"
html_p "The user guide contains the following files:"
local -a file_find_opts=( -name '*.html' )
local -a files
file_find files "$package_docs_guidedir"
for_each docs_gen_guide_index_file "${files[@]}"
docs_gen_footer
}
docs_gen_guide_index_file() {
# [ "${1#$package_docs_guidedir/}" != "index.html" ] || return 0
html_li_func docs_gen_guide_index_entry "$1"
}
docs_gen_guide_index_entry() {
local file=$1
local base=${file%.html}
local label=${base#$package_docs_guidedir/}
html_code_func docs_html_url "$file" "$label"
if [ -f "$base.rst" ]; then
echo -n ' ('
html_code_func docs_html_url "$base.rst" 'rst'
echo ')'
fi
}
Generated on Wed Jun 28 07:39:48 PDT 2017 by mcsh d14 v0.20.0.