1 module Rakka.Wiki.Interpreter.Base
7 import Control.Arrow.ListArrow
9 import qualified Data.Map as M
12 import Rakka.SystemConfig
14 import Rakka.Wiki.Interpreter
15 import Text.XML.HXT.Arrow.XmlArrow
16 import Text.XML.HXT.Arrow.XmlNodeSet
19 interpreters :: [Interpreter]
20 interpreters = [ lineBreakInterp
32 lineBreakInterp :: Interpreter
33 lineBreakInterp = InlineCommandInterpreter {
36 = \ _ (InlineCommand _ attrs _) -> return $ LineBreak attrs
40 spanInterp :: Interpreter
41 spanInterp = InlineCommandInterpreter {
44 = \ _ (InlineCommand _ attrs contents) -> return $ Span attrs contents
48 divInterp :: Interpreter
49 divInterp = BlockCommandInterpreter {
52 = \ _ (BlockCommand _ attrs contents)
53 -> return $ Div attrs (map Block contents)
57 pageNameInterp :: Interpreter
58 pageNameInterp = InlineCommandInterpreter {
61 = \ ctx _ -> return $ Text (fromMaybe "" $ ctxPageName ctx)
65 otherLangsInterp :: Interpreter
67 = BlockCommandInterpreter {
68 bciName = "inOtherLanguages"
71 let linkTable = case ctxMainPage ctx of
72 Just page -> runLA ( getXPathTreesInDoc "/page/otherLang/link"
74 ( getAttrValue0 "lang"
82 [] -> return EmptyBlock
83 _ -> do Languages langTable <- getSysConf (ctxSysConf ctx)
84 let merged = mergeTables langTable linkTable
85 return $ mkLangList merged
88 mergeTables :: Map LanguageTag LanguageName
89 -> [(LanguageTag, PageName)]
90 -> [(LanguageName, PageName)]
92 mergeTables m (x:xs) = let (langTag, name) = x
93 langName = fromMaybe langTag (M.lookup langTag m)
95 (langName, name) : mergeTables m xs
97 mkLangList :: [(LanguageName, PageName)] -> BlockElement
98 mkLangList xs = List Bullet (map mkLangLink xs)
100 mkLangLink :: (LanguageName, PageName) -> ListItem
101 mkLangLink (langName, name)
102 = [Inline (PageLink (Just name) Nothing (Just langName))]
105 -- <input type="button"
106 -- value="Create new page"
107 -- onclick="Rakka.newPage()"
108 -- class="newButton" />
109 newPageInterp :: Interpreter
111 = InlineCommandInterpreter {
114 = \ _ (InlineCommand _ args _) ->
115 let label = fromMaybe "Create new page" (lookup "label" args)
116 attrs = [ ("type" , "button")
118 , ("onclick", "Rakka.newPage()")
119 , ("class" , "newButton")
126 -- <input type="button"
128 -- onclick="Rakka.editPage(\"Foo\")"
129 -- class="editButton" />
130 editPageInterp :: Interpreter
132 = InlineCommandInterpreter {
135 = \ ctx (InlineCommand _ args _) ->
136 let name = fromMaybe (fromMaybe "" $ ctxPageName ctx) (lookup "page" args)
137 label = fromMaybe "Edit this page" (lookup "label" args)
138 attrs = [ ("type" , "button")
140 , ("onclick", "Rakka.editPage(\"" ++ name ++ "\")")
141 , ("class" , "editButton")
148 -- <input type="button"
150 -- class="loginButton" />
151 loginInterp :: Interpreter
153 = InlineCommandInterpreter {
157 let attrs = [ ("type" , "button")
159 , ("class", "loginButton")
166 -- <input type="text"
167 -- class="searchField" />
168 searchFieldInterp :: Interpreter
170 = InlineCommandInterpreter {
171 iciName = "searchField"
174 let attrs = [ ("type" , "text")
175 , ("class", "searchField")