htmlutil.cls source

00001 /*----------------------------------------------------------------------------*/
00002 /*                                                                            */
00003 /*   Copyright (c) 2004-2009 William  Data  Systems Ltd. and Geoff Stevens.   */
00004 /*   All rights reserved.                                                     */
00005 /*                                                                            */
00006 /*   This program and the  accompanying  materials are made available under   */
00007 /*   the terms of the  Common  Public  License  v1.0 which accompanies this   */
00008 /*   distribution. A  copy  is  also  available  at  the following address:   */
00009 /*   http://www.opensource.org/licenses/cpl1.0.php                            */
00010 /*                                                                            */
00011 /*   Redistribution and use in  source  and  binary  forms, with or without   */
00012 /*   modification, are  permitted  provided  that  the following conditions   */
00013 /*   are met:                                                                 */
00014 /*                                                                            */
00015 /*   Redistributions  of  source  code  must  retain  the  above  copyright   */
00016 /*   notice, this list of conditions and the following disclaimer.            */
00017 /*                                                                            */
00018 /*   Redistributions in  binary  form  must  reproduce  the above copyright   */
00019 /*   notice, this list of  conditions  and  the following disclaimer in the   */
00020 /*   documentation and/or other materials provided with the distribution.     */
00021 /*                                                                            */
00022 /*   Neither the name or trademarks  of  William Data Systems nor the names   */
00023 /*   of its  contributors  may  be  used  to  endorse  or  promote products   */
00024 /*   derived from this software without specific prior written permission.    */
00025 /*                                                                            */
00026 /*   DISCLAIMER                                                               */
00027 /*                                                                            */
00028 /*   THIS SOFTWARE IS PROVIDED  BY  THE  COPYRIGHT HOLDERS AND CONTRIBUTORS   */
00029 /*   "AS IS" AND  ANY  EXPRESS  OR  IMPLIED  WARRANTIES, INCLUDING, BUT NOT   */
00030 /*   LIMITED TO, THE IMPLIED WARRANTIES  OF MERCHANTABILITY AND FITNESS FOR   */
00031 /*   A PARTICULAR PURPOSE ARE DISCLAIMED.  IN  NO EVENT SHALL THE COPYRIGHT   */
00032 /*   OWNER OR CONTRIBUTORS BE LIABLE  FOR ANY DIRECT, INDIRECT, INCIDENTAL,   */
00033 /*   SPECIAL,  EXEMPLARY,  OR  CONSEQUENTIAL  DAMAGES  (INCLUDING,  BUT NOT   */
00034 /*   LIMITED TO, PROCUREMENT OF SUBSTITUTE  GOODS OR SERVICES; LOSS OF USE,   */
00035 /*   DATA, OR PROFITS; OR BUSINESS  INTERRUPTION) HOWEVER CAUSED AND ON ANY   */
00036 /*   THEORY OF LIABILITY, WHETHER  IN  CONTRACT,  STRICT LIABILITY, OR TORT   */
00037 /*   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN  ANY WAY OUT OF THE USE   */
00038 /*   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.     */
00039 /*                                                                            */
00040 /*----------------------------------------------------------------------------*/
00041 --  HTML page output utility static classe
00042 --
00043 --  These could be recast as routines, but making them class methods keeps them
00044 --  out of the namespace
00045 --
00046 -- class lookup
00047 ::REQUIRES 'classfinder.cls'
00048 -- html components
00049 ::REQUIRES 'fsobjects.cls'
00050 -- html components
00051 ::REQUIRES 'nodes.cls'
00052 -- flatclause
00053 ::REQUIRES 'rexxprogram.cls'
00054  
00055 -- sort a queue of Comparables and return its array
00056 -- @param q - the queue to sort
00057 -- @return sorted array
00058 ::ROUTINE sortq PUBLIC
00059   use strict arg q
00060  
00061   a = q~makearray
00062  
00063   a~sort
00064  
00065   return a
00066  
00067 ::CLASS htmlutil PUBLIC
00068  
00069 -- produce a menu
00070 -- @param tp - queue to which to add menu
00071 -- @param selector - selector name of tab to set active
00072  
00073 -- add a tabs header to a queue
00074 -- @param outq - the queue to which to add tabs
00075 -- @param tablist - queue of three-element queues
00076 --                element 1 : display name of tab
00077 --                element 2 : url to associate with tab
00078 --                element 3 : selector name
00079 -- @param selector - tab selector to set active
00080 ::METHOD tabshead CLASS
00081   use strict arg outq, tablist, selector
00082  
00083   outq~queue('<div class="tabs">')
00084   outq~queue('<ul>')
00085  
00086   do i over tablist
00087     if i[3] = selector
00088       then outq~queue('<li class="current">')
00089       else outq~queue('<li>')
00090     outq~queue('<a href="'i[2]'">')
00091     outq~queue('<span>'i[1]'</span>')
00092     outq~queue('</a>')
00093   end
00094  
00095   outq~queue('</ul>')
00096   outq~queue('</div>')
00097  
00098  
00099 -- expand details of callable feature
00100 -- @param htmlout - hrhrmlout object
00101 -- @param m - rdfeature, the proc or method
00102 -- @param bc - block comment of feature
00103 -- @param tp - queue on which to put output
00104 ::METHOD callableexpand CLASS
00105   use arg htmlout, m, bc, tp
00106  
00107   if m~exposelist~words > 0
00108     then do
00109            tp~queue('<div class="paramname">Exposes</div>')
00110            tp~queue(m~exposelist)
00111          end
00112   if bc~parms~items > 0 | m~arglist~words > 0
00113     then do
00114            tp~queue('<div class="paramname">Parameters</div>')
00115            copylist = m~arglist
00116  
00117            do i over bc~parms
00118              parse value .htmlutil~htmlizestring(i) with pname rest
00119              inx = copylist~wordpos(pname)
00120              if inx > 0
00121                then do
00122                       copylist = copylist~delword(inx,1)
00123                     end
00124                else do
00125                       if m~type = 'METH' | m~type = 'ATTR'
00126                         then htmlout~pwrongdoc~queue(m~document~relpath'::'m~ownerclass~rexxname'::'m~rexxname ''''pname'''')
00127                         else htmlout~pwrongdoc~queue(m~document~relpath'::'m~rexxname ''''pname'''')
00128                     end
00129              tp~queue('<span class="param">'pname'</span>' .classfinder~classnames(m~document, rest)'<br>')
00130            end
00131            j = copylist~words
00132            do j
00133              parse var copylist pname copylist
00134              if m~type = 'METH' | m~type = 'ATTR'
00135                then htmlout~pmissingdoc~queue(m~document~relpath'::'m~ownerclass~rexxname'::'m~rexxname ''''pname'''')
00136                else htmlout~pmissingdoc~queue(m~document~relpath'::'m~rexxname ''''pname'''')
00137              tp~queue('<span class="param">'pname'</span> not documented<br>')
00138            end
00139  
00140          end
00141   if bc~returns~items > 0
00142     then do
00143            tp~queue('<div class="paramname">Returns</div>')
00144            do i over bc~returns
00145              tp~queue(.classfinder~classnames(m~document, .htmlutil~htmlizestring(i))'<br/>')
00146            end
00147          end
00148  
00149   if bc~pres~items > 0
00150     then do
00151            tp~queue('<div class="paramname">Preconditions</div>')
00152            do i over bc~pres
00153              tp~queue(.classfinder~classnames(m~document, .htmlutil~htmlizestring(i))'<br/>')
00154            end
00155          end
00156  
00157   if bc~posts~items > 0
00158     then do
00159            tp~queue('<div class="paramname">Postconditions</div>')
00160            do i over bc~posts
00161              tp~queue(.classfinder~classnames(m~document, .htmlutil~htmlizestring(i))'<br/>')
00162            end
00163          end
00164  
00165   if m~type = 'PROC' | m~type = 'ROUT'
00166     then do
00167            tp~queue('<div class="paramname">Called by</div>')
00168            do r over m~callrefs
00169              src = r~rdatom~document~getsource(r~rdatom~feature)
00170              fc = .flatclause~new(r~rdatom~feature, src)
00171              tagtext = '"<i>'self~htmlizestring(fc~flat)'</i>"'
00172              tp~queue('<a href = "'r~rdatom~document~hsrcurl'#'r~rdatom~hsrcanchor'">',
00173                       r~rdatom~document~filename'</a> line' r~rdatom~feature~startline tagtext'<br/>')
00174            end
00175            tp~queue('<br/>')
00176  
00177  
00178          end
00179  
00180  
00181 -- expand details of referrable
00182 -- @param htmlout - .htmlout object
00183 -- @param m - .rdfeature, the attribute or method
00184 -- @param tp - queue on which to put output
00185 ::METHOD referrableexpand CLASS
00186  
00187   use arg htmlout, m, tp
00188  
00189   if m~statrefs~items > 0
00190     then do
00191            tp~queue('<div class="paramname">Statically referenced by</div>')
00192            do r over m~statrefs
00193              src = r~rdatom~document~getsource(r~rdatom~feature)
00194              fc = .flatclause~new(r~rdatom~feature, src)
00195              tagtext = '"<i>'self~htmlizestring(fc~flat)'</i>"'
00196              tp~queue('<a href = "'r~rdatom~document~hsrcurl'#'r~rdatom~hsrcanchor'">',
00197                       r~rdatom~document~filename'</a> line' r~rdatom~feature~startline tagtext'<br/>')
00198            end
00199            tp~queue('<br/>')
00200          end
00201  
00202   if m~dynrefs~items > 0
00203     then do
00204            tp~queue('<div class="paramname">Dynamically referenced by</div>')
00205            do r over m~dynrefs
00206              src = r~rdatom~document~getsource(r~rdatom~feature)
00207              fc = .flatclause~new(r~rdatom~feature, src)
00208              tagtext = '"<i>'self~htmlizestring(fc~flat)'</i>"'
00209              tp~queue('<a href = "'r~rdatom~document~hsrcurl'#'r~rdatom~hsrcanchor'">',
00210                       r~rdatom~document~filename'</a> line' r~rdatom~feature~startline tagtext'<br/>')
00211            end
00212            tp~queue('<br/>')
00213          end
00214  
00215  
00216  
00217 -- replace dangerous characters for html output
00218 -- @param c - character for possible replacement
00219 -- @return html-safe character or string
00220 ::METHOD htmlize CLASS
00221   use strict arg c
00222   select
00223     when c = '<'
00224       then return '&lt;'
00225     when c = '>'
00226       then return '&gt;'
00227     when c = '&'
00228       then return '&amp;'
00229     otherwise return c
00230   end
00231  
00232 -- replace dangerous characters for html output
00233 -- @param text - the string in which to replace html dangerous characters
00234 -- @return html-safe string
00235 ::METHOD htmlizestring CLASS
00236   use strict arg text
00237   newtext = ''
00238   do while text <> ''
00239     parse var text 1 c 2 text
00240     newtext = newtext || self~htmlize(c)
00241   end
00242   return newtext
00243  
00244 -- insert trailer statements into a queue
00245 -- @param tp - queue to which to add trailer
00246 ::METHOD trailer CLASS
00247   use arg htmlout, tp
00248   -- trailer
00249   tp~queue('<hr size="1"/>')
00250   tp~queue('<table width="100%"><tr><td width="50%">')
00251   tp~queue('<address style="text-align: left;">')
00252   tp~queue(htmlout~trailericon)
00253   tp~queue('</address>')
00254   tp~queue('</td><td width="50%">')
00255   tp~queue('<address style="text-align: right;">')
00256   tp~queue('<small>')
00257   tp~queue('Generated on' date() time() 'for' htmlout~title 'by')
00258   tp~queue('<a href="https://sourceforge.net/projects/rexxliterate/">')
00259   tp~queue(.nodes~prodimg)
00260   tp~queue('</a>')
00261   tp~queue('&nbsp;'htmlout~pversion)
00262   tp~queue('</small>')
00263   tp~queue('</address>')
00264   tp~queue('</td></tr></table>')
00265  
00266  
00267 -- write a file from a queue
00268 -- @param tp - queue to write
00269 -- @param towrite - filename to write it as
00270 ::METHOD writepage CLASS
00271   use arg tp, towrite
00272   -- write page as html
00273   rc = SysFileDelete(towrite)
00274   s = .stream~new(towrite)
00275   rc = s~arrayout(tp)
00276   s~close
00277  

Get RexxLiterate at SourceForge.net. Fast, secure and Free Open Source software downloads
Generated on 31 Aug 2010 05:20:29 for RexxLiterate by rexxliterate  0.0.1