]> gitweb @ CieloNegro.org - Rakka.git/blobdiff - Rakka/Wiki/Interpreter/Base.hs
Wrote many
[Rakka.git] / Rakka / Wiki / Interpreter / Base.hs
index 80ecefc78dbcaebbe2a4a13a9377d412b3584aa6..38578c0e590b53d4deb396a7a5da66476dbc84ef 100644 (file)
@@ -6,6 +6,7 @@ module Rakka.Wiki.Interpreter.Base
 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
@@ -18,6 +19,7 @@ interpreters = [ lineBreakInterp
                , divInterp
                , pageNameInterp
                , otherLangsInterp
+               , editPageInterp
                ]
 
 
@@ -84,4 +86,29 @@ otherLangsInterp
 
       mkLangLink :: (LanguageName, PageName) -> ListItem
       mkLangLink (langName, pageName)
-          = [Inline (PageLink (Just pageName) Nothing (Just langName))]
\ No newline at end of file
+          = [Inline (PageLink (Just pageName) Nothing (Just langName))]
+
+
+-- <input type="button"
+--        value="Edit"
+--        onclick="Rakka.editPage(\"http://example.org/\", \"Foo\")"
+--        class="editButton" />
+editPageInterp :: Interpreter
+editPageInterp 
+    = InlineCommandInterpreter {
+        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)
+      }