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

Rebol Server Pages

 [1/6] from: al::bri::xtra::co::nz at: 7-Oct-2002 16:59


Here's %Test.rsp, a example Rebol Server Pages file: <html> <head><title>Test</title></head> <body> <h1>Test</h1> <% random/seed now either random true [ %> Have a <b>nice</b> day! <% ] [ %> Have a <b>lousy</b> day! <% ] %> <br/> The date and time now is: <% now %> </body> </html> Note that "<%" and "%>" surround sections of Rebol script. It could be created by a HTML editor, I hope! :) I used my ML dialect to generate most of it, then edited by hand. Here's the RSP function: RSP: function [Text [string!]] [Open Close RSP Script String] [ Open: "<%" Close: "%>" RSP: make string! length? Text parse/all Text [ any [ end break | Open copy Script to Close Close (append RSP Script) | copy String [to Open | to end] (append RSP mold String) ] ] form replace/all reduce load RSP unset! "" ] Note that 'RSP is based on Rebol's 'build-markup. Here's the test script: write %Test.html RSP read %Test.rsp browse %Test.html And here's the generated HTML (I viewed the source and cut and pasted to this email: <html> <head><title>Test</title></head> <body> <h1>Test</h1> Have a <b>nice</b> day! <br/> The date and time now is: 7-Oct-2002/16:46:25+13:00 </body> </html> Note that the browser discards the extra spaces and line breaks shown here. Andrew Martin ICQ: 26227169 http://valley.150m.com/

 [2/6] from: maarten:koopmans:surfnet:nl at: 7-Oct-2002 11:50


RSP is based on build-markup is based on erebol. Shall we just leave it at build-markup? One Way To Do It helps acceptance sometimes. Having said that, I like the extension ;-) Using open and close as local variables is not a very good choice, for obvious reasons. i.e. <% copy open %somefile %> --Maarten Andrew Martin wrote:

 [3/6] from: al:bri:xtra at: 8-Oct-2002 10:06


Maarten wrote:
> Using open and close as local variables is not a very good choice, for obvious reasons. > > i.e. <% copy open %somefile %>
Some times I need the obvious pointed out to me. I'll change it. Thanks for pointing it out, Maarten. Andrew Martin ICQ: 26227169 http://valley.150m.com/ -><- Andrew Martin

 [4/6] from: al:bri:xtra at: 8-Oct-2002 17:14


Here's a better version with Maarten's suggested change. Rebol [ Name: 'RSP Title: "Rebol Server Pages" File: %RSP.r Author: "Andrew Martin" eMail: [Al--Bri--xtra--co--nz] Web: http://valley.150m.com Date: 8/October/2002 Version: 1.1.0 Purpose: {} Category: [util 1] Acknowledgements: ["Maarten Koopmans"] ] Hide: func [Block [block!]] [ do Block return ; Deliberately returns unset! value. ] RSP: function [Text [string!]] [RSP] [ RSP: make string! length? Text use [StringScript ScriptString Script String] [ StringScript: "<%" ScriptString: "%>" parse/all Text [ any [ end break | StringScript copy Script to ScriptString ScriptString (append RSP Script) | copy String [to StringScript | to end] (append RSP mold String) ] ] ] form replace/all reduce load RSP unset! "" ] Andrew Martin ICQ: 26227169 http://valley.150m.com/

 [5/6] from: doug:vos:eds at: 8-Oct-2002 8:54


Can you provide some examples of how you use it?

 [6/6] from: al:bri:xtra at: 9-Oct-2002 16:31


Doug wrote:
> Can you provide some examples of how you use it?
At the moment, I'm not using it. :( I just wrote it to show that it's possible to do what pekr needs without having to do the excess work that pekr seems to want to do. :) Here's an example .rsp: <html> <head> <title>{{Test}</title> </head> <body> <%hide [ Data: [ "L1 Foo Stuff" "L1 Bar Stuff" "L2 Foo Stuff" "L2 Bar Stuff" ] ]%> <h1>Test</h1> <% random/seed now either random true [ %> Have a <b>nice</b> day! <% ] [ %> Have a <b>lousy</b> day! <% ] %><br/> The date and time now is: <% now %>.<br/> <table> <tr><th>Foo</th><th>Bar</th></tr> <%map Data func [Foo Bar] [reform [%><tr><td><%Foo%></td><td><%Bar%></td></tr><%]]%> </table> </body> </html> And here's my test script: write %Test.html probe RSP read %Test.rsp browse %Test.html halt Using it with a web server would be specific to that web server. On Xitami, I'd put a line at the top of the .rsp file, like this: #! C:\Rebol\Base\Rebol.exe -cs "RSP Test.rsp" Andrew Martin ICQ: 26227169 http://valley.150m.com/