X-Git-Url: https://git.cielonegro.org/gitweb.cgi?a=blobdiff_plain;f=Rakka%2FWiki%2FInterpreter%2FBase.hs;h=f461027dc339e1049f9543fe36b401f7cf8a275e;hb=dc29dc9081156af3b536b19ffd828cdd67ddd84a;hp=437705dbdecbdfe7305acd7393d0d421ca104500;hpb=7c3065043cdfbd96539a9bf6bff9b1d4281c0b2a;p=Rakka.git
diff --git a/Rakka/Wiki/Interpreter/Base.hs b/Rakka/Wiki/Interpreter/Base.hs
index 437705d..f461027 100644
--- a/Rakka/Wiki/Interpreter/Base.hs
+++ b/Rakka/Wiki/Interpreter/Base.hs
@@ -1,35 +1,162 @@
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 Rakka.Page
+import Rakka.SystemConfig
import Rakka.Wiki
import Rakka.Wiki.Interpreter
-import Rakka.Wiki.Interpreter.Base.Image
+import Text.XML.HXT.Arrow.XmlArrow
+import Text.XML.HXT.Arrow.XmlNodeSet
-baseInterpreters :: [Interpreter]
-baseInterpreters = [ lineBreakInterp
- , spanInterp
- , divInterp
- , imageInterp
- , imgFrameInterp
- ]
+interpreters :: [Interpreter]
+interpreters = [ lineBreakInterp
+ , spanInterp
+ , divInterp
+ , pageNameInterp
+ , otherLangsInterp
+ , newPageInterp
+ , editPageInterp
+ , loginInterp
+ ]
lineBreakInterp :: Interpreter
-lineBreakInterp = pureInlineInterp "br" interpret
- where
- interpret (InlineCommand _ attrs _) _ = LineBreak attrs
+lineBreakInterp = InlineCommandInterpreter {
+ iciName = "br"
+ , iciInterpret
+ = \ _ (InlineCommand _ attrs _) -> return $ LineBreak attrs
+ }
spanInterp :: Interpreter
-spanInterp = pureInlineInterp "span" interpret
- where
- interpret (InlineCommand _ attrs contents) _ = Span attrs contents
+spanInterp = InlineCommandInterpreter {
+ iciName = "span"
+ , iciInterpret
+ = \ _ (InlineCommand _ attrs contents) -> return $ Span attrs contents
+ }
divInterp :: Interpreter
-divInterp = pureBlockInterp "div" interpret
+divInterp = BlockCommandInterpreter {
+ bciName = "div"
+ , bciInterpret
+ = \ _ (BlockCommand _ attrs contents)
+ -> return $ Div attrs (map Block contents)
+ }
+
+
+pageNameInterp :: Interpreter
+pageNameInterp = InlineCommandInterpreter {
+ iciName = "pageName"
+ , iciInterpret
+ = \ ctx _ -> return $ Text (fromMaybe "" $ 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
+ _ -> do Languages langTable <- getSysConf (ctxSysConf ctx)
+ let merged = mergeTables langTable linkTable
+ return $ mkLangList merged
+ }
where
- interpret (BlockCommand _ attrs contents) _ = Div attrs contents
\ No newline at end of file
+ mergeTables :: Map LanguageTag LanguageName
+ -> [(LanguageTag, PageName)]
+ -> [(LanguageName, PageName)]
+ mergeTables _ [] = []
+ mergeTables m (x:xs) = let (langTag, name) = x
+ langName = fromMaybe langTag (M.lookup langTag m)
+ in
+ (langName, name) : mergeTables m xs
+
+ mkLangList :: [(LanguageName, PageName)] -> BlockElement
+ mkLangList xs = List Bullet (map mkLangLink xs)
+
+ mkLangLink :: (LanguageName, PageName) -> ListItem
+ mkLangLink (langName, name)
+ = [Inline (PageLink (Just name) Nothing (Just langName))]
+
+
+--
+newPageInterp :: Interpreter
+newPageInterp
+ = InlineCommandInterpreter {
+ iciName = "newPage"
+ , iciInterpret
+ = \ _ (InlineCommand _ args _) ->
+ let label = fromMaybe "Create new page" (lookup "label" args)
+ attrs = [ ("type" , "button")
+ , ("value" , label)
+ , ("onclick", "Rakka.newPage()")
+ , ("class" , "newButton")
+ ]
+ in
+ return (Input attrs)
+ }
+
+
+--
+editPageInterp :: Interpreter
+editPageInterp
+ = InlineCommandInterpreter {
+ iciName = "editPage"
+ , iciInterpret
+ = \ ctx (InlineCommand _ args _) ->
+ let name = fromMaybe (fromMaybe "" $ ctxPageName ctx) (lookup "page" args)
+ label = fromMaybe "Edit this page" (lookup "label" args)
+ attrs = [ ("type" , "button")
+ , ("value" , label)
+ , ("onclick", "Rakka.editPage(\"" ++ name ++ "\")")
+ , ("class" , "editButton")
+ ]
+ in
+ return (Input attrs)
+ }
+
+
+--
+loginInterp :: Interpreter
+loginInterp
+ = InlineCommandInterpreter {
+ iciName = "login"
+ , iciInterpret
+ = \ _ _ ->
+ let attrs = [ ("type" , "button")
+ , ("value" , "Login")
+ , ("class" , "loginButton")
+ ]
+ in
+ return (Input attrs)
+ }
\ No newline at end of file