]> gitweb.factorcode.org Git - factor.git/commitdiff
Merge branch 'master' of git://factorcode.org/git/factor
authorSlava Pestov <slava@slava-pestovs-macbook-pro.local>
Thu, 12 Jun 2008 23:59:25 +0000 (18:59 -0500)
committerSlava Pestov <slava@slava-pestovs-macbook-pro.local>
Thu, 12 Jun 2008 23:59:25 +0000 (18:59 -0500)
22 files changed:
core/grouping/grouping-tests.factor
core/grouping/grouping.factor
core/parser/parser-docs.factor
extra/furnace/furnace.factor
extra/http/http-tests.factor
extra/http/http.factor
extra/http/server/server.factor
extra/io/pools/pools.factor
extra/io/server/server.factor
extra/webapps/blogs/blogs.factor
extra/webapps/blogs/edit-post.xml
extra/webapps/blogs/list-posts.xml
extra/webapps/blogs/user-posts.xml
extra/webapps/blogs/view-post.xml
extra/webapps/wiki/articles.xml
extra/webapps/wiki/changes.xml
extra/webapps/wiki/diff.xml
extra/webapps/wiki/page-common.xml
extra/webapps/wiki/revisions.xml
extra/webapps/wiki/user-edits.xml
extra/webapps/wiki/view.xml
extra/webapps/wiki/wiki.factor

index dcf62e1117b9289b09ae12a73f33dcad7047c586..dc3d970fbf5dddd3b25c0f8758b6f8beb86cee10 100644 (file)
@@ -10,3 +10,5 @@ IN: grouping.tests
     2 over set-length
     >array
 ] unit-test
+
+[ { { 1 2 } { 2 3 } } ] [ { 1 2 3 } 2 <sliced-clumps> [ >array ] map ] unit-test
index c12d43160c82278dba5add669a12020883d115ac..caf46e5480f8671d8d29bc62bac4c05cf33bca5d 100644 (file)
@@ -56,7 +56,7 @@ M: clumps set-length
 M: clumps group@
     [ n>> over + ] [ seq>> ] bi ;
 
-TUPLE: sliced-clumps < groups ;
+TUPLE: sliced-clumps < clumps ;
 
 : <sliced-clumps> ( seq n -- clumps )
     sliced-clumps new-groups ; inline
index 1dc47432d355ecbd6c76430674df74d0fbe77cd4..2ec9f2de544aa86b8bc065cbac5b87ebf32e06d5 100755 (executable)
@@ -117,14 +117,18 @@ $nl
 { $subsection parse-tokens } ;
 
 ARTICLE: "parsing-words" "Parsing words"
-"The Factor parser is follows a simple recursive-descent design. The parser reads successive tokens from the input; if the token identifies a number or an ordinary word, it is added to an accumulator vector. Otherwise if the token identifies a parsing word, the parsing word is executed immediately."
+"The Factor parser follows a simple recursive-descent design. The parser reads successive tokens from the input; if the token identifies a number or an ordinary word, it is added to an accumulator vector. Otherwise if the token identifies a parsing word, the parsing word is executed immediately."
 $nl
 "Parsing words are marked by suffixing the definition with a " { $link POSTPONE: parsing } " declaration. Here is the simplest possible parsing word; it prints a greeting at parse time:"
 { $code ": hello \"Hello world\" print ; parsing" }
-"Parsing words must have stack effect " { $snippet "( accum -- accum )" } ", where " { $snippet "accum" } " is the accumulator vector supplied by the parser. Parsing words can read input, add word definitions to the dictionary, and do anything an ordinary word can."
+"Parsing words must not pop or push items from the stack; however, they are permitted to access the accumulator vector supplied by the parser at the top of the stack. That is, parsing words must have stack effect " { $snippet "( accum -- accum )" } ", where " { $snippet "accum" } " is the accumulator vector supplied by the parser."
+$nl
+"Parsing words can read input, add word definitions to the dictionary, and do anything an ordinary word can."
+$nl
+"Because of the stack restriction, parsing words cannot pass data to other words by leaving values on the stack; instead, use " { $link parsed } " to add the data to the parse tree so that it can be evaluated later."
 $nl
 "Parsing words cannot be called from the same source file where they are defined, because new definitions are only compiled at the end of the source file. An attempt to use a parsing word in its own source file raises an error:"
