module Rakka.Wiki.Interpreter.Base
- ( baseInterpreters
+ ( interpreters
)
where
+import Control.Arrow
+import Control.Arrow.ListArrow
+import Data.Map (Map)
+import qualified Data.Map as M
+import Data.Maybe
+import Network.URI
+import Rakka.Page
+import Rakka.SystemConfig
import Rakka.Wiki
import Rakka.Wiki.Interpreter
-import Rakka.Wiki.Interpreter.Base.Image
-import Rakka.Wiki.Interpreter.Base.Outline
+import Text.XML.HXT.Arrow.XmlArrow
+import Text.XML.HXT.Arrow.XmlNodeSet
-baseInterpreters :: [Interpreter]
-baseInterpreters = [ lineBreakInterp
- , spanInterp
- , divInterp
- , imageInterp
- , imgFrameInterp
-
- , pageNameInterp
- , outlineInterp
- ]
+interpreters :: [Interpreter]
+interpreters = [ lineBreakInterp
+ , spanInterp
+ , divInterp
+ , pageNameInterp
+ , otherLangsInterp
+ , editPageInterp
+ ]
lineBreakInterp :: Interpreter
divInterp = BlockCommandInterpreter {
bciName = "div"
, bciInterpret
- = \ _ (BlockCommand _ attrs contents) -> return $ Div attrs contents
+ = \ _ (BlockCommand _ attrs contents)
+ -> return $ Div attrs (map Block contents)
}
, iciInterpret
= \ ctx _ -> return $ Text (ctxPageName ctx)
}
+
+
+otherLangsInterp :: Interpreter
+otherLangsInterp
+ = BlockCommandInterpreter {
+ bciName = "inOtherLanguages"
+ , bciInterpret
+ = \ ctx _ ->
+ let linkTable = case ctxMainPage ctx of
+ Just page -> runLA ( getXPathTreesInDoc "/page/otherLang/link"
+ >>>
+ ( getAttrValue0 "lang"
+ &&&
+ getAttrValue0 "page"
+ )
+ ) page
+ Nothing -> []
+ in
+ case linkTable of
+ [] -> return EmptyBlock
+ xs -> do Languages langTable <- getSysConf (ctxSysConf ctx)
+ let merged = mergeTables langTable linkTable
+ return $ mkLangList merged
+ }
+ where
+ mergeTables :: Map LanguageTag LanguageName
+ -> [(LanguageTag, PageName)]
+ -> [(LanguageName, PageName)]
+ mergeTables _ [] = []
+ mergeTables m (x:xs) = let (langTag, pageName) = x
+ langName = fromMaybe langTag (M.lookup langTag m)
+ in
+ (langName, pageName) : mergeTables m xs
+
+ mkLangList :: [(LanguageName, PageName)] -> BlockElement
+ mkLangList xs = List Bullet (map mkLangLink xs)
+
+ mkLangLink :: (LanguageName, PageName) -> ListItem
+ mkLangLink (langName, pageName)
+ = [Inline (PageLink (Just pageName) Nothing (Just langName))]
+
+
+-- <input type="button"
+-- value="Edit"
+-- onclick="Rakka.editPage(\"http://example.org/\", \"Foo\")"
+-- class="editButton" />
+editPageInterp :: Interpreter
+editPageInterp
+ = InlineCommandInterpreter {
+ iciName = "editPage"
+ , iciInterpret
+ = \ ctx (InlineCommand _ args _) ->
+ do BaseURI baseURI <- getSysConf (ctxSysConf ctx)
+
+ let pageName = fromMaybe (ctxPageName ctx) (lookup "page" args)
+ label = fromMaybe "Edit this page" (lookup "label" args)
+ uri = uriToString id baseURI ""
+ attrs = [ ("type" , "button")
+ , ("value" , label)
+ , ("onclick", "Rakka.editPage(\"" ++ uri ++ "\", \"" ++ pageName ++ "\")")
+ , ("class" , "editButton")
+ ]
+
+ return (Input attrs)
+ }