]> gitweb @ CieloNegro.org - Rakka.git/blob - Rakka/Wiki/Interpreter/Base.hs
Record before an experiment
[Rakka.git] / Rakka / Wiki / Interpreter / Base.hs
1 module Rakka.Wiki.Interpreter.Base
2     ( interpreters
3     )
4     where
5
6 import           Data.Map (Map)
7 import qualified Data.Map as M
8 import           Rakka.Page
9 import           Rakka.SystemConfig
10 import           Rakka.Wiki
11 import           Rakka.Wiki.Interpreter
12
13
14 interpreters :: [Interpreter]
15 interpreters = [ lineBreakInterp
16                , spanInterp
17                , divInterp
18                , pageNameInterp
19 --               , otherLangsInterp
20                ]
21
22
23 lineBreakInterp :: Interpreter
24 lineBreakInterp = InlineCommandInterpreter {
25                     iciName      = "br"
26                   , iciInterpret
27                       = \ _ (InlineCommand _ attrs _) -> return $ LineBreak attrs
28                   }
29
30
31 spanInterp :: Interpreter
32 spanInterp = InlineCommandInterpreter {
33                iciName      = "span"
34              , iciInterpret
35                  = \ _ (InlineCommand _ attrs contents) -> return $ Span attrs contents
36              }
37
38
39 divInterp :: Interpreter
40 divInterp = BlockCommandInterpreter {
41               bciName      = "div"
42             , bciInterpret
43                 = \ _ (BlockCommand _ attrs contents) -> return $ Div attrs contents
44             }
45
46
47 pageNameInterp :: Interpreter
48 pageNameInterp = InlineCommandInterpreter {
49                    iciName      = "pageName"
50                  , iciInterpret
51                      = \ ctx _ -> return $ Text (ctxPageName ctx)
52                  }
53
54 {-
55 otherLangsInterp :: Interpreter
56 otherLangsInterp
57     = BlockCommandInterpreter {
58         bciName      = "inOtherLanguages"
59       , bciInterpret
60           = \ ctx _ ->
61             case fmap pageOtherLang (ctxMainPage ctx) of
62               Nothing
63                 -> return EmptyBlock
64
65               Just linkTable
66                   -> do Languages langTable <- getSysConf (ctxSysConf ctx) (Languages undefined)
67                         let merged = mergeTables langTable (M.toList linkTable)
68                         -- FIXME
69       }
70     where
71       mergeTables :: Map LanguageTag LanguageName
72                   -> [(LanguageTag, PageName)]
73                   -> [(LanguageName, PageName)]
74       mergeTables _ []     = []
75       mergeTables m (x:xs) = fromMaybe x (M.lookup x m) : mergeTables m xs
76 -}