Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

[REBOL] Re: HTML-Template.r ?

From: pa:russo:perd at: 1-May-2001 17:12

>Anyone working on a HTML::Template (Perl module) clone for REBOL ? > >Would be nice to be able to separate HTML code from script code sometimes (and >then letting the REBOL CGI's concentrate on data processing) > >Info/Tutorial: >http://www.perlmonth.com/features/template/template.html?issue=11 > >Source: >http://sourceforge.net/projects/html-template/ > >/PeO
I don't know if you are referring to something like this exactly, but perhaps the following example could be useful to solve your problem. The logic is quite simple: 1. An HTML template with placeholders 2. A set of replacement rules 3. A cycle that replace the placeholders using the replacement rules Hope it helps. -- Paolo Russo #!/opt2/cyberurb/rebol/rebol -cs REBOL [ Title: "View a duello" Date: 07-jan-2001 Author: "Paolo Russo" Owner: "PERD s.r.l." Site: http://www.perd.com Email: [pa--russo--perd--com] File: %ilduello-view.r Project: 'duello Purpose: { Crea la maschera necessaria per votare un duello. } Comments: {} History: [ 04-mar-2001 "Modificato per visualizzare la schermata con i dati per votare" "Paolo Russo" 07-jan-2001 "Prima stesura" "Paolo Russo" ] Category: [CGI] Needs: [] Language: 'English ] ; ==== MODELLO DELLA PAGINA HTML html-template: { <HTML><HEAD> <TITLE>IL DUELLO: E ORA DECIDI TU!</TITLE> <LINK REL=STYLESHEET HREF="http://www.cyberurbs.com/duello/ilduello.css" TYPE="text/css"> </HEAD> <BODY BACKGROUND="http://www.ilduello.com/media/workspace.jpg"> <P class="titolopagina">___strillo___</P> <P>___descrizione___</P> <FORM ACTION="/cgi-bin/ilduello-vote.r" METHOD="GET"> <TABLE BORDER="0" CELLSPACING="12" CELLPADDING="1"> <TR ALIGN="left" VALIGN="top"> <TD COLSPAN="2">E ora decidi tu tra...</TD> </TR> <TR ALIGN="left" VALIGN="top"> <TD><INPUT NAME="duellante" TYPE="radio" VALUE="1" ><B>___duellante-1___</B></TD> <TD><INPUT NAME="duellante" TYPE="radio" VALUE="2"><B>___duellante-2___</B></TD> </TR> <TR ALIGN="left" VALIGN="top"> <TD>E-mail:</TD> <TD><INPUT NAME="email-address" TYPE="text" SIZE="40" MAXLENGTH="40"></TD> </TR> <TR ALIGN="left" VALIGN="top"> <TD>Password</TD> <TD><INPUT NAME="password" TYPE="password" SIZE="20" MAXLENGTH="20"></TD> </TR> <TR ALIGN="right" VALIGN="top"> <TD><INPUT NAME="duello" TYPE="hidden" VALUE="___codiceduello___"></TD> <TD><INPUT NAME="submit" TYPE="submit" VALUE=" vota! "></TD> </TR> </TABLE> </FORM> </BODY> </HTML> } ;==DEBUG TOOLS ;To be defined only during debugging. You MUST unset these words in the final version. ;debug-mode: 'on if not value? 'debug-mode [ print {Content-Type: text/html^/} ] ;Acquisizione dei dati di input either value? 'debug-mode [ ;deve ricevere una stringa del tipo -duellante1 vs. duellante2 [codiceduello]- ][ form-fields: make object! decode-cgi-query system/options/cgi/query-string ] ;Lettura dei dati either error? archivio-duelli: try [ load %ilduello-duelli.dat][ replacement-rules: [ ___strillo___ "Ooops..." ___descrizione___ "Archivio dei duelli momentaneamente non disponibile." ___duellante-1___ "" ___duellante-2___ "" ___codiceduello___ "" ] ][ either foreach duello archivio-duelli [ if duello/did = form-fields/did [ replacement-rules: compose [ ___strillo___ (duello/strillo) ___descrizione___ (duello/descrizione) ___duellante-1___ (duello/duellante/1) ___duellante-2___ (duello/duellante/2) ___codiceduello___ (duello/did) ] break/return true ] ][ ][ replacement-rules: [ ___strillo___ "Ooops..." ___descrizione___ "Il duello selezionato non &egrave; pi&ugrave; presente nell'archivio." ___duellante-1___ "" ___duellante-2___ "" ___codiceduello___ "" ] ] ] ; === Composizione della pagina HTML html-code: copy html-template foreach [ text-to-substitute replacement-text] replacement-rules [ replace/all html-code to-string text-to-substitute to-string replacement-text ] print html-code -- Paolo Russo [pa--russo--perd--com] _________________ PERD s.r.l. Virtual Technologies for Real Solutions http://www.perd.com