qJc@sdZddkZddkZddklZdZdZdZdZ dZ d Z d Z d Z d fd YZdfdYZdS(stccpage2.py: For dynamic generaton of web pages in standard TCC style. For documentation, see: http://www.nmt.edu/tcc/projects/tccpage/ iN(tetreesr shttp://www.w3.org/1999/xhtmls http://www.nmt.edu/tcc/style.csss / shttp://www.nmt.edu/tcc/s&http://www.nmt.edu/tcc/images/logo.pngs; cCsSt|djo|ipd||_n"|d}|ipd||_dS(sAdd text s inside a parent element. [ (parent is an et.Element instance) and (s is a string) -> if parent has no element children -> parent.text +:= s else -> (last element child of parent).tail +:= s ] itiN(tlenttextttail(tparenttstyoungest((s-/u/www/docs/tcc/projects/pystyler/tccpage2.pyt addTextMixeds  tTCCPagecBseZdZd d d d d d d dZdZdZdZdZdZ dZ dZ d Z d Z d Zd d ZRS(s Represents one page in the TCC style. Exports: TCCPage ( title=None, navList=None, author=None, url=None, logoImage=None, logoLink=None, cssUrl=None ): [ (title is the page's title as a string, default empty) and (navList describes the page's standard set of navigational links as NavLink instances, default empty) and (author is the page's author credit string, default empty) and (url is the page's URL as a string, default empty) and (logoImage is the URL of the logo image, default TCC_LOGO_URL) and (logoLink is the URL the logo links to, default TCC_MAIN_URL) and (cssURL is the stylesheet URL, default CSS_URL) -> return a new, empty TCCPage instance representing those values ] .root: [ self's "html" element as an et.Element ] .headTitle: [ self's head's title as an et.Element, initially the title argument, read/write ] .bodyTitle: [ self's body title as an h1 et.Element, initially the title argument, read/write ] .content: [ a div et.Element in self's body between the top and bottom nav links ] .address: [ self's address as an address et.Element, initially the author argument, read/write ] .url: [ as passed to constructor, read-only ] .write ( outFile=None ): [ outFile is a writeable file, defaulting to sys.stdout -> outFile +:= an XHTML representation of self ] State/Invariants: .doc: [ self's Document instance ] .head: [ self's head element ] .body: [ self's body element ] cCs|pd|_|pg|_|pd|_|pd|_|pt|_|pt|_|pt|_ t i ddt |_ t i|i |_|i|idS(sConstructor for a TCCPage.RthtmltxmlnsN(ttitletnavListtauthorturlt TCC_LOGO_URLt logoImaget TCC_MAIN_URLtlogoLinktCSS_URLtcssUrltettElementtXHTML_NStroott ElementTreetdoct_TCCPage__createHeadt_TCCPage__createBody(tselfR R RRRRR((s-/u/www/docs/tcc/projects/pystyler/tccpage2.pyt__init__gs cCssti|id|_ti|id|_|io|i|i_nti|idddd|idS(sSet up the page head element. [ self.doc := self.doc with a new head element added containing self's head content self.head := that element ] theadR tlinktrelt stylesheetthrefN(Rt SubElementRR t headTitleR RR(R((s-/u/www/docs/tcc/projects/pystyler/tccpage2.pyt __createHeads  cCs\ti|id|_|i|iti|id|_|i|idS(sSet up the page body. [ self.doc := self.doc with a new body element added containing self's body content self.body := that element self.bodyTitle := the h1 element containing self.title self.content := a div element for the body content self.address := the address element in the colophon ] tbodytdivN( RR%RR(t_TCCPage__topNavt_TCCPage__titleBlocktcontentt_TCCPage__botNavt_TCCPage__colophon(R((s-/u/www/docs/tcc/projects/pystyler/tccpage2.pyt __createBodys    cCsgti|id}d|id self.body := self.body with the top nav bar added ] R)stop-navtclassRN(RR%R(tattribR tnoTopt_TCCPage__topNavItemt TOP_NAV_SEP(RtnavBartprefixtnavItem((s-/u/www/docs/tcc/projects/pystyler/tccpage2.pyt__topNavs    cCsft|||io;|id\}}ti|dd|}|i|_nt||idS(sAdd one item to the top navigational bar. [ (navBar is an et.Element) and (navItem is a NavLink) -> navBar +:= (prefix) + (navItem as a top nav link) ] itaR$N(RtdestListRR%t shortNameR(RR5R7R6R RR9((s-/u/www/docs/tcc/projects/pystyler/tccpage2.pyt __topNavItems  cCsti|iddd}ti|ddd}ti|ddd }ti|d |_|io|i|i_nti|ddd }ti|d d |i}ti|dddd|i}dS(sSet up the main page title block. [ self.title as invariant -> self.body := self.body with a title block added self.bodyTitle := the h1 within that title block ] ttabletwidths100%ttrtvalignttopttdtaligntleftth1trightR9R$timgtalttlogotsrcN(RR%R(t bodyTitleR RRR(RR=trowRBR9RG((s-/u/www/docs/tcc/projects/pystyler/tccpage2.pyt __titleBlocks  cCs8ti|idx|iD]}|i|qWdS(sAdd the page-bottom navigational links section. [ (self.body as invariant) and (self.navList as invariant) -> self.body := self.body with bottom nav links added from self.navList ] thrN(RR%R(R t_TCCPage__botNavItem(RR7((s-/u/www/docs/tcc/projects/pystyler/tccpage2.pyt__botNav(s  cCsl|ipdSti|id}|id\}}|p|i|||in|i||dS(sGenerate one page-bottom navigational link. [ navItem is a NavLink instance -> self.body +:= a bottom nav link made from navItem ] NR)i(R:RR%R(t_TCCPage__botNavShortR;t_TCCPage__botNavGeneral(RR7R)R R((s-/u/www/docs/tcc/projects/pystyler/tccpage2.pyt __botNavItem;s  cCs7ti|dd|}ti|d}||_dS(sGenerate a short-form navigational link. [ (div is an et.Element) and (url is a URL as a string) and (shortName is a string) -> div +:= a link to url with link text shortName ] R9R$tbN(RR%R(RR)RR;R9RT((s-/u/www/docs/tcc/projects/pystyler/tccpage2.pyt __botNavShortbs cCsti|d}d|i|_d}xV|iD]K\}}|ot||nti|dd|}||_t}q2WdS(sEGenerate a bottom navigational link in the general case. [ (div is an et.Element) and (navItem is a NavItem instance) -> div +:= (navItem.shortName, boldfaced) + (elements of navItem.destList as links, separated by BOT_NAV_SEP) ] RTs%s: RR9R$N(RR%R;RR:Rt BOT_NAV_SEP(RR)R7RTR6R RR9((s-/u/www/docs/tcc/projects/pystyler/tccpage2.pyt__botNavGeneralus   cCsti|idti|id|_|io|i|i_nti|id}dtid|_|io@ti|id}d|_ti|d}|i|_ndS( sAdd the colophon section to the page. [ (self.author as invariant) and (self.url as invariant) -> self.body := self.body with the colophon added self.address := the address element within that colophon ] RNtaddressR)sLast updated: %ss%Y-%m-%d %H:%M %ZsURL: tttN( RR%R(RXRRttimetstrftimeR(RR)RY((s-/u/www/docs/tcc/projects/pystyler/tccpage2.pyt __colophons    cCs7|pti}|it|ii|dtdS(sWrite the page as XHTML.t pretty_printN(tsyststdouttwritet XHTML_DOCTYPERtTrue(RtoutFiletout((s-/u/www/docs/tcc/projects/pystyler/tccpage2.pyR`s N(t__name__t __module__t__doc__tNoneRRRR*R3R+R-RORQRRR.R`(((s-/u/www/docs/tcc/projects/pystyler/tccpage2.pyR <s( !  ( $  $  '  * !tNavLinkcBseZdZdddZRS(sRepresents one navigational feature with zero or more destinations. Exports: NavLink ( shortName, destList=None, noTop=0 ): [ (shortName is the short name of this feature) and (destList is a list of (title, url) tuples representing places this link should point, defaulting to none) and (noTop is true iff this feature should be omitted from the top nav bar) -> return a new NavLink instance representing those values ] .shortName: [ as passed to constructor, read-only ] .destList: [ as passed to constructor, read-only ] .noTop: [ as passed to constructor, read-only ] icCs||_||_||_dS(sConstructor for NavLink.N(R;R:R2(RR;R:R2((s-/u/www/docs/tcc/projects/pystyler/tccpage2.pyRs  N(ReRfRgRhR(((s-/u/www/docs/tcc/projects/pystyler/tccpage2.pyRis(RgR^RZtlxmlRRRaRRR4RRRVRR Ri(((s-/u/www/docs/tcc/projects/pystyler/tccpage2.pyts   $