#!/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

	package_docs_guide_clean
	run_mkdir "$package_docs_guidedir"
	run_rsync -a "$package_docs_srcdir/" "$package_docs_guidedir"
}

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_guide_footer
	} >"$dst"
}

docs_gen_html_guide_footer() {
	local path=$(docs_filename "$package_docs_guidedir" index html)
	docs_gen_html_page_footer "$path" "User Guide"
}


######
# 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/index.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
}

View the Script Reference Index


Generated on Tue Apr 25 21:20:24 PDT 2017 by mcsh i7 v0.18.0.