]> gitweb @ CieloNegro.org - Rakka.git/blobdiff - Rakka/Wiki/Interpreter/Base.hs
Record before an experiment
[Rakka.git] / Rakka / Wiki / Interpreter / Base.hs
index 437705dbdecbdfe7305acd7393d0d421ca104500..3d38c2c3c9dc2c34478e36de00175d73d1aa0784 100644 (file)
@@ -1,35 +1,76 @@
 module Rakka.Wiki.Interpreter.Base
-    ( baseInterpreters
+    ( interpreters
     )
     where
 
+import           Data.Map (Map)
+import qualified Data.Map as M
+import           Rakka.Page
+import           Rakka.SystemConfig
 import           Rakka.Wiki
 import           Rakka.Wiki.Interpreter
-import           Rakka.Wiki.Interpreter.Base.Image
 
 
-baseInterpreters :: [Interpreter]
-baseInterpreters = [ lineBreakInterp
-                   , spanInterp
-                   , divInterp
-                   , imageInterp
-                   , imgFrameInterp
-                   ]
+interpreters :: [Interpreter]
+interpreters = [ lineBreakInterp
+               , spanInterp
+               , divInterp
+               , pageNameInterp
+--               , otherLangsInterp
+               ]
 
 
 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 contents
+            }
+
+
+pageNameInterp :: Interpreter
+pageNameInterp = InlineCommandInterpreter {
+                   iciName      = "pageName"
+                 , iciInterpret
+                     = \ ctx _ -> return $ Text (ctxPageName ctx)
+                 }
+
+{-
+otherLangsInterp :: Interpreter
+otherLangsInterp
+    = BlockCommandInterpreter {
+        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
+      }
     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) = fromMaybe x (M.lookup x m) : mergeTables m xs
+-}
\ No newline at end of file