-{ $link staging-violation }
+{ $subsection staging-violation }
 "Tools for implementing parsing words:"
 { $subsection "reading-ahead" }
 { $subsection "parsing-word-nest" }
index 99ccf33eec83b555c35c53de6e5f220557399a76..6ddd84a2545478012a3f524f1b81741e49029d6e 100644 (file)
@@ -97,15 +97,21 @@ SYMBOL: exit-continuation
     dup empty?
     [ drop f ] [ "," split [ dup value ] H{ } map>assoc ] if ;
 
-CHLOE: atom
-    [ children>string ]
-    [ "href" required-attr ]
-    [ "query" optional-attr parse-query-attr ] tri
-    <url>
-        swap >>query
-        swap >>path
-    adjust-url relative-to-request
-    add-atom-feed ;
+: a-url-path ( tag -- string )
+    [ "href" required-attr ] [ "rest" optional-attr value ] bi
+    [ [ "/" ?tail drop "/" ] dip present 3append ] when* ;
+
+: a-url ( tag -- url )
+    dup "value" optional-attr [ ] [
+        <url>
+            swap
+            [ a-url-path >>path ]
+            [ "query" optional-attr parse-query-attr >>query ]
+            bi
+    ] ?if
+    adjust-url relative-to-request ;
+
+CHLOE: atom [ children>string ] [ a-url ] bi add-atom-feed ;
 
 CHLOE: write-atom drop write-atom-feeds ;
 
@@ -114,23 +120,11 @@ GENERIC: link-attr ( tag responder -- )
 M: object link-attr 2drop ;
 
 : link-attrs ( tag -- )
+    #! Side-effects current namespace.
     '[ , _ link-attr ] each-responder ;
 
 : a-start-tag ( tag -- )
-    [
-        <a
-            dup link-attrs
-            dup "value" optional-attr [ value f ] [
-                [ "href" required-attr ]
-                [ "query" optional-attr parse-query-attr ]
-                bi
-            ] ?if
-            <url>
-                swap >>query
-                swap >>path
-            adjust-url relative-to-request =href
-        a>
-    ] with-scope ;
+    [ <a [ link-attrs ] [ a-url =href ] bi a> ] with-scope ;
 
 CHLOE: a
     [ a-start-tag ]
