]> gitweb @ CieloNegro.org - Rakka.git/blobdiff - Rakka/Wiki/Interpreter/Base.hs
improved the page editor
[Rakka.git] / Rakka / Wiki / Interpreter / Base.hs
index 70951e6884ab1d43936d0d830d35e41e3ac16a50..6b883c376c270d68a2ecfaa00b112706bb358b66 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
@@ -23,6 +22,7 @@ interpreters = [ lineBreakInterp
                , divInterp
                , pageNameInterp
                , otherLangsInterp
+               , newPageInterp
                , editPageInterp
                ]
 
@@ -100,9 +100,30 @@ otherLangsInterp
           = [Inline (PageLink (Just name) Nothing (Just langName))]
 
 
+-- <input type="button"
+--        value="Create new page"
+--        onclick="Rakka.newPage()"
+--        class="newButton" />
+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")
+                        ]
+            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 
@@ -110,16 +131,13 @@ editPageInterp
         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)
       }