]> gitweb.factorcode.org Git - factor.git/blob - contrib/furnace-pastebin/pastebin.factor
More web framework work
[factor.git] / contrib / furnace-pastebin / pastebin.factor
1 IN: furnace:pastebin
2 USING: calendar kernel namespaces sequences furnace hashtables
3 math ;
4
5 TUPLE: paste n summary author channel contents date annotations ;
6
7 TUPLE: annotation summary author contents ;
8
9 C: paste ( summary author channel contents -- paste )
10     V{ } clone over set-paste-annotations
11     [ set-paste-contents ] keep
12     [ set-paste-author ] keep
13     [ set-paste-channel ] keep
14     [ set-paste-summary ] keep ;
15
16 TUPLE: pastebin pastes ;
17
18 C: pastebin ( -- pastebin )
19     V{ } clone over set-pastebin-pastes ;
20
21 : add-paste ( paste pastebin -- )
22     now timestamp>http-string pick set-paste-date
23     dup pastebin-pastes length pick set-paste-n
24     pastebin-pastes push ;
25
26 <pastebin> pastebin set-global
27
28 : get-paste ( n -- paste )
29     pastebin get pastebin-pastes nth ;
30
31 : show-paste ( n -- )
32     get-paste "show-paste" "Paste" render-page ;
33
34 \ show-paste { { "n" v-number } } define-action
35
36 : new-paste ( -- )
37     f "new-paste" "New paste" render-page ;
38
39 \ new-paste { } define-action
40
41 : submit-paste ( summary author channel contents -- )
42     <paste> pastebin get-global add-paste ;
43
44 \ submit-paste {
45     { "summary" v-required }
46     { "author" v-required }
47     { "channel" "#concatenative" v-default }
48     { "contents" v-required }
49 } define-action
50
51 : paste-list ( -- )
52     [
53         [ show-paste ] "show-paste-quot" set
54         [ new-paste ] "new-paste-quot" set
55
56         pastebin get "paste-list" "Pastebin" render-page
57     ] with-scope ;
58
59 \ paste-list { } define-action
60
61 \ submit-paste [ paste-list ] define-redirect
62
63 : annotate-paste ( paste# summary author contents -- )
64     <annotation> swap get-paste paste-annotations push ;
65
66 \ annotate-paste {
67     { "n" v-required v-number }
68     { "summary" v-required }
69     { "author" v-required }
70     { "contents" v-required }
71 } define-action
72
73 \ annotate-paste [ "n" show-paste ] define-redirect
74
75 "pastebin" "paste-list" "contrib/furnace-pastebin" web-app