@@ -158,11 +152,12 @@ CHLOE: a
     [
         [
             <form
-                "POST" =method
-                [ link-attrs ]
-                [ "action" required-attr resolve-base-path =action ]
-                [ tag-attrs non-chloe-attrs-only print-attrs ]
-                tri
+                {
+                    [ link-attrs ]
+                    [ "method" optional-attr "post" or =method ]
+                    [ "action" required-attr resolve-base-path =action ]
+                    [ tag-attrs non-chloe-attrs-only print-attrs ]
+                } cleave
             form>
         ]
         [ form-magic ] bi
index 81ada558f3f4a88bdb6309eafdf1ef6f0d777c2c..aa11dd67987a87196677c9b4cacd993ea11753d3 100755 (executable)
@@ -7,7 +7,7 @@ IN: http.tests
 : lf>crlf "\n" split "\r\n" join ;
 
 STRING: read-request-test-1
-POST http://foo/bar HTTP/1.1
+POST /bar HTTP/1.1
 Some-Header: 1
 Some-Header: 2
 Content-Length: 4
@@ -18,7 +18,7 @@ blah
 
 [
     TUPLE{ request
-        url: TUPLE{ url protocol: "http" port: 80 path: "/bar" }
+        url: TUPLE{ url path: "/bar" }
         method: "POST"
         version: "1.1"
         header: H{ { "some-header" "1; 2" } { "content-length" "4" } { "content-type" "application/octet-stream" } }
@@ -49,14 +49,14 @@ read-request-test-1' 1array [
 ] unit-test
 
 STRING: read-request-test-2
-HEAD  http://foo/bar   HTTP/1.1
+HEAD  /bar   HTTP/1.1
 Host: www.sex.com
 
 ;
 
 [
     TUPLE{ request
-        url: TUPLE{ url protocol: "http" port: 80 host: "www.sex.com" path: "/bar" }
+        url: TUPLE{ url host: "www.sex.com" path: "/bar" }
         method: "HEAD"
         version: "1.1"
         header: H{ { "host" "www.sex.com" } }
index d7fc1b766e6cb740041d2c1339a578101ce5775c..521c18c7033f22f1b72b50a09588e9bb77e3cf5a 100755 (executable)
@@ -6,8 +6,7 @@ assocs sequences splitting sorting sets debugger
 strings vectors hashtables quotations arrays byte-arrays
 math.parser calendar calendar.format present
 
-io io.server io.sockets.secure
-io.encodings.iana io.encodings.binary io.encodings.8-bit
+io io.encodings.iana io.encodings.binary io.encodings.8-bit
 
 unicode.case unicode.categories qualified
 
@@ -142,7 +141,6 @@ cookies ;
     request new
         "1.1" >>version
         <url>
-            "http" >>protocol
             H{ } clone >>query
         >>url
         H{ } clone >>header
@@ -202,7 +200,6 @@ TUPLE: post-data raw content content-type ;
 : extract-host ( request -- request )
     [ ] [ url>> ] [ "host" header parse-host ] tri
     [ >>host ] [ >>port ] bi*
-    ensure-port
     drop ;
 
 : extract-cookies ( request -- request )
@@ -214,9 +211,6 @@ TUPLE: post-data raw content content-type ;
 : parse-content-type ( content-type -- type encoding )
     ";" split1 parse-content-type-attributes "charset" swap at ;
 
-: detect-protocol ( request -- request )
-    dup url>> remote-address get secure? "https" "http" ? >>protocol drop ;
-
 : read-request ( -- request )
     <request>
     read-method
@@ -224,7 +218,6 @@ TUPLE: post-data raw content content-type ;
     read-request-version
     read-request-header
     read-post-data
-    detect-protocol
     extract-host
     extract-cookies ;
 
index 792757b1828e0e817390449dcdd757e3ba1ec86e..642e9f77f09dba8f703388d01349a0bcc5ad1d4c 100755 (executable)
@@ -2,16 +2,18 @@
 ! See http://factorcode.org/license.txt for BSD license.
 USING: kernel accessors sequences arrays namespaces splitting
 vocabs.loader destructors assocs debugger continuations
-tools.vocabs math
+combinators tools.vocabs math
 io
 io.server
+io.sockets
+io.sockets.secure
 io.encodings
 io.encodings.utf8
 io.encodings.ascii
 io.encodings.binary
 io.streams.limited
 io.timeouts
-fry logging calendar
+fry logging calendar urls
 http
 http.server.responses
 html.elements
@@ -88,12 +90,26 @@ LOG: httpd-hit NOTICE
 : dispatch-request ( request -- response )
     url>> path>> split-path main-responder get call-responder ;
 
+: prepare-request ( request -- request )
+    [
+        local-address get
+        [ secure? "https" "http" ? >>protocol ]
+        [ port>> '[ , or ] change-port ]
+        bi
+    ] change-url ;
+
+: valid-request? ( request -- ? )
+    url>> port>> local-address get port>> = ;
+
 : do-request ( request -- response )
     '[
         ,
-        [ init-request ]
-        [ log-request ]
-        [ dispatch-request ] tri
+        {
+            [ init-request ]
+            [ prepare-request ]
+            [ log-request ]
+            [ dup valid-request? [ dispatch-request ] [ drop <400> ] if ]
+        } cleave
     ] [ [ \ do-request log-error ] [ <500> ] bi ] recover ;
 
 : ?refresh-all ( -- )
index 033ba3cbfb12e6465d0c56bdbdb02702683b06a5..0e37e41a76414a0c4c98efe4775e46bcf274f315 100644 (file)
@@ -10,7 +10,7 @@ TUPLE: pool connections disposed expired ;
     dup check-disposed
     dup expired>> expired? [
         ALIEN: 31337 >>expired
-        connections>> [ delete-all ] [ dispose-each ] bi
+        connections>> delete-all
     ] [ drop ] if ;
 
 : <pool> ( class -- pool )
@@ -34,6 +34,7 @@ GENERIC: make-connection ( pool -- conn )
     dup check-pool [ make-connection ] keep return-connection ;
 
 : acquire-connection ( pool -- conn )
+    dup check-pool
     [ dup connections>> empty? ] [ dup new-connection ] [ ] while
     connections>> pop ;
 
index 359b9c6fb4eaf740944ef14d7e81d025b5f44df0..c855fba6be02c0584945371f8c305ef7bbab3832 100755 (executable)
@@ -4,7 +4,7 @@ USING: io io.sockets io.sockets.secure io.files
 io.streams.duplex logging continuations destructors kernel math
 math.parser namespaces parser sequences strings prettyprint
 debugger quotations calendar threads concurrency.combinators
-assocs fry ;
+assocs fry accessors ;
 IN: io.server
 
 SYMBOL: servers
@@ -15,9 +15,10 @@ SYMBOL: remote-address
 
 LOG: accepted-connection NOTICE
 
-: with-connection ( client remote quot -- )
+: with-connection ( client remote local quot -- )
     '[
         , [ remote-address set ] [ accepted-connection ] bi
+        , local-address set
         @
     ] with-stream ; inline
 
@@ -25,7 +26,8 @@ LOG: accepted-connection NOTICE
 
 : accept-loop ( server quot -- )
     [
-        >r accept r> '[ , , , with-connection ] "Client" spawn drop
+        [ [ accept ] [ addr>> ] bi ] dip
+        '[ , , , , with-connection ] "Client" spawn drop
     ] 2keep accept-loop ; inline
 
 : server-loop ( addrspec encoding quot -- )
@@ -59,7 +61,7 @@ LOG: received-datagram NOTICE
 
 : datagram-loop ( quot datagram -- )
     [
-        [ receive dup received-datagram >r swap call r> ] keep
+        [ receive dup received-datagram [ swap call ] dip ] keep
         pick [ send ] [ 3drop ] if
     ] 2keep datagram-loop ; inline
 
index 8dbf7db6901ffafa7d29bc92c04974cde8a03de8..882584f014192d8a0e98e73af1dbe77ea52b4ce4 100644 (file)
@@ -164,6 +164,8 @@ M: comment entity-url
 
 : <edit-post-action> ( -- action )
     <page-action>
+        "id" >>rest
+
         [
             validate-integer-id
             "id" value <post> select-tuple from-object
index da88a78ab08cc6efeeed3a7b67b0ac45658e1245..4522f8606bb3d34aab174ee38c7c6cb8ceb1d0e8 100644 (file)
 
        <div class="posting-footer">
                Post by
-               <t:a t:href="$blogs/" t:query="author">
+               <t:a t:href="$blogs/by" t:rest="author">
                        <t:label t:name="author" />
                </t:a>
                on
                <t:label t:name="date" />
                |
-               <t:a t:href="$blogs/post" t:for="id">View Post</t:a>
+               <t:a t:href="$blogs/post" t:rest="id">View Post</t:a>
                |
                <t:button t:action="$blogs/delete-post" t:for="id,author" class="link-button link">Delete Post</t:button>
        </div>
index 9c9685fe747fdb462c6341106d61674d325fe81f..94a5a69775d0f2cfbdab10a0c908fcd2afabacc1 100644 (file)
@@ -7,7 +7,7 @@
        <t:bind-each t:name="posts">
 
                <h2 class="post-title">
-                       <t:a t:href="$blogs/post" t:query="id">
+                       <t:a t:href="$blogs/post" t:rest="id">
                                <t:label t:name="title" />
                        </t:a>
                </h2>
 
                <div class="posting-footer">
                        Post by
-                       <t:a t:href="$blogs/by" t:query="author">
+                       <t:a t:href="$blogs/by" t:rest="author">
                                <t:label t:name="author" />
                        </t:a>
                        on
                        <t:label t:name="date" />
                        |
-                       <t:a t:href="$blogs/post" t:query="id">
+                       <t:a t:href="$blogs/post" t:rest="id">
                                <t:label t:name="comments" />
                                comments.
                        </t:a>
index 95fae23b34ff945852d42ec4b11db9ea9b36a5ad..d94b598fc0e8c0d57e38f53fc766e2e792c9b8d4 100644 (file)
@@ -2,7 +2,7 @@
 
 <t:chloe xmlns:t="http://factorcode.org/chloe/1.0">
 
-       <t:atom t:href="$blogs/by" t:query="author">
+       <t:atom t:href="$blogs/by" t:rest="author">
                Recent Posts by <t:label t:name="author" />
        </t:atom>
 
@@ -13,7 +13,7 @@
        <t:bind-each t:name="posts">
 
                <h2 class="post-title">
-                       <t:a t:href="$blogs/post" t:query="id">
+                       <t:a t:href="$blogs/post" t:rest="id">
                                <t:label t:name="title" />
                        </t:a>
                </h2>
 
                <div class="posting-footer">
                        Post by
-                       <t:a t:href="$blogs/by" t:query="author">
+                       <t:a t:href="$blogs/by" t:rest="author">
                                <t:label t:name="author" />
                        </t:a>
                        on
                        <t:label t:name="date" />
                        |
-                       <t:a t:href="$blogs/post" t:query="id">
+                       <t:a t:href="$blogs/post" t:rest="id">
                                <t:label t:name="comments" />
                                comments.
                        </t:a>
index 23bf51394629b7f31723de5ce049d206b268971c..fae9ff3e769eb9d77c4e10da57af9e567f95a1a7 100644 (file)
@@ -2,11 +2,11 @@
 
 <t:chloe xmlns:t="http://factorcode.org/chloe/1.0">
 
-       <t:atom t:href="$blogs/post.atom" t:query="id">
+       <t:atom t:href="$blogs/post.atom" t:rest="id">
                <t:label t:name="author" />: <t:label t:name="title" />
        </t:atom>
 
-       <t:atom t:href="$blogs/by.atom" t:query="author">
+       <t:atom t:href="$blogs/by.atom" t:rest="author">
                Recent Posts by <t:label t:name="author" />
        </t:atom>
 
 
        <div class="posting-footer">
                Post by
-               <t:a t:href="$blogs/" t:query="author">
+               <t:a t:href="$blogs/" t:rest="author">
                        <t:label t:name="author" />
                </t:a>
                on
                <t:label t:name="date" />
                |
-               <t:a t:href="$blogs/edit-post" t:query="id">Edit Post</t:a>
+               <t:a t:href="$blogs/edit-post" t:rest="id">Edit Post</t:a>
                |
                <t:button t:action="$blogs/delete-post" t:for="id,author" class="link-button link">Delete Post</t:button>
        </div>
index e19c531d3d383ecf052af6bfa9e6895ac2142bf1..9b2ae930fbca7ec0c247cfd8f384c31fd65b4e9a 100644 (file)
@@ -7,7 +7,7 @@
        <ul>
                <t:bind-each t:name="articles">
                        <li>
-                               <t:a t:href="view" t:query="title"><t:label t:name="title"/></t:a>
+                               <t:a t:href="$wiki/view" t:rest="title"><t:label t:name="title"/></t:a>
                        </li>
                </t:bind-each>
        </ul>
index 5b3e9de2c4f914a292087228a0d7b114055d07cd..1515c4924a35c251dc1cb2b19a2795a59114de57 100644 (file)
@@ -4,16 +4,26 @@
 
        <t:title>Recent Changes</t:title>
 
-       <ul>
-               <t:bind-each t:name="changes">
-                       <li>
-                               <t:a t:href="view" t:query="title"><t:label t:name="title" /></t:a>
-                               on
-                               <t:a t:href="revision" t:query="id"><t:label t:name="date" /></t:a>
-                               by
-                               <t:a t:href="user-edits" t:query="author"><t:label t:name="author" /></t:a>
-                       </li>
-               </t:bind-each>
-       </ul>
+       <div class="revisions">
+
+               <table>
+
+                       <tr>
+                               <th>Article</th>
+                               <th>Date</th>
+                               <th>By</th>
+                       </tr>
+
+                       <t:bind-each t:name="changes">
+                               <tr>
+                                       <td><t:a t:href="$wiki/view" t:rest="title"><t:label t:name="title" /></t:a></td>
+                                       <td><t:a t:href="$wiki/revision" t:rest="id"><t:label t:name="date" /></t:a></td>
+                                       <td><t:a t:href="$wiki/user-edits" t:rest="author"><t:label t:name="author" /></t:a></td>
+                               </tr>
+                       </t:bind-each>
+
+               </table>
+
+       </div>
 
 </t:chloe>
index 35afe51b66dd66bf4974970e81fd25411f6eabf0..9d65531eb0ad4725f53b1a18feaf014a5ccbf990 100644 (file)
@@ -8,13 +8,13 @@
                <tr>
                        <th class="field-label">Old revision:</th>
                        <t:bind t:name="old">
-                               <td>Created on <t:label t:name="date" /> by <t:a t:href="user-edits" t:query="author"><t:label t:name="author" /></t:a>.</td>
+                               <td>Created on <t:label t:name="date" /> by <t:a t:href="user-edits" t:rest="author"><t:label t:name="author" /></t:a>.</td>
                        </t:bind>
                </tr>
                <tr>
                        <th class="field-label">New revision:</th>
                        <t:bind t:name="old">
-                               <td>Created on <t:label t:name="date" /> by <t:a t:href="user-edits" t:query="author"><t:label t:name="author" /></t:a>.</td>
+                               <td>Created on <t:label t:name="date" /> by <t:a t:href="user-edits" t:rest="author"><t:label t:name="author" /></t:a>.</td>
                        </t:bind>
                </tr>
        </table>
index 675cb8cd65747bee5fe119ce9c7a03d07d788dcb..0d029946f89ac18a593b9ec311bb32264261a379 100644 (file)
@@ -2,16 +2,16 @@
 
 <t:chloe xmlns:t="http://factorcode.org/chloe/1.0">
 
-       <t:atom t:href="$wiki/revisions.atom" t:query="title">
+       <t:atom t:href="$wiki/revisions.atom" t:rest="title">
                Revisions of <t:label t:name="title" />
        </t:atom>
 
        <t:call-next-template />
 
        <div class="navbar">
-               <t:a t:href="$wiki/view" t:query="title">Latest</t:a>
-               | <t:a t:href="$wiki/revisions" t:query="title">Revisions</t:a>
-               | <t:a t:href="$wiki/edit" t:query="title">Edit</t:a>
+               <t:a t:href="$wiki/view" t:rest="title">Latest</t:a>
+               | <t:a t:href="$wiki/revisions" t:rest="title">Revisions</t:a>
+               | <t:a t:href="$wiki/edit" t:rest="title">Edit</t:a>
                | <t:button t:action="$wiki/delete" t:for="title" class="link-button link">Delete</t:button>
        </div>
 
index 2a909e6ab3a017680bd2eb26a2f757f12456c7f2..97a051cd96d95874ee0b5f6f1abe8bc9fe1ab15a 100644 (file)
@@ -8,14 +8,14 @@
                <table>
                        <tr>
                                <th>Revision</th>
-                               <th>Author</th>
+                               <th>By</th>
                                <th>Rollback</th>
                        </tr>
 
                        <t:bind-each t:name="revisions">
                                <tr>
-                                       <td> <t:a t:href="revision" t:query="id"><t:label t:name="date" /></t:a> </td>
-                                       <td> <t:a t:href="user-edits" t:query="author"><t:label t:name="author" /></t:a> </td>
+                                       <td> <t:a t:href="$wiki/revision" t:rest="id"><t:label t:name="date" /></t:a> </td>
+                                       <td> <t:a t:href="$wiki/user-edits" t:rest="author"><t:label t:name="author" /></t:a> </td>
                                        <td> <t:button t:action="rollback" t:for="id" class="link link-button">Rollback</t:button> </td>
                                </tr>
                        </t:bind-each>
@@ -24,7 +24,7 @@
 
        <h2>View Differences</h2>
 
-       <form action="diff" method="get">
+       <t:form t:action="$wiki/diff" t:method="get">
                <table>
                        <tr>
                                <th class="field-label">Old revision:</th>
@@ -51,6 +51,6 @@
                </table>
 
                <input type="submit" value="View" />
-       </form>
+       </t:form>
 
 </t:chloe>
index 6f22982f126265d269970ec124d3cc967f8898ac..6f6ada2dbdda91863f83d2cfae5e5f49066b605d 100644 (file)
@@ -2,7 +2,7 @@
 
 <t:chloe xmlns:t="http://factorcode.org/chloe/1.0">
 
-       <t:atom t:href="$wiki/user-edits.atom" t:query="author">
+       <t:atom t:href="$wiki/user-edits.atom" t:rest="author">
                Edits by <t:label t:name="author" />
        </t:atom>
 
@@ -11,9 +11,9 @@
        <ul>
                <t:bind-each t:name="user-edits">
                        <li>
-                               <t:a t:href="view" t:query="title"><t:label t:name="title" /></t:a>
+                               <t:a t:href="$wiki/view" t:rest="title"><t:label t:name="title" /></t:a>
                                on
-                               <t:a t:href="revision" t:query="id"><t:label t:name="date" /></t:a>
+                               <t:a t:href="$wiki/revision" t:rest="id"><t:label t:name="date" /></t:a>
                        </li>
                </t:bind-each>
        </ul>
index 30dfb71270eca5578e5badae38c79b9e874d88cb..7d2c7869b5a01f5e8a784c3e0e758b289f845b02 100644 (file)
@@ -8,6 +8,6 @@
                <t:farkup t:name="content" />
        </div>
 
-       <p><em>This revision created on <t:label t:name="date" /> by <t:a t:href="user-edits" t:query="author"><t:label t:name="author" /></t:a>.</em></p>
+       <p><em>This revision created on <t:label t:name="date" /> by <t:a t:href="$wiki/user-edits" t:rest="author"><t:label t:name="author" /></t:a>.</em></p>
 
 </t:chloe>
index 21a983fc7b4f6a51f918186b16a94f4a17d493e2..47912789743c5e0ebcc40bb249a71e4a6d7875be 100644 (file)
@@ -1,7 +1,7 @@
 ! Copyright (C) 2008 Slava Pestov
 ! See http://factorcode.org/license.txt for BSD license.
 USING: accessors kernel hashtables calendar
-namespaces splitting sequences sorting math.order
+namespaces splitting sequences sorting math.order present
 html.components syndication
 http.server
 http.server.dispatchers
@@ -15,20 +15,19 @@ validators
 db.types db.tuples lcs farkup urls ;
 IN: webapps.wiki
 
-: view-url ( title -- url )
-    "$wiki/view/" prepend >url ;
+: wiki-url ( rest path -- url )
+    [ "$wiki/" % % "/" % % ] "" make
+    <url> swap >>path ;
 
-: edit-url ( title -- url )
-    "$wiki/edit" >url swap "title" set-query-param ;
+: view-url ( title -- url ) "view" wiki-url ;
 
-: revisions-url ( title -- url )
-    "$wiki/revisions" >url swap "title" set-query-param ;
+: edit-url ( title -- url ) "edit" wiki-url ;
 
-: revision-url ( id -- url )
-    "$wiki/revision" >url swap "id" set-query-param ;
+: revisions-url ( title -- url ) "revisions" wiki-url ;
 
-: user-edits-url ( author -- url )
-    "$wiki/user-edits" >url swap "author" set-query-param ;
+: revision-url ( id -- url ) "revision" wiki-url ;
+
+: user-edits-url ( author -- url ) "user-edits" wiki-url ;
 
 TUPLE: wiki < dispatcher ;
 
@@ -83,12 +82,9 @@ M: revision feed-entry-url id>> revision-url ;
 : <view-article-action> ( -- action )
     <action>
         "title" >>rest
-
         [
             validate-title
-            "view?title=" relative-link-prefix set
         ] >>init
-
         [
             "title" value dup <article> select-tuple [
                 revision>> <revision> select-tuple from-object
@@ -100,13 +96,13 @@ M: revision feed-entry-url id>> revision-url ;
 
 : <view-revision-action> ( -- action )
     <page-action>
+        "id" >>rest
         [
             validate-integer-id
             "id" value <revision>
             select-tuple from-object
-            "view?title=" relative-link-prefix set
+            URL" $wiki/view/" adjust-url present relative-link-prefix set
         ] >>init
-
         { wiki "view" } >>template ;
 
 : add-revision ( revision -- )
@@ -121,15 +117,14 @@ M: revision feed-entry-url id>> revision-url ;
 
 : <edit-article-action> ( -- action )
     <page-action>
+        "title" >>rest
         [
             validate-title
             "title" value <article> select-tuple [
                 revision>> <revision> select-tuple from-object
             ] when*
         ] >>init
-
         { wiki "edit" } >>template
-        
         [
             validate-title
             { { "content" [ v-required ] } } validate-params
@@ -148,6 +143,7 @@ M: revision feed-entry-url id>> revision-url ;
 
 : <list-revisions-action> ( -- action )
     <page-action>
+        "title" >>rest
         [
             validate-title
             list-revisions "revisions" set-value
@@ -156,6 +152,7 @@ M: revision feed-entry-url id>> revision-url ;
 
 : <list-revisions-feed-action> ( -- action )
     <feed-action>
+        "title" >>rest
         [ validate-title ] >>init
         [ "Revisions of " "title" value append ] >>title
         [ "title" value revisions-url ] >>url
@@ -164,20 +161,18 @@ M: revision feed-entry-url id>> revision-url ;
 : <rollback-action> ( -- action )
     <action>
         [ validate-integer-id ] >>validate
-
         [
             "id" value <revision> select-tuple clone f >>id
             [ add-revision ] [ title>> view-url <redirect> ] bi
         ] >>submit ;
 
 : list-changes ( -- seq )
-    "id" value <revision> select-tuples
+    f <revision> select-tuples
     reverse-chronological-order ;
 
 : <list-changes-action> ( -- action )
     <page-action>
         [ list-changes "changes" set-value ] >>init
-
         { wiki "changes" } >>template ;
 
 : <list-changes-feed-action> ( -- action )
@@ -189,7 +184,6 @@ M: revision feed-entry-url id>> revision-url ;
 : <delete-action> ( -- action )
     <action>
         [ validate-title ] >>validate
-
         [
             "title" value <article> delete-tuples
             f <revision> "title" value >>title delete-tuples
@@ -213,7 +207,6 @@ M: revision feed-entry-url id>> revision-url ;
             [ [ content>> string-lines ] bi@ diff "diff" set-value ]
             2bi
         ] >>init
-
         { wiki "diff" } >>template ;
 
 : <list-articles-action> ( -- action )
@@ -223,7 +216,6 @@ M: revision feed-entry-url id>> revision-url ;
             [ [ title>> ] compare ] sort
             "articles" set-value
         ] >>init
-
         { wiki "articles" } >>template ;
 
 : list-user-edits ( -- seq )
@@ -232,6 +224,7 @@ M: revision feed-entry-url id>> revision-url ;
 
 : <user-edits-action> ( -- action )
     <page-action>
+        "author" >>rest
         [
             validate-author
             list-user-edits "user-edits" set-value
@@ -240,6 +233,7 @@ M: revision feed-entry-url id>> revision-url ;
 
 : <user-edits-feed-action> ( -- action )
     <feed-action>
+        "author" >>rest
         [ validate-author ] >>init
         [ "Edits by " "author" value append ] >>title
         [ "author" value user-edits-url ] >>url