6.14.6.2. Code

Start python section to interscript/weavers/web.py[1 /8 ] Next Last
     1: #line 87 "web_weaver.ipk"
     2: from interscript.weavers.multiplexor import multiplexor
     3: from interscript.weavers.html import html_weaver
     4: from interscript.weavers.html import cvt_code, cvt_text
     5: from interscript.drivers.sinks.bufdisk import named_file_sink
     6: from interscript.drivers.sinks.disk import simple_named_file_sink
     7: from interscript.core.sets import set
     8: from interscript.languages.interscript_languages import tr_phrase
     9: from interscript.core.stacks import stack
    10: 
    11: import string
    12: import traceback
    13: 
    14: def munge2filename(x):
    15:   s = ''
    16:   ids = string.letters + string.digits + '_'
    17:   for ch in x:
    18:     if ch in ids: s = s + ch
    19:     elif ch == ' ': s = s + '_'
    20:     else: s = s + hex(ord(ch))
    21:   return s
    22: 
    23: def mk_web(pass_frame,basename, directory, prefix, eol, title, language):
    24:   if language: filename = directory + language + '_' + basename + '.html'
    25:   else: filename = directory + basename + '.html'
    26:   w = named_file_sink(pass_frame,filename, prefix, eol=eol)
    27:   if not title: title = basename
    28:   w = html_weaver(pass_frame,w,title=title,language=language)
    29:   if language: pattern = language+'_'+basename+'_%s.html'
    30:   else: pattern = basename+'_%s.html'
    31:   return stacking_weaver(w,pattern,(1,2,3,4,5,6,7,8,9,10),language=language)
    32: 
    33: 
    34: class stacking_weaver(multiplexor):
    35:   def __init__(self,parent_weaver, pattern='', break_list=None, language='', **kwds):
    36:     self.base = [parent_weaver]
    37:     self.pass_frame = parent_weaver.pass_frame
    38:     self.master = self.pass_frame.master
    39:     self.process = self.pass_frame.process
    40:     self.language = language
    41:     self.sequence = self.pass_frame.get_new_sequence_number()
    42:     self.persistent_frame = self.master.get_persistent_frame(self.sequence)
    43:     self.persistent_frame['language']=language
    44:     if 'weavers' in self.process.trace:
    45:       self.process.acquire_object(self,'WEB WEAVER')
    46:       print 'language=',language
    47:     self.tags = ['web','html']
    48:     if language: self.tags.append(language)
    49:     self.tr_phrase = lambda x,y=language: tr_phrase(x,y)
    50:     self.debug_missing_methods = 0
    51:     self.keywords = kwds
    52: 
    53:     self.original_filename = 'Unknown'
    54: 
    55:     self.toc_depth = self.keywords.get('toc_depth',99)
    56:     parent_sink = parent_weaver.sink.name
    57:     self.basedir = string.join(string.split(parent_sink,'/')[:-1],'/')+'/'
    58:     if self.basedir == '/': self.basedir = ''
    59:     #print 'Base directory for stacking weaver is',self.basedir
    60:     self.home_file = string.split(parent_sink,'/')[-1]
    61:     if kwds.has_key('title'):
    62:       self.title = kwds['title']
    63:     elif hasattr(parent_weaver,'title'):
    64:       self.title = parent_weaver.title
    65:     else:
    66:       self.title = self.home_file
    67:     self.pattern = pattern
    68:     if string.find(pattern,'%') == -1:
    69:       self.pattern = self.pattern+'_%s.html'
    70:     # break list
    71:     self.break_list = [0]
    72:     if break_list:
    73:       for b in break_list: self.break_list.append(b)
    74:     else:
    75:       for i in range(1,40): self.break_list.append(i)
    76: 
    77:     self.stack = [parent_weaver]
    78:     self.childcount = 0
    79:     self.debug = 0
    80:     self.protocol = 'web'
    81:     self.persistent_frame['protocol']=self.protocol
    82:     self.hcount = [1,0]
    83:     self.acount = 0
    84:     self.anchor_file = {}
    85:     self.name = 'web weaver for '+self.pattern
    86:     self.persistent_frame['name']=self.name
    87:     self.eol = parent_weaver.sink.eol
    88:     self.subdoc_stack = stack((0,None))
    89:     # table of contents
    90:     self.toc = []
    91: 
    92:     self.home_anchor = '<A HREF="'+self.home_file+'">'+self.tr_phrase('Home')+'</A>'
    93:     self.home_nav = '<DIV CLASS="NAVIGATION">'+self.home_anchor+'<BR><HR></DIV>'
    94: 
    95:     #self.mk_frames(self.home_file)
    96: 
    97:     # cheat here, guess next exists :-)
    98:     next = self.pattern%('%04d'%(self.childcount+1))
    99:     next = '<A HREF="'+next+'">'+self.tr_phrase('Next')+'</A>'
   100: 
   101:     nav = ''
   102:     if next : nav = nav + next+' '
   103: 
   104:     hnav = '<HR><DIV CLASS="NAVIGATION">'+nav+'<BR><HR></DIV>'
   105:     parent_weaver._writeline(hnav)
   106: 
   107:   def mk_head(self, sink):
   108:     w = sink.writeline
   109:     w('<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN">')
   110:     w( '<HTML>')
   111:     w( '<HEAD>')
   112: 
   113:     w('<TITLE>'+self.title+'</TITLE>')
   114: 
   115:     w( '<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=UTF-8">')
   116:     if self.keywords.has_key('author'):
   117:       author =self.keywords['author']
   118:       self.frames_sink.writeline( '<META NAME="Author" CONTENT="'+author+'">')
   119:     version = self.process.global_frame.version
   120: 
   121:     w( '<META NAME="Generator" CONTENT="Interscript '+version+'">')
   122:     w( '</HEAD>')
   123: 
   124:   def mk_frame(self,name, orientation, subframes):
   125:     filename = self.pattern % name
   126:     sink = named_file_sink(
   127:       self.pass_frame,
   128:       self.basedir+filename,
   129:       self.master.weaver_prefix,
   130:       eol=self.eol)
   131:     self.mk_head(sink)
   132:     pc = ''
   133:     for frame_name,frame_percent,frame_src in subframes:
   134:       pc = pc + str(frame_percent)+'%,'
   135:     pc = pc[:-1]
   136:     w = sink.writeline
   137:     w( '<FRAMESET '+orientation+'="'+pc+'" scrolling="yes">')
   138:     for frame_name,frame_percent,frame_src in subframes:
   139:       w( '<FRAME NAME="'+frame_name+'" SRC="'+frame_src+'">')
   140:     w( '</FRAMESET>')
   141:     w( '</HTML>')
   142: 
   143:   def mk_frames(self, doc,tables):
   144:     top = self.pattern % 'top' # top level frame
   145:     indexview = self.pattern % 'indexview'
   146:     indexnav = self.pattern % 'indexnav'
   147: 
   148:     contents = self.pattern % 'contents'
   149:     #classref = self.pattern % 'classref'
   150:     #funcref = self.pattern % 'funcref'
   151:     #identref = self.pattern % 'identref'
   152:     #testref = self.pattern % 'testref'
   153:     #filestatus = self.pattern % 'filestatus'
   154:     #sectionref = self.pattern % 'sectionref'
   155:     #sourceref = self.pattern % 'sourceref'
   156:     #metricsref = self.pattern % 'metricsref'
   157:     #noticesref = self.pattern % 'noticesref'
   158: 
   159:     self.mk_frame('indexview','ROWS', (
   160:       ('indexnav',20,indexnav),
   161:       ('indexdat',80,contents)))
   162:     self.mk_frame('top','COLS',(
   163:       ('indexview',30,indexview),
   164:       ('docview',70,doc)))
   165: 
   166:     nav = '';
   167:     for name, descr, target, count in tables:
   168:       if count:
   169:         filename = self.pattern % name
   170:         nav = nav + '<A HREF="'+filename+'" TARGET="indexdat">'+self.tr_phrase(descr)+'</A> '
   171:     ha = '<A HREF="'+self.home_file+'" TARGET="docview">'+self.tr_phrase('Home')+'</A>'
   172:     nav = '<DIV CLASS="NAVIGATION">'+nav+' '+ha+'</DIV>'
   173: 
   174:     filename = self.pattern % 'indexnav'
   175:     sink = named_file_sink(
   176:       self.pass_frame,
   177:       self.basedir+filename,
   178:       self.master.weaver_prefix,
   179:       eol=self.eol)
   180:     self.mk_head(sink)
   181:     w = sink.writeline
   182:     w ('<BODY LANG="'+self.language+'">')
   183:     w (nav)
   184:     w ('</BODY>')
   185:     w ('</HTML>')
   186: 
   187: 
   188:   def print_table(self,dict,sink):
   189:     keys = dict.keys()
   190:     keys.sort()
   191:     w = sink.writeline
   192:     w('<TABLE COLS="2" BORDER="1" CELLPADDING="2">')
   193:     for k in keys:
   194:       refs = dict[k]
   195:       w('<TR><TD VALIGN="Top"><CODE> '+k+' </CODE></TD><TD> ')
   196:       old_df = ''
   197:       for sf,sc,df,dc in refs:
   198:         key = (sf, sc)
   199:         if self.anchor_file.has_key(key):
   200:           child = self.anchor_file[key]
   201:         else:
   202:           child = ''
   203:         anchor = '<A HREF='+child+'#'+sf+':'+str(sc)+' TARGET="docview">'+str(dc)+'</A>'
   204: 
   205:         if old_df != '': w(', ')
   206:         if old_df != df:
   207:           w(df+': '+ anchor )
   208:           old_df = df
   209:         else:
   210:           w(anchor)
   211:       w('</TD></TR>')
   212:     w('</TABLE>')
   213: 
End python section to interscript/weavers/web.py[1]


6.14.6.2.1. Reference processor
6.14.6.2.2. section processor
6.14.6.2.3. heading processor
6.14.6.2.4. document control
6.14.6.2.5. Table of contents
6.14.6.2.6. Identifier Cross references