ussg

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README

navbar.tm (3378B)


      1 # This is an UmbrellixSSG Plugin.
      2 # It is sourced into ::templcmds::.
      3 # It can use any header, although it cannot limit them
      4 # to being single-use as headers have already been parsed.
      5 # If that's needed, one will need to just pick off the last
      6 # option.
      7 # Some checking can be done.
      8 
      9 proc navbar {} {
     10 	# So, the user wants a side navbar, huh?
     11 	# We'll have to look in the Navbar-Source header.
     12 	set prefix ""
     13 	if {![catch {dict get $::headers navbar-prefix} navprefix]} {set prefix [file normalize $navprefix]}
     14 	# This is the prefix that is assumed to be on $::outputfile during generation. This is used to calculate "this page."
     15 
     16 	if {![catch {dict get $::headers url-prefix} urlprefix]} {set prefix [file normalize $navprefix]}
     17 	# This is the prefix that is assumed to be on URLs but not on $::outputfile during generation. This is used to calculate "this page."
     18 
     19 	if {[catch {dict get $::headers navbar-title} navtitle]} {set navtitle ""}
     20 	#mimicking the werc function of the same nature
     21 
     22 	if {[catch {set ::outputfile} outputfile]} {
     23 		puts stderr "Warn: Navbar plugin: You are running ussg in stdout mode. Navbar doesn't work in stdout mode; it needs the output file name to know if it's on \"this page\". Navbar will still do its best, but there will be no differentiation of this page from not this page."
     24 		set outputfile ""
     25 	} ;# without an output filename we cannot work properly.
     26 
     27 	if {[catch {set ::inputfile} inputfile]} {
     28 		puts stderr "Warn: Navbar plugin: You are running ussg in stdin mode. Navbar may not work in stdin mode; it needs the output file name to know if it's on \"this page\". Navbar will still do its best."
     29 		set inputfile ""
     30 	} ;# without an input filename we cannot work properly.
     31 
     32 	if {[catch {dict get $::headers navbar-source} navsource]} {
     33 		puts stderr "Warn: Navbar plugin: there is no Navbar-Source document header. This is required to use Navbar, and must be a regular file of tab-separated values: path, label."
     34 	} {
     35 		# off to the races, folks!
     36 		if {[catch {open [file normalize [lindex $navsource end]] r} provinputfd]} {
     37 			puts stderr [format "Warn: Navbar plugin: fixed-paths file \'%s\' could not be opened for reading. This file must be openable for Navbar to work. \[open\] reports:" $navsource]
     38 			puts stderr $provinputfd
     39 			return
     40 		} {
     41 			if {$navtitle != ""} {puts $::outputfd [format "<p class=\"sideBarTitle\">%s</p>" [lindex $navtitle end]]}
     42 			puts $::outputfd "<ul>"
     43 			while {![eof $provinputfd]} {
     44 				set garbage [lassign [split [gets $provinputfd] "\t"] path label]
     45 				if {$path == ""} {continue}
     46 				if {$outputfile == ""} {
     47 					set isthispath 0
     48 					puts $::outputfd [format "<li><a href=\"%s\">&raquo; <i>%s</i></a></li>" $path $label]
     49 				} {
     50 					set isthispath 0
     51 					if {[string index $path 0] == "/"} {
     52 						# then we can see if it's this path
     53 						if {[file normalize [format "%s/%s" $prefix $path]] == [file normalize $outputfile]} {set isthispath 1}
     54 					}
     55 					if {$isthispath} {
     56 						puts $::outputfd [format "<li><a href=\"%s\" class=\"thisPage\">&raquo; <i>%s</i></a></li>" $path $label]
     57 					} {
     58 						puts $::outputfd [format "<li><a href=\"%s\">&rsaquo; %s</a></li>" $path $label]
     59 					}
     60 				}
     61 				puts stderr [format "info: navbar plugin: prefix: %s outputfile: %s path: %s label: %s isthispath: %s" $prefix $outputfile $path $label $isthispath]
     62 			}
     63 			puts $::outputfd "</ul>"
     64 		}
     65 	}
     66 }