X-Git-Url: http://git.cielonegro.org/gitweb.cgi?a=blobdiff_plain;f=Rakka%2FWiki%2FInterpreter%2FBase.hs;h=5daba841ae7021abeabcff9ade57fc75baa29737;hb=43113f26d3e61c96d896724c5509abe67b6a99e7;hp=3d38c2c3c9dc2c34478e36de00175d73d1aa0784;hpb=f4a655a34bc6017db008c2e915053958ae13ee81;p=Rakka.git diff --git a/Rakka/Wiki/Interpreter/Base.hs b/Rakka/Wiki/Interpreter/Base.hs index 3d38c2c..5daba84 100644 --- a/Rakka/Wiki/Interpreter/Base.hs +++ b/Rakka/Wiki/Interpreter/Base.hs @@ -5,10 +5,12 @@ module Rakka.Wiki.Interpreter.Base 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 Text.XML.HXT.Arrow interpreters :: [Interpreter] @@ -16,13 +18,18 @@ interpreters = [ lineBreakInterp , spanInterp , divInterp , pageNameInterp --- , otherLangsInterp + , otherLangsInterp + , newPageInterp + , editPageInterp + , loginInterp + , searchFieldInterp + , configurationInterp ] lineBreakInterp :: Interpreter lineBreakInterp = InlineCommandInterpreter { - iciName = "br" + iciName = "br" , iciInterpret = \ _ (InlineCommand _ attrs _) -> return $ LineBreak attrs } @@ -30,7 +37,7 @@ lineBreakInterp = InlineCommandInterpreter { spanInterp :: Interpreter spanInterp = InlineCommandInterpreter { - iciName = "span" + iciName = "span" , iciInterpret = \ _ (InlineCommand _ attrs contents) -> return $ Span attrs contents } @@ -38,39 +45,150 @@ spanInterp = InlineCommandInterpreter { divInterp :: Interpreter divInterp = BlockCommandInterpreter { - bciName = "div" + bciName = "div" , bciInterpret - = \ _ (BlockCommand _ attrs contents) -> return $ Div attrs contents + = \ _ (BlockCommand _ attrs contents) + -> return $ Div attrs (map Block contents) } pageNameInterp :: Interpreter pageNameInterp = InlineCommandInterpreter { - iciName = "pageName" + iciName = "pageName" , iciInterpret - = \ ctx _ -> return $ Text (ctxPageName ctx) + = \ ctx _ -> return $ Text (fromMaybe "" $ ctxPageName ctx) } -{- + otherLangsInterp :: Interpreter otherLangsInterp = BlockCommandInterpreter { - bciName = "inOtherLanguages" + bciName = "inOtherLanguages" , bciInterpret = \ ctx _ -> - case fmap pageOtherLang (ctxMainPage ctx) of - Nothing - -> return EmptyBlock - - Just linkTable - -> do Languages langTable <- getSysConf (ctxSysConf ctx) (Languages undefined) - let merged = mergeTables langTable (M.toList linkTable) - -- FIXME + 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 mergeTables :: Map LanguageTag LanguageName -> [(LanguageTag, PageName)] -> [(LanguageName, PageName)] mergeTables _ [] = [] - mergeTables m (x:xs) = fromMaybe x (M.lookup x m) : mergeTables m xs --} \ No newline at end of file + 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 = List Bullet . map mkLangLink + + 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) + } + + +-- +searchFieldInterp :: Interpreter +searchFieldInterp + = InlineCommandInterpreter { + iciName = "searchField" + , iciInterpret + = \ _ _ -> + let attrs = [ ("type" , "text") + , ("class", "searchField") + ] + in + return (Input attrs) + } + +-- +configurationInterp :: Interpreter +configurationInterp + = InlineCommandInterpreter { + iciName = "configuration" + , iciInterpret + = \ _ _ -> + let attrs = [ ("type" , "button") + , ("value", "Configuration") + , ("class", "configButton") + ] + in + return (Input attrs) + }