#!/bin/bash
# dev/docs/index - package source reference index support

set -e

lib_load 'dev/docs/color'


######
# Source File Index

# docs_gen_html_index() - Generates documentation index file
docs_gen_html_index(){
	run_mkdir "$package_docs_refdir"

	local tmp=$(cmd_tempfile)
	docs_gen_index_html > "$tmp"

	local index="$package_docs_refdir/index.html"
	run mv "$tmp" "$index"
}

docs_gen_index_html() {
	html_doc docs_gen_index_head docs_gen_index_body
}

docs_gen_index_head() {
	html_stylesheet "$(docs_css_filename)"
}

docs_gen_index_body() {
	docs_gen_index_header
	for_each docs_gen_index_section src libs conf
	docs_gen_index_footer
}

docs_gen_index_header() {
	html_anchor_func "top" \
		html_h1 "$(html_code "$PKG") Programming Reference"

	html_p "The source files have been sorted into three sections:"
	html_ul	\
		"$(html_li_func html_url '#src' "Tool Scripts")" \
		"$(html_li_func html_url '#libs' "Library Scripts")" \
		"$(html_li_func html_url '#conf' "Configuration Files")"

	local allurl=$(html_url 'all.deps.svg' 'View the dependency graph')
	html_div "$allurl for all Tool and Library Scripts."

	html_h2 "Script File Reference"

	html_p "For each file, links are provided to the following pages:"
	html_ul \
		$(html_li "Extracted Reference Documentation" \
		$(html_ul \
			$(html_li "reStructuredText ($(html_code rst))") \
			$(html_li "Stylized Source Code ($(html_code raw))"))) \
		$(html_li "Dependency Graphs ($(html_code dot svg pdf))")
}

docs_gen_index_footer() {
	docs_gen_footer
}


######
# File Sections

docs_gen_index_section() {
	local dir=$1

	local -a files=()
	docs_file_list files "$dir"

	docs_gen_index_section_header "$dir"
	for_each docs_gen_index_group "${GROUP_ORDER[@]}"
}

docs_gen_index_section_header() {
	local dir=$1

	local section url rturl
	case "$dir" in
	(conf)
		section="Configuration Files"
		;;
	(src)
		section="Tool Scripts"
		url="tools.deps.svg"
		;;
	(libs)
		section="Library Scripts"
		url="libraries.deps.svg"
		rturl="runtime.deps.svg"
		;;
	esac

	html_h2_func doc_gen_index_section_title

	[ "$url" ] || return 0
	local hurl=$(html_url "$url" "dependency graph")
	html_div "View the $hurl for all $section."

	[ "$rturl" ] || return 0
	local rthurl=$(html_url "$rturl" "dependency graph")
	html_div "View the $rthurl for the core Runtime Libraries."
}

doc_gen_index_section_title() {
	html_anchor "$dir" "$section"
	echo -n ' ('
	html_code_func html_url "#top" "top"
	echo -n ')'
}


######
# Script Groups

docs_gen_index_group() {
	local group_name=$1
	local tmp
	tmp=$(cmd_tempfile)
	docs_gen_index_group_files >"$tmp"
	if [ -s "$tmp" ]; then
		local name=$(html_code "$group_name")
		local desc=${GROUP_NAMES[$group_name]}
		html_h3 "$desc ($name)"
		html_ul_file "$tmp"
	fi
}
docs_gen_index_group_files() {
	for_each docs_gen_index_group_file "${files[@]}"
}
docs_gen_index_group_file() {
	local file=$1
	local name=${file#*/}
	str_startswith "$name" "$group_name/" || return 0
	docs_gen_index_file "$file"
}


######
# File Entries

docs_gen_index_file() {
	html_li_func docs_gen_index_entry "$1"
}

docs_gen_index_entry() {
	local file=$1

	local base=${file%.in}
	local name=${base#*/}
	name=${name#$group_name/}

	html_code_func html_url "$base.html" "$name"
	echo -n ' ('
	html_code_func html_url "$base.rst" 'rst'
	echo -n ' '
	html_code_func html_url "$base.raw.html" 'raw'
	echo ')'
	if [ -s "$package_docs_refdir/$base.deps.dot" ]; then
		echo -n ' ('
		html_code_func html_url "$base.deps.dot" 'dot'
		echo -n ' '
		html_code_func html_url "$base.deps.svg" 'svg'
		echo -n ' '
		html_code_func html_url "$base.deps.pdf" 'pdf'
		echo ')'
	fi
}

######
# Symbol index

# TODO: implement symbol index, giving a <file:line> pair for each appearance
#	html_p "This page provide links to the programming interfaces and
#		commands provided by the <code>$PKG</code> package."

View the Script Reference Index


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