]> gitweb.factorcode.org Git - factor.git/blob - contrib/furnace-pastebin/pastebin.factor
1bd2b64a2acb136bc7ed128fbffacfb2005a73dd
[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 contents date ;
6
7 C: paste ( summary author contents -- paste )
8     [ set-paste-contents ] keep
9     [ set-paste-author ] keep
10     [ set-paste-summary ] keep ;
11
12 TUPLE: pastebin pastes ;
13
14 C: pastebin ( -- pastebin )
15     V{ } clone over set-pastebin-pastes ;
16
17 : add-paste ( paste pastebin -- )
18     now timestamp>http-string pick set-paste-date
19     dup pastebin-pastes length pick set-paste-n
20     pastebin-pastes push ;
21
22 <pastebin> "pastebin" set-global
23
24 : get-paste ( n -- paste )
25     "pastebin" get pastebin-pastes nth ;
26
27 : show-paste ( n -- )
28     "Paste"
29     swap string>number get-paste
30     "show-paste" render-page ;
31
32 \ show-paste { { "n" "0" } } define-action
33
34 : new-paste ( -- )
35     "New paste" f "new-paste" render-page ;
36
37 \ new-paste { } define-action
38
39 : submit-paste ( summary author contents -- )
40     <paste> "pastebin" get-global add-paste ;
41
42 \ submit-paste {
43     { "summary" "" }
44     { "author" "" }
45     { "contents" "" }
46 } define-action
47
48 : paste-list ( -- )
49     [
50         [ show-paste ] "show-paste-quot" set
51         [ new-paste ] "new-paste-quot" set
52
53         "Pastebin"
54         "pastebin" get
55         "paste-list" render-page
56     ] with-scope ;
57
58 \ paste-list { } define-action
59
60 \ submit-paste [ paste-list ] define-redirect
61
62 "pastebin" "paste-list" "contrib/furnace-pastebin" web-app