apm_serve_docs

one of the documented procedures in this installation of the ACS
Usage:
apm_serve_docs   conn   dir
What it does:
Serves a documentation file, or index pages.
Defined in: /web/philip/packages/acs-core/apm-admin-procs.tcl

Source code:


    set url [ns_conn url]

    if { [string compare [string range $url 0 [expr { [string length $dir] - 1 }]] $dir] } {
	# The URL doesn't seem to begin with the directory we expect! Wacky.
	ns_returnnotfound
	return
    }   

    # Clip the registered path off the URL.
    set url [string range $url [string length $dir] [string length $url]]
    if { [empty_string_p $url] } {
	# Requested something like "/apm/doc" - no trailing slash. Append one and redirect.
	ad_returnredirect "[ns_conn url]/"
	return
    }

    if { ![string compare $url "/"] } {
	# Requested something like "/apm/doc/" - serve up the index page.

	ReturnHeaders

	ns_write "[ad_header "Package Documentation"]
<h3>Package Documentation</h3>

[ad_context_bar_ws "Package Documentation"]
<hr>
<ul>
"
        set out ""

	db_foreach "select * from apm_enabled_package_versions" {
	    set doc_files [apm_version_file_list -type "documentation" $version_id]
	    if { [llength $doc_files] == 0 } {
		append out "<li><b>$package_name $version_name</b> - $summary\n"
	    } elseif { [llength $doc_files] == 1 } {
		append out "<li><b><a href=\"$package_key/[file tail [lindex $doc_files 0]]\">$package_name $version_name</a></b> - $summary\n"
	    } else {
		append out "<li><b>$package_name $version_name</b> - $summary\n<ul>\n"
		foreach file $doc_files {
		    append out "<li><a href=\"$package_key/[file tail $file]\">[file tail $file]</a>\n"
		}
		append out "</ul>\n"
	    }
	}
	append out "</ul>\n[ad_footer]\n"
	ns_write $out
    } elseif { [regexp {^/([^/]+)/([^/]+)$} $url "" package_key tail] } {
	db_foreach "
            select path from apm_package_files
            where  version_id in (
                select version_id
                from   apm_packages p, apm_package_versions v
                where  p.package_id = v.package_id
                and    p.package_key = '[db_quote $package_key]'
                and    v.enabled_p = 't'
            )
            and file_type = 'documentation'
            and path like '%/[db_quote $tail]'
        " {
	    if { ![info exists real_path] && ![string compare [lindex [split $path "/"] end] $tail] } {
		set real_path "[acs_root_dir]/$path"
	    }
	}

	if { ![info exists real_path] } {
	    ns_returnnotfound
	    return
	}

	# Borrow from abstract-url-procs.tcl. Eventually the abstract URL stuff will push
	# this stuff out into its own procedure.
	set extension [file extension $real_path]
	if { $extension == ".tcl" } {
	    # Tcl file - use source.
	    
	    aurl_eval [list source $real_path]
	} elseif { $extension == ".adp" } {
	    if { ![aurl_eval [list ns_adp_parse -file $real_path] adp] } {
		return
	    }
	    set content_type [ns_set iget [ns_conn outputheaders] "content-type"]
	    if { $content_type == "" } {
		set content_type "text/html"
	    }
	    ns_return 200 $content_type $adp
	} else {
	    # Some other random kind of find - return it.
	    ns_returnfile 200 [ns_guesstype $real_path] $real_path
	}
    }


philg@mit.edu