From 8abda5c6534bc5810bd29d4f96da70d6f269446f Mon Sep 17 00:00:00 2001 From: Slava Pestov Date: Mon, 22 Sep 2008 23:45:16 -0500 Subject: [PATCH 1/7] Fix RSS feed links --- extra/webapps/wiki/wiki.factor | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extra/webapps/wiki/wiki.factor b/extra/webapps/wiki/wiki.factor index 420d71d26b..16c51a876b 100644 --- a/extra/webapps/wiki/wiki.factor +++ b/extra/webapps/wiki/wiki.factor @@ -19,7 +19,7 @@ db.types db.tuples lcs farkup urls ; IN: webapps.wiki : wiki-url ( rest path -- url ) - [ "$wiki/" % % "/" % % ] "" make + [ "$wiki/" % % "/" % present % ] "" make swap >>path ; : view-url ( title -- url ) "view" wiki-url ; From cbee5b39c2128518b05b7b94392b11fed260cfee Mon Sep 17 00:00:00 2001 From: Doug Coleman Date: Tue, 23 Sep 2008 01:27:39 -0500 Subject: [PATCH 2/7] farkup: add horizontal lines as ___ (3 underlines) --- basis/farkup/farkup-tests.factor | 3 +++ basis/farkup/farkup.factor | 7 ++++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/basis/farkup/farkup-tests.factor b/basis/farkup/farkup-tests.factor index 5237774b04..42979007e8 100644 --- a/basis/farkup/farkup-tests.factor +++ b/basis/farkup/farkup-tests.factor @@ -132,3 +132,6 @@ link-no-follow? off [ "

asdf\n

  • lol
  • \n
  • haha

" ] [ "asdf\n-lol\n-haha" convert-farkup ] unit-test [ "

asdf

  • lol
  • \n
  • haha
" ] [ "asdf\n\n-lol\n-haha" convert-farkup ] unit-test + +[ "
" ] [ "___" convert-farkup ] unit-test +[ "
\n" ] [ "___\n" convert-farkup ] unit-test diff --git a/basis/farkup/farkup.factor b/basis/farkup/farkup.factor index 495e6d9b57..f482f8beaa 100644 --- a/basis/farkup/farkup.factor +++ b/basis/farkup/farkup.factor @@ -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
; 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. ; From 5037a841d952e828a71fcf8a5785190ffb6afc23 Mon Sep 17 00:00:00 2001 From: Doug Coleman Date: Tue, 23 Sep 2008 01:50:34 -0500 Subject: [PATCH 3/7]
, it's what farkup craves --- basis/html/elements/elements.factor | 1 + 1 file changed, 1 insertion(+) diff --git a/basis/html/elements/elements.factor b/basis/html/elements/elements.factor index ad75b58df3..ced2f700dc 100644 --- a/basis/html/elements/elements.factor +++ b/basis/html/elements/elements.factor @@ -149,6 +149,7 @@ SYMBOL: html [ "input" "br" + "hr" "link" "img" ] [ define-open-html-word ] each From 216064ab50e659ba051af334d7f7667fa5def90c Mon Sep 17 00:00:00 2001 From: Slava Pestov Date: Tue, 23 Sep 2008 03:34:35 -0500 Subject: [PATCH 4/7] Fix referrer bug --- basis/furnace/referrer/referrer.factor | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/basis/furnace/referrer/referrer.factor b/basis/furnace/referrer/referrer.factor index b7a3df4b53..003028ab1e 100644 --- a/basis/furnace/referrer/referrer.factor +++ b/basis/furnace/referrer/referrer.factor @@ -14,4 +14,4 @@ M: referrer-check call-responder* [ 2drop 403 "Bad referrer" ] if ; : ( responder -- responder' ) - [ post-request? [ same-host? ] [ drop f ] if ] ; + [ post-request? [ same-host? ] [ drop t ] if ] ; From b890c8374445f767b974377c9db748a1213dbce7 Mon Sep 17 00:00:00 2001 From: Slava Pestov Date: Tue, 23 Sep 2008 03:34:48 -0500 Subject: [PATCH 5/7] Make alloy easier to use by creating the database tables for you --- basis/furnace/alloy/alloy.factor | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/basis/furnace/alloy/alloy.factor b/basis/furnace/alloy/alloy.factor index 684c4aef4c..decee690a3 100644 --- a/basis/furnace/alloy/alloy.factor +++ b/basis/furnace/alloy/alloy.factor @@ -11,21 +11,24 @@ furnace.auth.providers furnace.auth.login.permits ; IN: furnace.alloy -: ( responder db params -- responder' ) - '[ - - - - _ _ - - ] call ; - : state-classes { session aside conversation permit } ; inline : init-furnace-tables ( -- ) state-classes ensure-tables user ensure-table ; +: ( responder db params -- responder' ) + [ [ init-furnace-tables ] with-db ] + [ + [ + + + + ] 2dip + + + ] 2bi ; + : start-expiring ( db params -- ) '[ _ _ [ state-classes [ expire-state ] each ] with-db From 47a74f05454b9e081fd9d316b798f069ef3603a9 Mon Sep 17 00:00:00 2001 From: Slava Pestov Date: Tue, 23 Sep 2008 03:35:01 -0500 Subject: [PATCH 6/7] Update webapps.counter for alloy change --- extra/webapps/counter/counter.factor | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/extra/webapps/counter/counter.factor b/extra/webapps/counter/counter.factor index a0ee3a1b29..f49d8f008e 100644 --- a/extra/webapps/counter/counter.factor +++ b/extra/webapps/counter/counter.factor @@ -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 ; ; ! 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-db + counter-db main-responder set-global 8080 httpd ; From 88c59b16399eccb08d63a6f35a3f63233ae4de12 Mon Sep 17 00:00:00 2001 From: Slava Pestov Date: Tue, 23 Sep 2008 03:35:09 -0500 Subject: [PATCH 7/7] New webapps.calculator demo --- extra/webapps/calculator/calculator.factor | 44 ++++++++++++++++++++++ extra/webapps/calculator/calculator.xml | 28 ++++++++++++++ 2 files changed, 72 insertions(+) create mode 100644 extra/webapps/calculator/calculator.factor create mode 100644 extra/webapps/calculator/calculator.xml diff --git a/extra/webapps/calculator/calculator.factor b/extra/webapps/calculator/calculator.factor new file mode 100644 index 0000000000..f1416fb02d --- /dev/null +++ b/extra/webapps/calculator/calculator.factor @@ -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 ; + +: ( -- 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 + + ] >>submit ; + +: ( -- responder ) + calculator new-dispatcher + >>default ; + +! Deployment example +USING: db.sqlite furnace.alloy namespaces http.server ; + +: calculator-db ( -- params db ) "calculator.db" sqlite-db ; + +: run-calculator ( -- ) + + calculator-db + main-responder set-global + 8080 httpd ; + +MAIN: run-calculator diff --git a/extra/webapps/calculator/calculator.xml b/extra/webapps/calculator/calculator.xml new file mode 100644 index 0000000000..ed8e60d89a --- /dev/null +++ b/extra/webapps/calculator/calculator.xml @@ -0,0 +1,28 @@ + + + + + Calculator + + +

Calculator

+ + + + + + +
First value:
Second value:
+ + + + +
+ + Result: +
+ +
+ + +