X-Git-Url: https://git.cielonegro.org/gitweb.cgi?a=blobdiff_plain;f=Rakka%2FWiki%2FInterpreter%2FBase.hs;h=73950537c9bd7179b26655f0f38531df69201de4;hb=45bce2c29948649f74ada71f2fa851bdb812e96c;hp=f461027dc339e1049f9543fe36b401f7cf8a275e;hpb=dc29dc9081156af3b536b19ffd828cdd67ddd84a;p=Rakka.git
diff --git a/Rakka/Wiki/Interpreter/Base.hs b/Rakka/Wiki/Interpreter/Base.hs
index f461027..7395053 100644
--- a/Rakka/Wiki/Interpreter/Base.hs
+++ b/Rakka/Wiki/Interpreter/Base.hs
@@ -1,22 +1,31 @@
+{-# LANGUAGE
+ OverloadedStrings
+ , RecordWildCards
+ , UnicodeSyntax
+ #-}
module Rakka.Wiki.Interpreter.Base
( interpreters
)
where
-
-import Control.Arrow
-import Control.Arrow.ListArrow
-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.XmlArrow
-import Text.XML.HXT.Arrow.XmlNodeSet
-
-
-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
@@ -25,9 +34,10 @@ interpreters = [ lineBreakInterp
, newPageInterp
, editPageInterp
, loginInterp
+ , searchFieldInterp
+ , configurationInterp
]
-
lineBreakInterp :: Interpreter
lineBreakInterp = InlineCommandInterpreter {
iciName = "br"
@@ -60,43 +70,44 @@ pageNameInterp = InlineCommandInterpreter {
= \ 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 xs = List Bullet (map mkLangLink xs)
+ 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))]
@@ -104,7 +115,7 @@ otherLangsInterp
--
+-- class="newButton controls" />
newPageInterp :: Interpreter
newPageInterp
= InlineCommandInterpreter {
@@ -115,7 +126,7 @@ newPageInterp
attrs = [ ("type" , "button")
, ("value" , label)
, ("onclick", "Rakka.newPage()")
- , ("class" , "newButton")
+ , ("class" , "newButton controls")
]
in
return (Input attrs)
@@ -125,19 +136,19 @@ newPageInterp
--
-editPageInterp :: Interpreter
+-- class="editButton controls" />
+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 ++ "\")")
- , ("class" , "editButton")
+ , ("onclick", "Rakka.editPage(\"" â name â "\")")
+ , ("class" , "editButton controls")
]
in
return (Input attrs)
@@ -146,17 +157,50 @@ editPageInterp
--
+-- class="loginButton controls" />
loginInterp :: Interpreter
loginInterp
= InlineCommandInterpreter {
iciName = "login"
, iciInterpret
= \ _ _ ->
- let attrs = [ ("type" , "button")
- , ("value" , "Login")
- , ("class" , "loginButton")
+ let attrs = [ ("type" , "button")
+ , ("value", "Login")
+ , ("class", "loginButton controls")
]
in
return (Input attrs)
- }
\ No newline at end of file
+ }
+
+
+--
+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)
+ }