X-Git-Url: http://git.cielonegro.org/gitweb.cgi?a=blobdiff_plain;f=Rakka%2FWiki%2FInterpreter%2FBase.hs;h=73950537c9bd7179b26655f0f38531df69201de4;hb=42f51754dea02201aececaacbf194d714cd58aaf;hp=fa225e6b27144a5a253852bb66faacaf36401dd8;hpb=dcfffa578c5dd6647a5be7d2074488a520dfcf2d;p=Rakka.git
diff --git a/Rakka/Wiki/Interpreter/Base.hs b/Rakka/Wiki/Interpreter/Base.hs
index fa225e6..7395053 100644
--- a/Rakka/Wiki/Interpreter/Base.hs
+++ b/Rakka/Wiki/Interpreter/Base.hs
@@ -1,28 +1,46 @@
+{-# LANGUAGE
+ OverloadedStrings
+ , RecordWildCards
+ , UnicodeSyntax
+ #-}
module Rakka.Wiki.Interpreter.Base
- ( baseInterpreters
+ ( interpreters
)
where
+import Control.Applicative
+import Control.Arrow
+import Control.Arrow.ListArrow
+import Control.Arrow.Unicode
+import qualified Data.CaseInsensitive as CI
+import Data.Map (Map)
+import qualified Data.Map as M
+import Data.Maybe
+import Data.Monoid.Unicode
+import qualified Data.Text as T
+import Prelude.Unicode
+import Rakka.Page
+import Rakka.SystemConfig
+import Rakka.Wiki
+import Rakka.Wiki.Interpreter
+import Text.XML.HXT.Arrow.XmlArrow
+import Text.XML.HXT.XPath
-import Rakka.Page
-import Rakka.Wiki
-import Rakka.Wiki.Interpreter
-import Rakka.Wiki.Interpreter.Base.Image
-
-
-baseInterpreters :: [Interpreter]
-baseInterpreters = [ lineBreakInterp
- , spanInterp
- , divInterp
- , imageInterp
- , imgFrameInterp
-
- , pageNameInterp
- ]
-
+interpreters â· [Interpreter]
+interpreters = [ lineBreakInterp
+ , spanInterp
+ , divInterp
+ , pageNameInterp
+ , otherLangsInterp
+ , newPageInterp
+ , editPageInterp
+ , loginInterp
+ , searchFieldInterp
+ , configurationInterp
+ ]
lineBreakInterp :: Interpreter
lineBreakInterp = InlineCommandInterpreter {
- iciName = "br"
+ iciName = "br"
, iciInterpret
= \ _ (InlineCommand _ attrs _) -> return $ LineBreak attrs
}
@@ -30,7 +48,7 @@ lineBreakInterp = InlineCommandInterpreter {
spanInterp :: Interpreter
spanInterp = InlineCommandInterpreter {
- iciName = "span"
+ iciName = "span"
, iciInterpret
= \ _ (InlineCommand _ attrs contents) -> return $ Span attrs contents
}
@@ -38,17 +56,151 @@ 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 (InlineCommand _ _ _) -> case ctxPage ctx of
- Nothing -> return $ Text "(None)"
- Just page -> return $ Text $ pageName page
- }
\ No newline at end of file
+ = \ ctx _ -> return $ Text (fromMaybe "" $ ctxPageName ctx)
+ }
+
+otherLangsInterp â· Interpreter
+otherLangsInterp
+ = BlockCommandInterpreter {
+ bciName = "inOtherLanguages"
+ , bciInterpret
+ = \(InterpreterContext {..}) _ â
+ let linkTable = case ctxMainPage 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
+ let merged = mergeTables langTable $
+ (CI.mk â T.pack â T.pack) <$> linkTable
+ pure $ mkLangList merged
+ }
+ where
+ mergeTables â· Map LanguageTag LanguageName
+ â [(LanguageTag, PageName)]
+ â [(LanguageName, PageName)]
+ mergeTables _ [] = []
+ mergeTables m (x:xs) = let (langTag, name) = x
+ langName = fromMaybe (CI.foldedCase langTag)
+ (M.lookup langTag m)
+ in
+ (langName, name) : mergeTables m xs
+
+ mkLangList â· [(LanguageName, PageName)] â BlockElement
+ mkLangList = List Bullet â (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 controls")
+ ]
+ 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 controls")
+ ]
+ in
+ return (Input attrs)
+ }
+
+
+--
+loginInterp :: Interpreter
+loginInterp
+ = InlineCommandInterpreter {
+ iciName = "login"
+ , iciInterpret
+ = \ _ _ ->
+ let attrs = [ ("type" , "button")
+ , ("value", "Login")
+ , ("class", "loginButton controls")
+ ]
+ 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 controls")
+ ]
+ in
+ return (Input attrs)
+ }