1 ! Copyright (C) 2006 Chris Double. All Rights Reserved.
2 ! See http://factorcode.org/license.txt for BSD license.
5 USING: kernel html furnace xml io httpd sequences
6 namespaces file-responder parser-combinators lazy-lists
10 #! given a path to a javascript file, output the
11 #! script tag that references it.
12 <script "text/javascript" =type =src script> </script> ;
14 : fjsc-page ( scripts title quot -- )
15 #! Display a web page importing the given script
16 #! tags and using the title. The body of the page
17 #! is generated by calling the quotation.
20 <html " xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en\" lang=\"en\"" write-html html>
22 <title> write </title>
30 : fjsc-render ( template title -- )
31 #! Render the fjsc page importing the required
34 "/responder/fjsc-resources/jquery.js"
35 "/responder/fjsc-resources/bootstrap.js"
38 f swap render-template
43 #! Compile the facor code as a string, outputting the http
44 #! response containing the javascript.
46 'expression' parse car parse-result-parsed fjsc-compile
49 ! The 'compile' action results in an URL that looks like
50 ! 'responder/fjsc/compile'. It takes one query or post
51 ! parameter called 'code'. It calls the 'compile' word
52 ! passing the parameter to it on the stack.
58 #! The main 'repl' page.
59 f "repl" "Factor to Javascript REPL" fjsc-render ;
61 ! An action called 'repl'
62 \ repl { } define-action
64 ! Create the web app, providing access
65 ! under '/responder/fjsc' which calls the
67 "fjsc" "repl" "apps/furnace-fjsc" web-app
69 ! An URL to the javascript resource files used by
70 ! the 'fjsc' responder.
73 "libs/fjsc/resources/" resource-path "doc-root" set
76 ] add-simple-responder