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

[REBOL] lister

From: Al::Bri::xtra::co::nz at: 12-Jul-2003 17:41

Beware! I've had to change this line: ;test: system/version/4 = 3 to this: test: true Andrew J Martin ICQ: 26227169 -><- #!rebol -cs REBOL [ Name: 'lister Title: "REBOL Email Discussion Web Pages" File: %lister.r Author: ["Carl Sassenrath"] Version: 1.1.0 Date: 10-Jul-2003 Tabs: 4 Revisions: [ 12/July/2003 1.1.0 [Al--Bri--xtra--co--nz] "Gold leafing..." 10-Jul-2003 1.0.3 [carl--rebol--com] {Minor cleanups.} 10-Jul-2003 1.0.1 [carl--rebol--com] {Released source code.} ] ] ; If we're on the devel system, set switch for rapid development: ;test: system/version/4 = 3 test: true Folder: %web/ ; Master index file name: index-file: %index.html ; Source output file: source-file: replace copy Rebol/script/header/File %.r %.html css-file: replace copy Rebol/script/header/File %.r %.css ; Target directory for storing message HTML files: msg-dir-ref: %list-msgs/ msg-dir: Folder/:msg-dir-ref if not exists? msg-dir [ make-dir/deep msg-dir ] ; Message block format: ; * Each record is a block of: [id from subject date content] ; * Order is older to newer ; * DB currently selects only current month (to be changed) ; * Date field is currently a string (but should be REBOL date/time) ; Or using Rebol to describe it, it's like: ; [id [integer!] from [email!] subject [string!] date [string!] content [string!]] msgs: either test [ ; Just use some test messages: [ [10001 [carl--rebol--com] "Example Message" "3 Jul 2003" "Content here"] [10002 [luke--rebol--com] "Another Message" "4 Jul 2003" "Happy Iday"] ] ][ ; Read and parse the database for current month: ; (Note: the DB is huge text file right now, but REBOL parses ; it very fast, so we're being a bit lazy, but it needs to be ; optimized someday.) msgs: do %load-msgs.r ] encode-html: func [ ; Translate only the most common HTML tags and escapes. ; (If you think others are needed, add them. But remember ; that this code runs at N-squared speed, so take it easy.) code [string!] "Script to translate" ][ replacements: [#"&" "&amp;" #"<" "<" #">" ">"] foreach [from to] replacements [ replace/all code from to ] ] Linkage: func [ Id1 [integer!] "First message number" Index [integer!] "Current message number" Id2 [integer!] "Last message number" ] [ rejoin [ either Id1 < Index [ rejoin [{<a href="} Index - 1 {.html">< Older</a> }] ] [ "" ] <a href="../index.html"> "Index" </a> either Index < Id2 [ rejoin [{ <a href="} Index + 1 {.html">Newer ></a>}] ] [ "" ] ] ] write Folder/:css-file { @media screen { body { color: #000000; background: #FFFFFC; } body, p, td { Font-Family: "Arial"; Font-Size: 10pt; } } @media print { } } Heading: func [ "Generates standard HTML header." Title [string!] "The title to show." ] [ rejoin [ make string! 1000 <html><head> <title> Title </title> rejoin [{<link rel="stylesheet" type="text/css" href="} css-file {" />}] </head> ] ] emit-message-page: func [ "Generate a message as a very simple HTML web page." msg [block!] "Message block: [id from subject date content]" Id1 [integer!] "First message number" Id2 [integer!] "Last message number" ][ write join msg-dir [msg/1 ".html"] rejoin [ make string! 1000 Heading join "REBOL List - " msg/3 <body bgcolor=#FFFFFC> <h1> "REBOL Email Discussion List" </h1> <h2> encode-html msg/3 </h2> <b> msg/2 <br /> msg/4 <br /> "#" msg/1 <br /> Linkage Id1 Msg/1 Id2 </b> <hr><pre> encode-html msg/5 </pre><hr><br /> <b> Linkage Id1 Msg/1 Id2 </b> <br /> <a href=""><font color="gray"><b>"2003"</b></font></a> </body></html> ] ] emit-index-line: func [ "Generate a message line in the master index" msg [block!] "Message block: [id from subject date content]" ][ rejoin [ make string! 1000 pick [<tr> <tr bgcolor="#E0E8E0">] odd? msg/1 <td nowrap width="10" align="right"><font color="GRAY"> msg/1 </font></td> <td><b> {<a href="} msg-dir-ref msg/1 {.html">} msg/3 </a></b></td> <td> msg/2 </td> <td nowrap> msg/4 </td> </tr> newline ] ] emit-index-page: func [ {Generate the master message index page. Messages are listed in reverse order.} msgs [block!] "Block of messages" /local html ][ html: rejoin [ make string! 10000 Heading "REBOL List Index" <body bgcolor=#FFFFFC> <h1> "REBOL Email Discussion List" </h1> <b> length? msgs " messages for " pick system/locale/months now/month " as of " now "." </b> <br /> "You may need refresh/reload this page to see changes." <br /> "To post messages or learn more, " <a href=""> "go here" </a> "." <hr> <table border="0" cellpadding="4" cellspacing="0" width="100%"> ] foreach msg head reverse msgs [ insert tail html emit-index-line msg ] write Folder/:index-file rejoin [ html </table> <hr> <font size="1"> <a href=""> <b> "2003" </b> </a> <br /> rejoin [{<a href="} source-file {">}] "Lister Source Code " system/script/header/version </a> </font> </body></html> ] write Folder/:source-file rejoin [ make string! 10000 Heading "REBOL List Source Code" <body bgcolor=#FFFFFC><pre> detab/size encode-html read/with Rebol/script/header/File CRLF 4 </pre> </body></html> ] ] foreach msg msgs [ emit-message-page msg first first msgs first last msgs ] emit-index-page msgs if test [ browse Folder/:index-file ] quit