+{-# LANGUAGE
+ OverloadedStrings
+ , RecordWildCards
+ , UnicodeSyntax
+ #-}
module Rakka.Wiki.Interpreter.Base
( interpreters
)
where
-
-import Data.Map (Map)
+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 Rakka.Page
-import Rakka.SystemConfig
-import Rakka.Wiki
-import Rakka.Wiki.Interpreter
-import Text.XML.HXT.Arrow
-import Text.XML.HXT.XPath
-
-
-interpreters :: [Interpreter]
+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
+
+interpreters ∷ [Interpreter]
interpreters = [ lineBreakInterp
, spanInterp
, divInterp
, configurationInterp
]
-
lineBreakInterp :: Interpreter
lineBreakInterp = InlineCommandInterpreter {
iciName = "br"
= \ ctx _ -> return $ Text (fromMaybe "" $ ctxPageName ctx)
}
-
-otherLangsInterp :: Interpreter
+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 -> []
+ = \(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 ctx)
- let merged = mergeTables langTable linkTable
- return $ mkLangList merged
+ _ -> 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 ∷ Map LanguageTag LanguageName
+ → [(LanguageTag, PageName)]
+ → [(LanguageName, PageName)]
mergeTables _ [] = []
mergeTables m (x:xs) = let (langTag, name) = x
- langName = fromMaybe langTag (M.lookup langTag m)
+ langName = fromMaybe (CI.foldedCase langTag)
+ (M.lookup langTag m)
in
(langName, name) : mergeTables m xs
- mkLangList :: [(LanguageName, PageName)] -> BlockElement
- mkLangList = List Bullet . map mkLangLink
+ mkLangList ∷ [(LanguageName, PageName)] → BlockElement
+ mkLangList = List Bullet ∘ (mkLangLink <$>)
- mkLangLink :: (LanguageName, PageName) -> ListItem
+ mkLangLink ∷ (LanguageName, PageName) → ListItem
mkLangLink (langName, name)
= [Inline (PageLink (Just name) Nothing (Just langName))]
-- value="Edit"
-- onclick="Rakka.editPage(\"Foo\")"
-- class="editButton controls" />
-editPageInterp :: Interpreter
+editPageInterp ∷ Interpreter
editPageInterp
= InlineCommandInterpreter {
iciName = "editPage"
, iciInterpret
- = \ ctx (InlineCommand _ args _) ->
+ = \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 ++ "\")")
+ , ("onclick", "Rakka.editPage(\"" ⊕ name ⊕ "\")")
, ("class" , "editButton controls")
]
in
-- <input type="button"
-- value="Configuration"
-- class="configButton controls" />
-configurationInterp :: Interpreter
+configurationInterp ∷ Interpreter
configurationInterp
= InlineCommandInterpreter {
iciName = "configuration"
, iciInterpret
- = \ _ _ ->
+ = \_ _ →
let attrs = [ ("type" , "button")
, ("value", "Configuration")
, ("class", "configButton controls")