]> gitweb @ CieloNegro.org - Rakka.git/blobdiff - Rakka/Wiki/Interpreter/Base.hs
implemented login/out interface
[Rakka.git] / Rakka / Wiki / Interpreter / Base.hs
index 6feb92a77c82dcec77157cf3f0bff2929328a06f..bb4c4ad1ba24ad184c5ca3cc910c81a2d0371e0e 100644 (file)
@@ -8,7 +8,6 @@ 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
@@ -25,12 +24,13 @@ interpreters = [ lineBreakInterp
                , otherLangsInterp
                , newPageInterp
                , editPageInterp
+               , loginInterp
                ]
 
 
 lineBreakInterp :: Interpreter
 lineBreakInterp = InlineCommandInterpreter {
-                    iciName      = "br"
+                    iciName = "br"
                   , iciInterpret
                       = \ _ (InlineCommand _ attrs _) -> return $ LineBreak attrs
                   }
@@ -38,7 +38,7 @@ lineBreakInterp = InlineCommandInterpreter {
 
 spanInterp :: Interpreter
 spanInterp = InlineCommandInterpreter {
-               iciName      = "span"
+               iciName = "span"
              , iciInterpret
                  = \ _ (InlineCommand _ attrs contents) -> return $ Span attrs contents
              }
@@ -46,7 +46,7 @@ spanInterp = InlineCommandInterpreter {
 
 divInterp :: Interpreter
 divInterp = BlockCommandInterpreter {
-              bciName      = "div"
+              bciName = "div"
             , bciInterpret
                 = \ _ (BlockCommand _ attrs contents)
                 -> return $ Div attrs (map Block contents)
@@ -55,7 +55,7 @@ divInterp = BlockCommandInterpreter {
 
 pageNameInterp :: Interpreter
 pageNameInterp = InlineCommandInterpreter {
-                   iciName      = "pageName"
+                   iciName = "pageName"
                  , iciInterpret
                      = \ ctx _ -> return $ Text (ctxPageName ctx)
                  }
@@ -64,7 +64,7 @@ pageNameInterp = InlineCommandInterpreter {
 otherLangsInterp :: Interpreter
 otherLangsInterp
     = BlockCommandInterpreter {
-        bciName      = "inOtherLanguages"
+        bciName = "inOtherLanguages"
       , bciInterpret
           = \ ctx _ ->
             let linkTable = case ctxMainPage ctx of
@@ -103,48 +103,60 @@ otherLangsInterp
 
 -- <input type="button"
 --        value="Create new page"
---        onclick="Rakka.newPage(\"http://example.org/\")"
+--        onclick="Rakka.newPage()"
 --        class="newButton" />
 newPageInterp :: Interpreter
 newPageInterp 
     = InlineCommandInterpreter {
-        iciName      = "newPage"
+        iciName = "newPage"
       , iciInterpret
-          = \ ctx (InlineCommand _ args _) ->
-            do BaseURI baseURI <- getSysConf (ctxSysConf ctx)
-               
-               let label = fromMaybe "Create new page" (lookup "label" args)
-                   uri   = uriToString id baseURI ""
-                   attrs = [ ("type"   , "button")
-                           , ("value"  , label)
-                           , ("onclick", "Rakka.newPage(\"" ++ uri ++ "\")")
-                           , ("class"  , "newButton")
-                           ]
-
-               return (Input attrs)
+          = \ _ (InlineCommand _ args _) ->
+            let label = fromMaybe "Create new page" (lookup "label" args)
+                attrs = [ ("type"   , "button")
+                        , ("value"  , label)
+                        , ("onclick", "Rakka.newPage()")
+                        , ("class"  , "newButton")
+                        ]
+            in
+              return (Input attrs)
       }
 
 
 -- <input type="button"
 --        value="Edit"
---        onclick="Rakka.editPage(\"http://example.org/\", \"Foo\")"
+--        onclick="Rakka.editPage(\"Foo\")"
 --        class="editButton" />
 editPageInterp :: Interpreter
 editPageInterp 
     = InlineCommandInterpreter {
-        iciName      = "editPage"
+        iciName = "editPage"
       , iciInterpret
           = \ ctx (InlineCommand _ args _) ->
-            do BaseURI baseURI <- getSysConf (ctxSysConf ctx)
-
-               let name  = 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 ++ "\", \"" ++ name ++ "\")")
-                           , ("class"  , "editButton")
-                           ]
-
-               return (Input attrs)
+            let name  = 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")
+                        ]
+            in
+              return (Input attrs)
       }
+
+
+-- <input type="button"
+--        value="Login"
+--        class="loginButton" />
+loginInterp :: Interpreter
+loginInterp 
+    = InlineCommandInterpreter {
+        iciName = "login"
+      , iciInterpret
+          = \ _ _ ->
+            let attrs = [ ("type"   , "button")
+                        , ("value"  , "Login")
+                        , ("class"  , "loginButton")
+                        ]
+            in
+              return (Input attrs)
+      }
\ No newline at end of file