RSP Text Preprocessor
Short for REBOL Server Pages. Originally an all-in-one REBOL CGI framework, this iteration abstracts only the text pre-processor. This closely resembles RSP as used in QuarterMaster.
RSP Basics
There are three forms of markup associated with RSP. First there is the output directive:
<%= title %>
This replaces the mark with the value of ‘title. Then the flow directive:
<% loop 3 [ %>Ha! <% ] %>
There is no output from a flow block, and REBOL block types do not have to be terminated in the same flow block (though they still have to be terminated).
And finally, the build-tag directive.
<%: a href http://www.rebol.com/ %>
Put it all together and you can start to build some interesting pages:
<ul><%
sites: [
"Yahoo" http://yahoo.com
"Google" http://google.com
"Apple" http://apple.com
]
foreach [site link] sites [
%><li><%: a href (link) %><%= site %></a></li><%
]
%></ul>
Additionally, you can comment your code like so:
<%; This is a comment %>
(note that in QM, ‘build-tag has different syntax - see QM documentation)
Script Usage
do http://reb4.me/r/rsp
There are three functions included in this module: ‘load-rsp, ‘render and ‘render-each
‘load-rsp
This is the low-level parser that turns the RSP string into a function:
build-page: load-rsp {<h1><%= title %></h1>}
page1: build-page context [title: "Title 1"]
page2: build-page context [title: "Title 2"]
‘render
This function is a simple wrapper for ‘load-rsp:
render {<%= 1 + 1 %>}
render/with {<%= title %>} context [title: "Jaws"]
‘render-each
Works much like ‘foreach and produces a single string output:
render-each [term definition] dictionary {
<dt><%= term %></dt>
<dd><%= definition %></dd>
}
Both ‘render and ‘render-each take file! and url! arguments in addition to string!
Binding Local Values
When loading an RSP string, it is loaded into the global namespace. You need to explicitly pass a set of local words or an object to avoid having to work globally. With ‘render and ‘render-each, this can be passed using the /with refinement.