1 module Rakka.Wiki.Interpreter.Base
7 import qualified Data.Map as M
10 import Rakka.SystemConfig
12 import Rakka.Wiki.Interpreter
13 import Text.XML.HXT.Arrow
16 interpreters :: [Interpreter]
17 interpreters = [ lineBreakInterp
29 lineBreakInterp :: Interpreter
30 lineBreakInterp = InlineCommandInterpreter {
33 = \ _ (InlineCommand _ attrs _) -> return $ LineBreak attrs
37 spanInterp :: Interpreter
38 spanInterp = InlineCommandInterpreter {
41 = \ _ (InlineCommand _ attrs contents) -> return $ Span attrs contents
45 divInterp :: Interpreter
46 divInterp = BlockCommandInterpreter {
49 = \ _ (BlockCommand _ attrs contents)
50 -> return $ Div attrs (map Block contents)
54 pageNameInterp :: Interpreter
55 pageNameInterp = InlineCommandInterpreter {
58 = \ ctx _ -> return $ Text (fromMaybe "" $ ctxPageName ctx)
62 otherLangsInterp :: Interpreter
64 = BlockCommandInterpreter {
65 bciName = "inOtherLanguages"
68 let linkTable = case ctxMainPage ctx of
69 Just page -> runLA ( getXPathTreesInDoc "/page/otherLang/link"
71 ( getAttrValue0 "lang"
79 [] -> return EmptyBlock
80 _ -> do Languages langTable <- getSysConf (ctxSysConf ctx)
81 let merged = mergeTables langTable linkTable
82 return $ mkLangList merged
85 mergeTables :: Map LanguageTag LanguageName
86 -> [(LanguageTag, PageName)]
87 -> [(LanguageName, PageName)]
89 mergeTables m (x:xs) = let (langTag, name) = x
90 langName = fromMaybe langTag (M.lookup langTag m)
92 (langName, name) : mergeTables m xs
94 mkLangList :: [(LanguageName, PageName)] -> BlockElement
95 mkLangList xs = List Bullet (map mkLangLink xs)
97 mkLangLink :: (LanguageName, PageName) -> ListItem
98 mkLangLink (langName, name)
99 = [Inline (PageLink (Just name) Nothing (Just langName))]
102 -- <input type="button"
103 -- value="Create new page"
104 -- onclick="Rakka.newPage()"
105 -- class="newButton" />
106 newPageInterp :: Interpreter
108 = InlineCommandInterpreter {
111 = \ _ (InlineCommand _ args _) ->
112 let label = fromMaybe "Create new page" (lookup "label" args)
113 attrs = [ ("type" , "button")
115 , ("onclick", "Rakka.newPage()")
116 , ("class" , "newButton")
123 -- <input type="button"
125 -- onclick="Rakka.editPage(\"Foo\")"
126 -- class="editButton" />
127 editPageInterp :: Interpreter
129 = InlineCommandInterpreter {
132 = \ ctx (InlineCommand _ args _) ->
133 let name = fromMaybe (fromMaybe "" $ ctxPageName ctx) (lookup "page" args)
134 label = fromMaybe "Edit this page" (lookup "label" args)
135 attrs = [ ("type" , "button")
137 , ("onclick", "Rakka.editPage(\"" ++ name ++ "\")")
138 , ("class" , "editButton")
145 -- <input type="button"
147 -- class="loginButton" />
148 loginInterp :: Interpreter
150 = InlineCommandInterpreter {
154 let attrs = [ ("type" , "button")
156 , ("class", "loginButton")
163 -- <input type="text"
164 -- class="searchField" />
165 searchFieldInterp :: Interpreter
167 = InlineCommandInterpreter {
168 iciName = "searchField"
171 let attrs = [ ("type" , "text")
172 , ("class", "searchField")