Merge branch 'master' of git://factorcode.org/git/factor
commit
ee400a4955
|
@ -132,3 +132,6 @@ link-no-follow? off
|
|||
[ "<p>asdf\n<ul><li>lol</li>\n<li>haha</li></ul></p>" ] [ "asdf\n-lol\n-haha" convert-farkup ] unit-test
|
||||
|
||||
[ "<p>asdf</p><ul><li>lol</li>\n<li>haha</li></ul>" ] [ "asdf\n\n-lol\n-haha" convert-farkup ] unit-test
|
||||
|
||||
[ "<hr/>" ] [ "___" convert-farkup ] unit-test
|
||||
[ "<hr/>\n" ] [ "___\n" convert-farkup ] unit-test
|
||||
|
|
|
@ -28,6 +28,7 @@ TUPLE: table-row child ;
|
|||
TUPLE: link href text ;
|
||||
TUPLE: image href text ;
|
||||
TUPLE: code mode string ;
|
||||
TUPLE: line ;
|
||||
|
||||
: absolute-url? ( string -- ? )
|
||||
{ "http://" "https://" "ftp://" } [ head? ] with contains? ;
|
||||
|
@ -123,6 +124,9 @@ unordered-list = ((unordered-list-item nl)+ unordered-list-item? | unordered-lis
|
|||
|
||||
list = ordered-list | unordered-list
|
||||
|
||||
line = '___'
|
||||
=> [[ drop line new ]]
|
||||
|
||||
code = '[' (!('{' | nl | '[').)+ '{' (!("}]").)+ "}]"
|
||||
=> [[ [ second >string ] [ fourth >string ] bi code boa ]]
|
||||
|
||||
|
@ -131,7 +135,7 @@ simple-code
|
|||
=> [[ second f swap code boa ]]
|
||||
|
||||
stand-alone
|
||||
= (code | simple-code | heading | list | table | paragraph | nl)*
|
||||
= (line | code | simple-code | heading | list | table | paragraph | nl)*
|
||||
;EBNF
|
||||
|
||||
|
||||
|
@ -193,6 +197,7 @@ M: paragraph (write-farkup) [ child>> (write-farkup) ] "p" in-tag. ;
|
|||
M: link (write-farkup) [ href>> ] [ text>> ] bi write-link ;
|
||||
M: image (write-farkup) [ href>> ] [ text>> ] bi write-image-link ;
|
||||
M: code (write-farkup) [ string>> ] [ mode>> ] bi render-code ;
|
||||
M: line (write-farkup) drop <hr/> ;
|
||||
M: table-row (write-farkup) ( obj -- )
|
||||
child>> [ [ [ (write-farkup) ] "td" in-tag. ] each ] "tr" in-tag. ;
|
||||
M: table (write-farkup) [ child>> (write-farkup) ] "table" in-tag. ;
|
||||
|
|
|
@ -11,21 +11,24 @@ furnace.auth.providers
|
|||
furnace.auth.login.permits ;
|
||||
IN: furnace.alloy
|
||||
|
||||
: <alloy> ( responder db params -- responder' )
|
||||
'[
|
||||
<asides>
|
||||
<conversations>
|
||||
<sessions>
|
||||
_ _ <db-persistence>
|
||||
<check-form-submissions>
|
||||
] call ;
|
||||
|
||||
: state-classes { session aside conversation permit } ; inline
|
||||
|
||||
: init-furnace-tables ( -- )
|
||||
state-classes ensure-tables
|
||||
user ensure-table ;
|
||||
|
||||
: <alloy> ( responder db params -- responder' )
|
||||
[ [ init-furnace-tables ] with-db ]
|
||||
[
|
||||
[
|
||||
<asides>
|
||||
<conversations>
|
||||
<sessions>
|
||||
] 2dip
|
||||
<db-persistence>
|
||||
<check-form-submissions>
|
||||
] 2bi ;
|
||||
|
||||
: start-expiring ( db params -- )
|
||||
'[
|
||||
_ _ [ state-classes [ expire-state ] each ] with-db
|
||||
|
|
|
@ -14,4 +14,4 @@ M: referrer-check call-responder*
|
|||
[ 2drop 403 "Bad referrer" <trivial-response> ] if ;
|
||||
|
||||
: <check-form-submissions> ( responder -- responder' )
|
||||
[ post-request? [ same-host? ] [ drop f ] if ] <referrer-check> ;
|
||||
[ post-request? [ same-host? ] [ drop t ] if ] <referrer-check> ;
|
||||
|
|
|
@ -149,6 +149,7 @@ SYMBOL: html
|
|||
[
|
||||
"input"
|
||||
"br"
|
||||
"hr"
|
||||
"link"
|
||||
"img"
|
||||
] [ define-open-html-word ] each
|
||||
|
|
|
@ -0,0 +1,44 @@
|
|||
! Copyright (C) 2008 Slava Pestov.
|
||||
! See http://factorcode.org/license.txt for BSD license.
|
||||
USING: furnace.actions furnace.redirection
|
||||
http.server.dispatchers html.forms validators urls accessors
|
||||
math ;
|
||||
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" "x" value "y" value + "z" set-query-param
|
||||
<redirect>
|
||||
] >>submit ;
|
||||
|
||||
: <calculator> ( -- responder )
|
||||
calculator new-dispatcher
|
||||
<calculator-action> >>default ;
|
||||
|
||||
! Deployment example
|
||||
USING: db.sqlite furnace.alloy namespaces http.server ;
|
||||
|
||||
: calculator-db ( -- params db ) "calculator.db" sqlite-db ;
|
||||
|
||||
: run-calculator ( -- )
|
||||
<calculator>
|
||||
calculator-db <alloy>
|
||||
main-responder set-global
|
||||
8080 httpd ;
|
||||
|
||||
MAIN: run-calculator
|
|
@ -0,0 +1,28 @@
|
|||
<?xml version='1.0' ?>
|
||||
|
||||
<t:chloe xmlns:t="http://factorcode.org/chloe/1.0">
|
||||
|
||||
<head> <title>Calculator</title> </head>
|
||||
|
||||
<body>
|
||||
<h1>Calculator</h1>
|
||||
|
||||
<t:form t:action="$calculator">
|
||||
|
||||
<table>
|
||||
<tr><td>First value:</td><td> <t:field t:name="x" /> </td></tr>
|
||||
<tr><td>Second value:</td><td> <t:field t:name="y" /> </td></tr>
|
||||
</table>
|
||||
|
||||
<input type="SUBMIT" value="Compute" />
|
||||
|
||||
<t:if t:value="z">
|
||||
<br/>
|
||||
|
||||
Result: <t:label t:name="z" />
|
||||
</t:if>
|
||||
|
||||
</t:form>
|
||||
</body>
|
||||
|
||||
</t:chloe>
|
|
@ -2,8 +2,7 @@
|
|||
! See http://factorcode.org/license.txt for BSD license.
|
||||
USING: math kernel accessors http.server http.server.dispatchers
|
||||
furnace furnace.actions furnace.sessions furnace.redirection
|
||||
html.components html.forms html.templates.chloe
|
||||
fry urls ;
|
||||
html.components html.forms fry urls ;
|
||||
IN: webapps.counter
|
||||
|
||||
SYMBOL: count
|
||||
|
@ -32,17 +31,13 @@ M: counter-app init-session* drop 0 count sset ;
|
|||
<sessions> ;
|
||||
|
||||
! Deployment example
|
||||
USING: db.sqlite db.tuples db furnace.db namespaces ;
|
||||
USING: db.sqlite furnace.alloy namespaces ;
|
||||
|
||||
: counter-db ( -- params db ) "counter.db" sqlite-db ;
|
||||
|
||||
: init-counter-db ( -- )
|
||||
counter-db [ session ensure-table ] with-db ;
|
||||
|
||||
: run-counter ( -- )
|
||||
init-counter-db
|
||||
<counter-app>
|
||||
counter-db <db-persistence>
|
||||
counter-db <alloy>
|
||||
main-responder set-global
|
||||
8080 httpd ;
|
||||
|
||||
|
|
|
@ -19,7 +19,7 @@ db.types db.tuples lcs farkup urls ;
|
|||
IN: webapps.wiki
|
||||
|
||||
: wiki-url ( rest path -- url )
|
||||
[ "$wiki/" % % "/" % % ] "" make
|
||||
[ "$wiki/" % % "/" % present % ] "" make
|
||||
<url> swap >>path ;
|
||||
|
||||
: view-url ( title -- url ) "view" wiki-url ;
|
||||
|
|
Loading…
Reference in New Issue