factor/extra/webapps/calculator/calculator.factor

46 lines
1.1 KiB
Factor
Raw Permalink Normal View History

2009-01-12 17:17:58 -05:00
! Copyright (C) 2008, 2009 Slava Pestov.
2008-09-23 04:35:09 -04:00
! See http://factorcode.org/license.txt for BSD license.
2016-12-22 08:50:31 -05:00
USING: accessors furnace.actions furnace.alloy
furnace.redirection html.forms http.server
http.server.dispatchers kernel math namespaces urls validators
webapps.utils ;
2008-09-23 04:35:09 -04:00
IN: webapps.calculator
TUPLE: calculator < dispatcher ;
: <calculator-action> ( -- action )
<page-action>
[
{ { "z" [ [ v-number ] v-optional ] } } validate-params
] >>init
{ calculator "calculator" } >>template
[
{
{ "x" [ v-number ] }
{ "y" [ v-number ] }
} validate-params
URL" $calculator" clone "x" value "y" value + "z" set-query-param
2008-09-23 04:35:09 -04:00
<redirect>
] >>submit ;
: <calculator> ( -- responder )
calculator new-dispatcher
<calculator-action> >>default ;
! Deployment example
: calculator-db ( -- db ) "calculator.db" <temp-sqlite-db> ;
2008-09-23 04:35:09 -04:00
: <calculator-app> ( -- dispatcher )
<calculator> calculator-db <alloy> ;
2008-09-23 04:35:09 -04:00
! Calculator runs at port 8081 and 8431
: run-calculator ( -- )
<calculator-app> main-responder set-global
run-test-httpd ;
2008-09-23 04:35:09 -04:00
MAIN: run-calculator