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.XPath
16 interpreters :: [Interpreter]
17 interpreters = [ lineBreakInterp
30 lineBreakInterp :: Interpreter
31 lineBreakInterp = InlineCommandInterpreter {
34 = \ _ (InlineCommand _ attrs _) -> return $ LineBreak attrs
38 spanInterp :: Interpreter
39 spanInterp = InlineCommandInterpreter {
42 = \ _ (InlineCommand _ attrs contents) -> return $ Span attrs contents
46 divInterp :: Interpreter
47 divInterp = BlockCommandInterpreter {
50 = \ _ (BlockCommand _ attrs contents)
51 -> return $ Div attrs (map Block contents)
55 pageNameInterp :: Interpreter
56 pageNameInterp = InlineCommandInterpreter {
59 = \ ctx _ -> return $ Text (fromMaybe "" $ ctxPageName ctx)
63 otherLangsInterp :: Interpreter
65 = BlockCommandInterpreter {
66 bciName = "inOtherLanguages"
69 let linkTable = case ctxMainPage ctx of
70 Just page -> runLA ( getXPathTreesInDoc "/page/otherLang/link"
72 ( getAttrValue0 "lang"
80 [] -> return EmptyBlock
81 _ -> do Languages langTable <- getSysConf (ctxSysConf ctx)
82 let merged = mergeTables langTable linkTable
83 return $ mkLangList merged
86 mergeTables :: Map LanguageTag LanguageName
87 -> [(LanguageTag, PageName)]
88 -> [(LanguageName, PageName)]
90 mergeTables m (x:xs) = let (langTag, name) = x
91 langName = fromMaybe langTag (M.lookup langTag m)
93 (langName, name) : mergeTables m xs
95 mkLangList :: [(LanguageName, PageName)] -> BlockElement
96 mkLangList = List Bullet . map mkLangLink
98 mkLangLink :: (LanguageName, PageName) -> ListItem
99 mkLangLink (langName, name)
100 = [Inline (PageLink (Just name) Nothing (Just langName))]
103 -- <input type="button"
104 -- value="Create new page"
105 -- onclick="Rakka.newPage()"
106 -- class="newButton controls" />
107 newPageInterp :: Interpreter
109 = InlineCommandInterpreter {
112 = \ _ (InlineCommand _ args _) ->
113 let label = fromMaybe "Create new page" (lookup "label" args)
114 attrs = [ ("type" , "button")
116 , ("onclick", "Rakka.newPage()")
117 , ("class" , "newButton controls")
124 -- <input type="button"
126 -- onclick="Rakka.editPage(\"Foo\")"
127 -- class="editButton controls" />
128 editPageInterp :: Interpreter
130 = InlineCommandInterpreter {
133 = \ ctx (InlineCommand _ args _) ->
134 let name = fromMaybe (fromMaybe "" $ ctxPageName ctx) (lookup "page" args)
135 label = fromMaybe "Edit this page" (lookup "label" args)
136 attrs = [ ("type" , "button")
138 , ("onclick", "Rakka.editPage(\"" ++ name ++ "\")")
139 , ("class" , "editButton controls")
146 -- <input type="button"
148 -- class="loginButton controls" />
149 loginInterp :: Interpreter
151 = InlineCommandInterpreter {
155 let attrs = [ ("type" , "button")
157 , ("class", "loginButton controls")
164 -- <input type="text"
165 -- class="searchField" />
166 searchFieldInterp :: Interpreter
168 = InlineCommandInterpreter {
169 iciName = "searchField"
172 let attrs = [ ("type" , "text")
173 , ("class", "searchField")
179 -- <input type="button"
180 -- value="Configuration"
181 -- class="configButton controls" />
182 configurationInterp :: Interpreter
184 = InlineCommandInterpreter {
185 iciName = "configuration"
188 let attrs = [ ("type" , "button")
189 , ("value", "Configuration")
190 , ("class", "configButton controls")