X-Git-Url: http://git.cielonegro.org/gitweb.cgi?a=blobdiff_plain;f=Rakka%2FWiki%2FInterpreter%2FBase.hs;h=f461027dc339e1049f9543fe36b401f7cf8a275e;hb=dc29dc9081156af3b536b19ffd828cdd67ddd84a;hp=70951e6884ab1d43936d0d830d35e41e3ac16a50;hpb=7a4f13a3d483c950743e1ced001ade4406d239d3;p=Rakka.git diff --git a/Rakka/Wiki/Interpreter/Base.hs b/Rakka/Wiki/Interpreter/Base.hs index 70951e6..f461027 100644 --- a/Rakka/Wiki/Interpreter/Base.hs +++ b/Rakka/Wiki/Interpreter/Base.hs @@ -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,13 +22,15 @@ interpreters = [ lineBreakInterp , divInterp , pageNameInterp , otherLangsInterp + , newPageInterp , editPageInterp + , loginInterp ] lineBreakInterp :: Interpreter lineBreakInterp = InlineCommandInterpreter { - iciName = "br" + iciName = "br" , iciInterpret = \ _ (InlineCommand _ attrs _) -> return $ LineBreak attrs } @@ -37,7 +38,7 @@ lineBreakInterp = InlineCommandInterpreter { spanInterp :: Interpreter spanInterp = InlineCommandInterpreter { - iciName = "span" + iciName = "span" , iciInterpret = \ _ (InlineCommand _ attrs contents) -> return $ Span attrs contents } @@ -45,7 +46,7 @@ spanInterp = InlineCommandInterpreter { divInterp :: Interpreter divInterp = BlockCommandInterpreter { - bciName = "div" + bciName = "div" , bciInterpret = \ _ (BlockCommand _ attrs contents) -> return $ Div attrs (map Block contents) @@ -54,16 +55,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 @@ -100,26 +101,62 @@ otherLangsInterp = [Inline (PageLink (Just name) Nothing (Just langName))] +-- +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) + } + + -- 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 (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) } + + +-- +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