]> gitweb.factorcode.org Git - factor.git/blob - contrib/furnace-pastebin/pastebin.factor
Working on furnace
[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     "Paste"
33     swap get-paste
34     "show-paste" render-page ;
35
36 \ show-paste { { "n" v-number } } define-action
37
38 : new-paste ( -- )
39     "New paste" f "new-paste" render-page ;
40
41 \ new-paste { } define-action
42
43 : submit-paste ( summary author channel contents -- )
44     <paste> pastebin get-global add-paste ;
45
46 \ submit-paste {
47     { "summary" v-required }
48     { "author" v-required }
49     { "channel" "#concatenative" v-default }
50     { "contents" v-required }
51 } define-action
52
53 : paste-list ( -- )
54     [
55         [ show-paste ] "show-paste-quot" set
56         [ new-paste ] "new-paste-quot" set
57
58         "Pastebin"
59         pastebin get
60         "paste-list" render-page
61     ] with-scope ;
62
63 \ paste-list { } define-action
64
65 \ submit-paste [ paste-list ] define-redirect
66
67 "pastebin" "paste-list" "contrib/furnace-pastebin" web-app
68
69 : annotate-paste ( paste# summary author contents -- )
70     <annotation> swap get-paste paste-annotations push ;
71
72 \ annotate-paste {
73     { "n" v-required v-number }
74     { "summary" v-required }
75     { "author" v-required }
76     { "contents" v-required }
77 } define-action
78
79 \ annotate-paste [ "n" show-paste ] define-redirect