]> ruin.nu Git - yawbih.git/blob - Main.hs
05414b4f3ec15786ccd05f14d094f5ce63b5287a
[yawbih.git] / Main.hs
1 module Main where 
2
3 import CGI hiding (div, head, map, span, Text)
4 import RawCGIInternal
5 import CGIOutput
6 import CGITypes
7 import System
8 import Wiki
9
10 import Text.ParserCombinators.Parsec
11
12 testDB = createPGB "wave" "wiki" "wiki" "12wiki34db"
13
14 --main = start [] cgi
15
16 main = do 
17         db <- testDB
18         runWithHook [] (\(key:act) -> sp db key act ) $ sp db "MainPage" [] 
19
20 ps a = standardQuery "Hello" a
21
22 editPage db key = do 
23         s <- io $ getCurrent db key 
24         s' <- case s of
25                 Nothing -> return ""
26                 Just (x,_) -> return x
27         standardQuery key $ do
28                 t <- p $ makeTextarea s' (attr_SS "rows" "10" ## attr_SS "cols" "75" ## attr_SS "colspan" "2")
29                 p empty
30                 text "Author: "
31                 a <- textInputField (fieldSIZE 20)
32                 p empty
33                 text "Comment: "
34                 c <- textInputField (fieldSIZE 20)
35                 --p $ submit (F2 t a) testing (attr "value" "Send")
36                 p $ defaultSubmit (F3 t a c) (savePage db key) (attr "value" "Send")
37                 --submit0 (sp db key []) (attr "value" "Send1")
38
39 sp db key _ = do
40         s <- io $ getCurrent db key 
41         standardQuery key $ showPage db key s
42
43 savePage db key (F3 t a c) = do
44         io $ update db key fulltext author comment
45         s <- io $ getCurrent db key 
46         standardQuery key $ do
47                 showPage db key s
48   where
49         fulltext = value t
50         author = value a
51         comment = value c 
52
53 showPage db key s = do
54                 case s of
55                         Nothing -> text "No text added for this keyword"
56                         Just (full, date) -> do
57                                 case parse wikiParser "" full of
58                                         Right n -> ex n 
59                                         Left e -> do
60                                                 text "PARSE ERROR: "
61                                                 text (show e)
62                                                 p $ text full
63                                 p $ text $ "Last edited: "++date
64                 footer db key
65
66 footer db key = do
67         hr empty
68         submit0 (editPage db key) (attr "value" "Edit")
69         --address (hlink (URL {unURL = ("wiki?"++key++"+edit")}) (text "Edit this page") 
70
71 ex [] = return ()
72 ex ((Paragraph):xs) = do
73         p empty
74         ex xs
75 ex ((Text s):xs) = do
76         text s
77         ex xs
78 ex ((Link l d):xs) = do
79         hlink (URL {unURL = ("wiki?"++l)}) (text d)
80         ex xs
81
82 ex2 [] = []
83 ex2 ((Paragraph):xs) = "<p>"++ex2 xs
84 ex2 ((Text s):xs) = s++ex2 xs
85 ex2 ((Link l d):xs) = "<link: "++l++" desc: "++d++">"++ex2 xs
86
87
88 test s = case parse wikiParser "" s of
89                                         Right n -> do 
90                                                 print (ex2 n)
91                                         Left e -> do
92                                                 print e