2019-10-18 09:05:04 -04:00
|
|
|
! Copyright (C) 2006 Chris Double. All Rights Reserved.
|
|
|
|
|
! See http://factorcode.org/license.txt for BSD license.
|
|
|
|
|
!
|
2019-10-18 09:05:06 -04:00
|
|
|
USING: kernel furnace xml xml-writer io httpd sequences
|
2019-10-18 09:05:04 -04:00
|
|
|
namespaces file-responder parser-combinators lazy-lists
|
2019-10-18 09:05:06 -04:00
|
|
|
fjsc http-client errors ;
|
|
|
|
|
IN: furnace:fjsc
|
2019-10-18 09:05:04 -04:00
|
|
|
|
|
|
|
|
: compile ( code -- )
|
2019-10-18 09:05:06 -04:00
|
|
|
#! Compile the factor code as a string, outputting the http
|
2019-10-18 09:05:04 -04:00
|
|
|
#! response containing the javascript.
|
|
|
|
|
serving-text
|
|
|
|
|
'expression' parse car parse-result-parsed fjsc-compile
|
2019-10-18 09:05:06 -04:00
|
|
|
write flush ;
|
2019-10-18 09:05:04 -04:00
|
|
|
|
|
|
|
|
! The 'compile' action results in an URL that looks like
|
|
|
|
|
! 'responder/fjsc/compile'. It takes one query or post
|
|
|
|
|
! parameter called 'code'. It calls the 'compile' word
|
|
|
|
|
! passing the parameter to it on the stack.
|
|
|
|
|
\ compile {
|
|
|
|
|
{ "code" v-required }
|
|
|
|
|
} define-action
|
|
|
|
|
|
2019-10-18 09:05:06 -04:00
|
|
|
: compile-url ( url -- )
|
|
|
|
|
#! Compile the factor code at the given url, return the javascript.
|
|
|
|
|
dup "http:" head? [ "Unable to access remote sites." throw ] when
|
|
|
|
|
"http://" host rot 3append http-get 2nip compile "();" write flush ;
|
|
|
|
|
|
|
|
|
|
\ compile-url {
|
|
|
|
|
{ "url" v-required }
|
|
|
|
|
} define-action
|
|
|
|
|
|
2019-10-18 09:05:04 -04:00
|
|
|
: repl ( -- )
|
|
|
|
|
#! The main 'repl' page.
|
2019-10-18 09:05:06 -04:00
|
|
|
f "repl" "head" render-page* ;
|
2019-10-18 09:05:04 -04:00
|
|
|
|
|
|
|
|
! An action called 'repl'
|
|
|
|
|
\ repl { } define-action
|
|
|
|
|
|
|
|
|
|
! Create the web app, providing access
|
|
|
|
|
! under '/responder/fjsc' which calls the
|
|
|
|
|
! 'repl' action.
|
|
|
|
|
"fjsc" "repl" "apps/furnace-fjsc" web-app
|
|
|
|
|
|
|
|
|
|
! An URL to the javascript resource files used by
|
|
|
|
|
! the 'fjsc' responder.
|
|
|
|
|
"fjsc-resources" [
|
|
|
|
|
[
|
|
|
|
|
"libs/fjsc/resources/" resource-path "doc-root" set
|
|
|
|
|
file-responder
|
|
|
|
|
] with-scope
|
|
|
|
|
] add-simple-responder
|
2019-10-18 09:05:06 -04:00
|
|
|
|
|
|
|
|
! An URL to the resource files used by
|
|
|
|
|
! 'termlib'.
|
|
|
|
|
"fjsc-repl-resources" [
|
|
|
|
|
[
|
|
|
|
|
"apps/furnace-fjsc/resources/" resource-path "doc-root" set
|
|
|
|
|
file-responder
|
|
|
|
|
] with-scope
|
|
|
|
|
] add-simple-responder
|