2 Javascript
The Javascript language in Mirrors allows the programatic assembly of syntactically valid Javascript. The language uses the AST structures and pretty printing libraries from Dave Herman’s javascript.plt package as its underlying representation.
Javascript syntax describes the syntax for creating blocks of Javascript and Rendering Javascript and sending Javascript responses describes how to send Javascript responses in the PLT web server.
2.1 Javascript syntax
(require (planet untyped/mirrors/javascript/syntax)) |
Mirrors provides a set of macros for rendering blocks of Javascript, intended to replace Jay McCarthy’s javascript.plt (which is no longer in development). Almost no checking is performed to make sure the Javascript code makes sense.
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Builds a Javascript declaration, statement or expression. Unquote can be used to insert Scheme expressions resulting in Boolean, numeric, string, symbol, bytes or URL values.
Syntactic shorthand for:
(if boolean-expr |
(js js-stmt ) |
(js)) |
Only works at the statement level.
Examples: | ||
| ||
"alert(\"This alert will be shown....\");" | ||
| ||
"" |
val : any |
Returns #t if val is a Javascript declaration, statement or expression.
val : any |
Returns #t if val is a Javascript declaration.
val : any |
Returns #t if val is a Javascript statement.
val : any |
Returns #t if val is a Javascript expression.
2.2 Rendering Javascript and sending Javascript responses
2.2.1 Rendering Javascript in string form
val : javascript-statement? |
Renders a Javascript statement as a compact string with no line breaks or indentation.
val : javascript-statement? |
Renders a Javascript statement as a formatted string with line breaks and indentation.
2.2.2 Sending HTTP responses with Javascript content
| ||||||||||||||||||||||||||||||||||||||||||
code : integer = 200 | ||||||||||||||||||||||||||||||||||||||||||
message : string = "OK" | ||||||||||||||||||||||||||||||||||||||||||
seconds : integer = (current-seconds) | ||||||||||||||||||||||||||||||||||||||||||
| ||||||||||||||||||||||||||||||||||||||||||
headers : (alistof symbol string) = no-cache-http-headers | ||||||||||||||||||||||||||||||||||||||||||
content : javascript-statement |
Takes a js statement and wraps it in an HTTP response object that can be used with the PLT web server (including procedures such as send/suspend and send/suspend/dispatch). The keyword arguments correspond to the first five arguments of make-response/full.