]> gitweb @ CieloNegro.org - Rakka.git/blobdiff - Rakka/Wiki/Interpreter/Base.hs
Fixing build breakage...
[Rakka.git] / Rakka / Wiki / Interpreter / Base.hs
index 9a02ae255668be349716a141300996bbe74aba1c..1af5c77e9844f7e5497b8c4ba364f3ac8440d101 100644 (file)
@@ -3,18 +3,14 @@ module Rakka.Wiki.Interpreter.Base
     )
     where
 
-import           Control.Arrow
-import           Control.Arrow.ListArrow
 import           Data.Map (Map)
 import qualified Data.Map as M
 import           Data.Maybe
-import           Network.URI
 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
+import           Text.XML.HXT.XPath
 
 
 interpreters :: [Interpreter]
@@ -23,13 +19,17 @@ interpreters = [ lineBreakInterp
                , divInterp
                , pageNameInterp
                , otherLangsInterp
+               , newPageInterp
                , editPageInterp
+               , loginInterp
+               , searchFieldInterp
+               , configurationInterp
                ]
 
 
 lineBreakInterp :: Interpreter
 lineBreakInterp = InlineCommandInterpreter {
-                    iciName      = "br"
+                    iciName = "br"
                   , iciInterpret
                       = \ _ (InlineCommand _ attrs _) -> return $ LineBreak attrs
                   }
@@ -37,7 +37,7 @@ lineBreakInterp = InlineCommandInterpreter {
 
 spanInterp :: Interpreter
 spanInterp = InlineCommandInterpreter {
-               iciName      = "span"
+               iciName = "span"
              , iciInterpret
                  = \ _ (InlineCommand _ attrs contents) -> return $ Span attrs contents
              }
@@ -45,7 +45,7 @@ spanInterp = InlineCommandInterpreter {
 
 divInterp :: Interpreter
 divInterp = BlockCommandInterpreter {
-              bciName      = "div"
+              bciName = "div"
             , bciInterpret
                 = \ _ (BlockCommand _ attrs contents)
                 -> return $ Div attrs (map Block contents)
@@ -54,16 +54,16 @@ divInterp = BlockCommandInterpreter {
 
 pageNameInterp :: Interpreter
 pageNameInterp = InlineCommandInterpreter {
-                   iciName      = "pageName"
+                   iciName = "pageName"
                  , iciInterpret
-                     = \ ctx _ -> return $ Text (ctxPageName ctx)
+                     = \ ctx _ -> return $ Text (fromMaybe "" $ ctxPageName ctx)
                  }
 
 
 otherLangsInterp :: Interpreter
 otherLangsInterp
     = BlockCommandInterpreter {
-        bciName      = "inOtherLanguages"
+        bciName = "inOtherLanguages"
       , bciInterpret
           = \ ctx _ ->
             let linkTable = case ctxMainPage ctx of
@@ -78,7 +78,7 @@ otherLangsInterp
             in
               case linkTable of
                 [] -> return EmptyBlock
-                xs -> do Languages langTable <- getSysConf (ctxSysConf ctx)
+                 -> do Languages langTable <- getSysConf (ctxSysConf ctx)
                          let merged = mergeTables langTable linkTable
                          return $ mkLangList merged
       }
@@ -87,39 +87,108 @@ otherLangsInterp
                   -> [(LanguageTag, PageName)]
                   -> [(LanguageName, PageName)]
       mergeTables _ []     = []
-      mergeTables m (x:xs) = let (langTag, pageName) = x
-                                 langName            = fromMaybe langTag (M.lookup langTag m)
+      mergeTables m (x:xs) = let (langTag, name) = x
+                                 langName        = fromMaybe langTag (M.lookup langTag m)
                              in
-                               (langName, pageName) : mergeTables m xs
+                               (langName, name) : mergeTables m xs
 
       mkLangList :: [(LanguageName, PageName)] -> BlockElement
-      mkLangList xs = List Bullet (map mkLangLink xs)
+      mkLangList = List Bullet . map mkLangLink
 
       mkLangLink :: (LanguageName, PageName) -> ListItem
-      mkLangLink (langName, pageName)
-          = [Inline (PageLink (Just pageName) Nothing (Just langName))]
+      mkLangLink (langName, name)
+          = [Inline (PageLink (Just name) Nothing (Just langName))]
+
+
+-- <input type="button"
+--        value="Create new page"
+--        onclick="Rakka.newPage()"
+--        class="newButton controls" />
+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)
+      }
 
 
 -- <input type="button"
 --        value="Edit"
---        onclick="Rakka.editPage(\"http://example.org/\", \"Foo\")"
---        class="editButton" />
+--        onclick="Rakka.editPage(\"Foo\")"
+--        class="editButton controls" />
 editPageInterp :: Interpreter
 editPageInterp 
     = InlineCommandInterpreter {
-        iciName      = "editPage"
+        iciName = "editPage"
       , iciInterpret
           = \ ctx (InlineCommand _ args _) ->
-            do BaseURI baseURI <- getSysConf (ctxSysConf ctx)
-
-               let pageName = fromMaybe (ctxPageName ctx) (lookup "page" args)
-                   label    = fromMaybe "Edit this page" (lookup "label" args)
-                   uri      = uriToString id baseURI ""
-                   attrs    = [ ("type"   , "button")
-                              , ("value"  , label)
-                              , ("onclick", "Rakka.editPage(\"" ++ uri ++ "\", \"" ++ pageName ++ "\")")
-                              , ("class"  , "editButton")
-                              ]
-
-               return (Input attrs)
+            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)
+      }
+
+
+-- <input type="button"
+--        value="Login"
+--        class="loginButton controls" />
+loginInterp :: Interpreter
+loginInterp 
+    = InlineCommandInterpreter {
+        iciName = "login"
+      , iciInterpret
+          = \ _ _ ->
+            let attrs = [ ("type" , "button")
+                        , ("value", "Login")
+                        , ("class", "loginButton controls")
+                        ]
+            in
+              return (Input attrs)
+      }
+
+
+-- <input type="text"
+--        class="searchField" />
+searchFieldInterp :: Interpreter
+searchFieldInterp 
+    = InlineCommandInterpreter {
+        iciName = "searchField"
+      , iciInterpret
+          = \ _ _ ->
+            let attrs = [ ("type" , "text")
+                        , ("class", "searchField")
+                        ]
+            in
+              return (Input attrs)
+      }
+
+-- <input type="button"
+--        value="Configuration"
+--        class="configButton controls" />
+configurationInterp :: Interpreter
+configurationInterp 
+    = InlineCommandInterpreter {
+        iciName = "configuration"
+      , iciInterpret
+          = \ _ _ ->
+            let attrs = [ ("type" , "button")
+                        , ("value", "Configuration")
+                        , ("class", "configButton controls")
+                        ]
+            in
+              return (Input attrs)
       }