- -> do SiteName siteName <- getSysConfA sysConf -< ()
- BaseURI baseURI <- getSysConfA sysConf -< ()
- StyleSheet cssName <- getSysConfA sysConf -< ()
-
- Just pageTitle <- getPageA sto -< ("PageTitle" , Nothing)
- Just leftSideBar <- getPageA sto -< ("SideBar/Left" , Nothing)
- Just rightSideBar <- getPageA sto -< ("SideBar/Right", Nothing)
-
- tree <- ( eelem "/"
- += ( eelem "page"
- += sattr "site" siteName
- += sattr "baseURI" (uriToString id baseURI "")
- += sattr "name" (pageName page)
- += sattr "type" (show $ pageType page)
- += ( case pageLanguage page of
- Just x -> sattr "lang" x
- _ -> none
- )
- += ( case pageFileName page of
- Just x -> sattr "fileName" x
- _ -> none
- )
- += ( case pageType page of
- MIMEType "text" "css" _
- -> sattr "isTheme" (yesOrNo $ pageIsTheme page)
- _ -> none
- )
- += ( case pageType page of
- MIMEType "text" "x-rakka" _
- -> sattr "isFeed" (yesOrNo $ pageIsFeed page)
- _ -> none
- )
- += sattr "isLocked" (yesOrNo $ pageIsLocked page)
- += sattr "isBoring" (yesOrNo $ pageIsBoring page)
- += sattr "isBinary" (yesOrNo $ pageIsBinary page)
- += sattr "revision" (show $ pageRevision page)
- += sattr "lastModified" (formatW3CDateTime $ pageLastMod page)
-
- += ( eelem "styleSheets"
- += ( eelem "styleSheet"
- += sattr "src" (uriToString id (mkObjectURI baseURI cssName) "")
- )
- )
-
- += ( eelem "scripts"
- += ( eelem "script"
- += sattr "src" (uriToString id (baseURI { uriPath = "/js" }) "")
- )
- )
-
- += ( case pageSummary page of
- Nothing -> none
- Just s -> eelem "summary" += txt s
- )
-
- += ( if M.null (pageOtherLang page) then
- none
- else
- selem "otherLang"
- [ eelem "link"
- += sattr "lang" lang
- += sattr "page" page
- | (lang, page) <- M.toList (pageOtherLang page) ]
- )
- += ( eelem "pageTitle"
- += ( (constA (pageName page) &&& constA (Just page) &&& constA pageTitle)
- >>>
- formatSubPage sto sysConf interpTable
- )
- )
- += ( eelem "sideBar"
- += ( eelem "left"
- += ( (constA (pageName page) &&& constA (Just page) &&& constA leftSideBar)
- >>>
- formatSubPage sto sysConf interpTable
- )
- )
- += ( eelem "right"
- += ( (constA (pageName page) &&& constA (Just page) &&& constA rightSideBar)
- >>>
- formatSubPage sto sysConf interpTable
- )
- )
- )
- += ( eelem "body"
- += (constA page >>> formatMainPage sto sysConf interpTable)
- )
- += (constA page >>> formatSource)
- >>>
- uniqueNamespacesFromDeclAndQNames
- )
- ) -<< ()
- returnA -< tree
-
-
-formatSource :: (ArrowXml a, ArrowChoice a) => a Page XmlTree
-formatSource = proc page
- -> if pageIsBinary page then
- none -< ()
- else
- let source = decodeLazy UTF8 (pageContent page)
- in
- ( eelem "source" += mkText ) -< source
-
-
-formatUnexistentPage :: (ArrowXml a, ArrowChoice a, ArrowIO a) =>
- Storage
- -> SystemConfig
- -> InterpTable
- -> a PageName XmlTree
-formatUnexistentPage sto sysConf interpTable
- = proc name
- -> do SiteName siteName <- getSysConfA sysConf -< ()
- BaseURI baseURI <- getSysConfA sysConf -< ()
- StyleSheet cssName <- getSysConfA sysConf -< ()
-
- Just pageTitle <- getPageA sto -< ("PageTitle" , Nothing)
- Just leftSideBar <- getPageA sto -< ("SideBar/Left" , Nothing)
- Just rightSideBar <- getPageA sto -< ("SideBar/Right", Nothing)
-
- tree <- ( eelem "/"
- += ( eelem "pageNotFound"
- += sattr "site" siteName
- += sattr "baseURI" (uriToString id baseURI "")
- += sattr "name" name
-
- += ( eelem "styleSheets"
- += ( eelem "styleSheet"
- += sattr "src" (uriToString id (mkObjectURI baseURI cssName) "")
- )
- )
-
- += ( eelem "scripts"
- += ( eelem "script"
- += sattr "src" (uriToString id (baseURI { uriPath = "/js" }) "")
- )
- )
-
- += ( eelem "pageTitle"
- += ( (constA name &&& constA Nothing &&& constA pageTitle)
- >>>
- formatSubPage sto sysConf interpTable
- )
- )
- += ( eelem "sideBar"
- += ( eelem "left"
- += ( (constA name &&& constA Nothing &&& constA leftSideBar)
- >>>
- formatSubPage sto sysConf interpTable
- )
- )
- += ( eelem "right"
- += ( (constA name &&& constA Nothing &&& constA rightSideBar)
- >>>
- formatSubPage sto sysConf interpTable
- )
- )
- )
- >>>
- uniqueNamespacesFromDeclAndQNames
- )
- ) -<< ()
- returnA -< tree
-
-
-formatMainPage :: (ArrowXml a, ArrowChoice a, ArrowIO a) =>
- Storage
- -> SystemConfig
- -> InterpTable
- -> a Page XmlTree
-formatMainPage sto sysConf interpTable
- = proc page
- -> do BaseURI baseURI <- getSysConfA sysConf -< ()
- wiki <- arr2 wikifyPage -< (interpTable, page)
- xs <- interpretCommandsA sto sysConf interpTable
- -< (pageName page, Just (page, wiki), wiki)
- formatWikiBlocks -< (baseURI, xs)
+ -> (eelem "/"
+ += ( eelem "page"
+ += sattr "name" (pageName page)
+ += sattr "type" (show $ pageType page)
+ += ( case pageLanguage page of
+ Just x -> sattr "lang" x
+ Nothing -> none
+ )
+ += ( case pageFileName page of
+ Just x -> sattr "fileName" x
+ Nothing -> none
+ )
+ += ( case pageType page of
+ MIMEType "text" "css" _
+ -> sattr "isTheme" (yesOrNo $ pageIsTheme page)
+ MIMEType "text" "x-rakka" _
+ -> sattr "isFeed" (yesOrNo $ pageIsFeed page)
+ _
+ -> none
+ )
+ += sattr "isLocked" (yesOrNo $ pageIsLocked page)
+ += sattr "isBoring" (yesOrNo $ pageIsBoring page)
+ += sattr "isBinary" (yesOrNo $ pageIsBinary page)
+ += sattr "revision" (show $ pageRevision page)
+ += sattr "lastModified" (formatW3CDateTime $ pageLastMod page)
+ += ( case pageSummary page of
+ Just s -> eelem "summary" += txt s
+ Nothing -> none
+ )
+ += ( if M.null (pageOtherLang page) then
+ none
+ else
+ selem "otherLang"
+ [ eelem "link"
+ += sattr "lang" lang
+ += sattr "page" page
+ | (lang, page) <- M.toList (pageOtherLang page) ]
+ )
+ += ( if pageIsBinary page then
+ ( eelem "binaryData"
+ += txt (B64.encode $ L.unpack $ pageContent page)
+ )
+ else
+ ( eelem "textData"
+ += txt (decodeLazy UTF8 $ pageContent page)
+ )
+ )
+ )
+ ) -<< ()
+
+
+wikifyPage :: (ArrowXml a, ArrowChoice a) => InterpTable -> a XmlTree WikiPage
+wikifyPage interpTable
+ = proc tree
+ -> do pName <- getXPathTreesInDoc "/page/@name/text()" >>> getText -< tree
+ pType <- getXPathTreesInDoc "/page/@type/text()" >>> getText >>> arr read -< tree
+ pFileName <- maybeA (getXPathTreesInDoc "/page/fileName/text()" >>> getText) -< tree
+ textData <- maybeA (getXPathTreesInDoc "/page/textData/text()" >>> getText) -< tree
+ base64Data <- maybeA (getXPathTreesInDoc "/page/binaryData/text()" >>> getText) -< tree
+
+ let dataURI = fmap (binToURI pType) base64Data
+
+ case pType of
+ MIMEType "text" "x-rakka" _
+ -> case parse (wikiPage cmdTypeOf) "" (fromJust textData) of
+ Left err -> wikifyParseError -< err
+ Right xs -> returnA -< xs
+
+ MIMEType "image" _ _
+ -- <img src="data:image/png;base64,..." />
+ -> returnA -< [ Paragraph [Image (Left $ fromJust dataURI) Nothing] ]
+
+ _ -> if isJust dataURI then
+ -- <a href="data:application/zip;base64,...">foo.zip</a>
+ returnA -< [ Paragraph [ Anchor
+ [("href", show dataURI)]
+ [Text (fromMaybe (defaultFileName pType pName) pFileName)]
+ ]
+ ]
+ else
+ -- pre
+ returnA -< [ Preformatted [Text $ fromJust textData] ]
+ where
+ cmdTypeOf :: String -> Maybe CommandType
+ cmdTypeOf name
+ = fmap commandType (M.lookup name interpTable)
+
+ binToURI :: MIMEType -> String -> URI
+ binToURI pType base64Data
+ = nullURI {
+ uriScheme = "data:"
+ , uriPath = show pType ++ ";base64," ++ (stripWhiteSpace base64Data)
+ }