]> gitweb @ CieloNegro.org - Rakka.git/commitdiff
Wrote many
authorpho <pho@cielonegro.org>
Mon, 29 Oct 2007 08:52:21 +0000 (17:52 +0900)
committerpho <pho@cielonegro.org>
Mon, 29 Oct 2007 08:52:21 +0000 (17:52 +0900)
darcs-hash:20071029085221-62b54-d30fa2eae5994785e6fbee6ddade3e74f39644f1.gz

13 files changed:
Rakka/Resource/Render.hs
Rakka/SystemConfig.hs
Rakka/Wiki.hs
Rakka/Wiki/Engine.hs
Rakka/Wiki/Formatter.hs
Rakka/Wiki/Interpreter/Base.hs
Rakka/Wiki/Parser.hs
defaultPages/Help/Syntax
defaultPages/SideBar/Right
defaultPages/StyleSheet/Default
js/Makefile
js/base.js [new file with mode: 0644]
js/editPage.js [new file with mode: 0644]

index cb01bcd35f3aa5abca2c7da7f97a9b6d47944261..c4c8da062c93bdac1358046946867330b9c06c12 100644 (file)
@@ -70,6 +70,7 @@ handleRedirect env
 
 {-
   <page site="CieloNegro"
+        baseURI="http://example.org"
         name="Foo/Bar"
         type="text/x-rakka"
         lang="ja"            -- 存在しない場合もある
@@ -113,6 +114,10 @@ handleRedirect env
     <body>
       blah blah...
     </body>
+
+    <source><!-- isBinary="no" の場合にのみ存在 -->
+      blah blah...
+    </source>
   </page>
 -}
 handleGetEntity :: (ArrowXml a, ArrowChoice a, ArrowIO a) => Environment -> a Page (Resource ())
@@ -206,9 +211,17 @@ entityToXHTML
 
 {-
   <pageNotFound site="CieloNegro"
-                styleSheet="http://example.org/object/StyleSheet/Default"
+                baseURI="http://example.org"
                 name="Foo/Bar">
 
+    <styleSheets>
+      <styleSheet src="http://example.org/object/StyleSheet/Default" />
+    </styleSheets>
+
+    <scripts>
+      <script src="http://example.org/js" />
+    </scripts>
+
     <pageTitle>
       blah blah...
     </pageTitle>
index 09c45166530dfc4b5f53fe700ff6aeec0aa0543f..67603862d60b00fcfe7692f56a3f48b743ec3036 100644 (file)
@@ -17,6 +17,7 @@ module Rakka.SystemConfig
 
 import           Control.Arrow.ArrowIO
 import           Control.Concurrent.STM
+import           Control.Monad
 import           Control.Monad.Trans
 import qualified Data.ByteString.Char8 as C8
 import           Data.Dynamic
@@ -148,7 +149,13 @@ newtype BaseURI = BaseURI URI deriving (Show, Typeable)
 instance SysConfValue BaseURI where
     confPath _              = "baseURI"
     serialize (BaseURI uri) = uriToString id uri ""
-    deserialize uri         = fmap BaseURI (parseURI uri)
+    deserialize uri         = fmap BaseURI
+                              $ do parsed <- parseURI uri
+                                   when (uriPath parsed        == "" ) (fail undefined)
+                                   when (last (uriPath parsed) /= '/') (fail undefined)
+                                   when (uriQuery parsed       /= "" ) (fail undefined)
+                                   when (uriFragment parsed    /= "" ) (fail undefined)
+                                   return parsed
     defaultValue sc
         = let conf = scLucuConf sc
               host = C8.unpack $ LC.cnfServerHost conf
index 719ed62cc646699ebb4069a2bc1c6b51506b3de0..5dfb462bba6a33d0559c195b5a5cb37147ab06df 100644 (file)
@@ -78,6 +78,7 @@ data InlineElement
       , imgAlt    :: !(Maybe String)
       }
     | Anchor ![Attribute] ![InlineElement]
+    | Input ![Attribute]
     | EmptyInline
     | InlineCmd !InlineCommand
     deriving (Eq, Show, Typeable, Data)
index 0f18fb1187fe3df6e3c2733441314b4116af9551..07eaff4a594ed5c5ff112f1550997e533bffe6df 100644 (file)
@@ -53,6 +53,7 @@ formatEntirePage sto sysConf interpTable
           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
@@ -128,6 +129,7 @@ formatEntirePage sto sysConf interpTable
                          += ( eelem "body"
                               += (constA page >>> formatMainPage sto sysConf interpTable)
                             )
+                         += (constA page >>> formatSource)
                          >>>
                          uniqueNamespacesFromDeclAndQNames
                        )
@@ -135,6 +137,16 @@ formatEntirePage sto sysConf interpTable
           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
@@ -152,9 +164,21 @@ formatUnexistentPage sto sysConf interpTable
 
           tree <- ( eelem "/"
                     += ( eelem "pageNotFound"
-                         += sattr "site"       siteName
-                         += sattr "styleSheet" (uriToString id (mkObjectURI baseURI cssName) "")
-                         += sattr "name"       name
+                         += 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)
index 1c3abe549d2a2445d22bd799fc15d1cf38c043a5..983673bf9614867a619f211e136a7b5980ce6d54 100644 (file)
@@ -188,6 +188,9 @@ formatInline
          Anchor attrs contents
              -> formatElem "a" -< (baseURI, attrs, contents)
 
+         Input attrs
+             -> formatElem "input" -< (baseURI, attrs, [])
+
          EmptyInline
              -> none -< ()
     where
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)
+      }
index 6e4edeb4bc5c604aab1f6e97c0080471c1ebeff4..4d936f95f2995929ae22b03d9a3a90ed08bddc35 100644 (file)
@@ -34,7 +34,7 @@ blockElement cmdTypeOf
                                  , horizontalLine
                                  , listElement cmdTypeOf
                                  , definitionList cmdTypeOf
-                                 , pdata
+                                 , verbatim
                                  , leadingSpaced cmdTypeOf
                                  , paragraph cmdTypeOf
                                  , blockCmd cmdTypeOf
@@ -149,19 +149,19 @@ definitionList cmdTypeOf = many1 definition >>= return . DefinitionList
                     "description of term"
 
 
-pdata :: Parser BlockElement
-pdata = do try (string "<![PDATA[")
-           many (oneOf " \t\n")
-           x <- pdata'
-           return (Preformatted [Text x])
+verbatim :: Parser BlockElement
+verbatim = do try (string "<!verbatim[")
+              many (oneOf " \t\n")
+              x <- verbatim'
+              return (Preformatted [Text x])
     where
-      pdata' :: Parser String
-      pdata' = do try (many (oneOf " \t\n") >> string "]]>")
-                  return []
-               <|>
-               do x  <- anyChar
-                  xs <- pdata'
-                  return (x:xs)
+      verbatim' :: Parser String
+      verbatim' = do try (many (oneOf " \t\n") >> string "]>")
+                     return []
+                  <|>
+                  do x  <- anyChar
+                     xs <- verbatim'
+                     return (x:xs)
 
 
 leadingSpaced :: CommandTypeOf -> Parser BlockElement
@@ -279,7 +279,7 @@ blockCmd cmdTypeOf
 inlineElement :: CommandTypeOf -> Parser InlineElement
 inlineElement cmdTypeOf
     = try $ do skipMany comment
-               foldr (<|>) pzero [ cdata
+               foldr (<|>) pzero [ nowiki
                                  , apostrophes cmdTypeOf
                                  , text
                                  , objLink
@@ -289,16 +289,16 @@ inlineElement cmdTypeOf
                                  ]
 
 
-cdata :: Parser InlineElement
-cdata = try (string "<![CDATA[") >> cdata' >>= return . Text
+nowiki :: Parser InlineElement
+nowiki = try (string "<!nowiki[") >> nowiki' >>= return . Text
     where
-      cdata' :: Parser String
-      cdata' = do try (string "]]>")
-                  return []
-               <|>
-               do x  <- anyChar
-                  xs <- cdata'
-                  return (x:xs)
+      nowiki' :: Parser String
+      nowiki' = do try (string "]>")
+                   return []
+                <|>
+                do x  <- anyChar
+                   xs <- nowiki'
+                   return (x:xs)
 
 
 text :: Parser InlineElement
index 1634607c1e6472d12bedeb629d2c7c42a32a5663..5e54aed9f49f2ede54689209bda9bea07bcade12 100644 (file)
@@ -31,17 +31,17 @@ special -- there are just '''' left
 over ones'''' that are included as part of the text.)
 ]]>
 
-== CDATA section ==
-&lt;![CDATA[
+== nowiki section ==
+&lt;!nowiki[
 [[Wiki]] markup is ignored here
 but the text is reformatted.
-]]&gt;
+]&gt;
 
-== PDATA section ==
-&lt;![PDATA[
+== verbatim section ==
+&lt;!verbatim[
 [[Wiki]] markup is ignored here
  and   reformatting is    also  disabled.
-]]&gt;
+]&gt;
 
 <![CDATA[
 == Leading spaces ==
index afef42700ac59206f402a0a03a50c7ac26ed5642..c43cef15a8f654edfe003d553907b56803c01c95 100644 (file)
@@ -4,6 +4,7 @@
       isBoring="yes">
   <textData><![CDATA[
 = Control =
+* <editPage />
 
 = In other languages =
 <inOtherLanguages />
index b2c369359fc38eb7a1f59c640d2fa5e3bd2ace05..71bbf99e62d6350c9ce0165f7be77140f601d07f 100644 (file)
@@ -214,6 +214,21 @@ a {
     color: #008800;
     text-decoration: none;
 }
+a:hover {
+    text-decoration: underline;
+}
+
+input[type="button"] {
+    background-color: #eeeeee;
+
+    border-color: #fafafa #dddddd #dddddd #fafafa;
+    border-width: 2px;
+    border-style: solid;
+}
+input[type="button"]:active {
+    background-color: white;
+    border-color: #dddddd #fafafa #fafafa #dddddd;
+}
 
 .header, .footer, .sideBar {
     background-color: #eeeeee;
index a5c163b11b746c2cbc073e117d11417878ece1e4..d7e9959a975a2607b3b326cb6217a3dab200fb0b 100644 (file)
@@ -1,5 +1,8 @@
 SOURCES = \
        jquery-1.2.1.js \
+       jquery-dom.js \
+       base.js \
+       editPage.js \
        $(NULL)
 
 
@@ -13,6 +16,11 @@ build: ../Rakka/Resource/JavaScript.hs
        rm tmp.js tmp.packed.js
 
 
+jquery-dom.js:
+       @echo "Warning: jquery-dom.js is missing. Trying to download it..."
+       wget http://mg.to/files/jquery-dom.js
+
+
 jquery-%.js:
        @echo "Error: $@ has to be placed on this directory."
        @echo "       See http://jquery.com/"
diff --git a/js/base.js b/js/base.js
new file mode 100644 (file)
index 0000000..a1be768
--- /dev/null
@@ -0,0 +1,2 @@
+/* Namespace Rakka */
+var Rakka = {};
diff --git a/js/editPage.js b/js/editPage.js
new file mode 100644 (file)
index 0000000..7e54fbb
--- /dev/null
@@ -0,0 +1,101 @@
+Rakka.editPage = function (baseURI, pageName) {
+    var $body = $("div.body");
+
+    $body.text("Loading... please wait.");
+    
+    // XML 版のページを取得する。
+    $.ajax({
+        url    : baseURI + pageName + ".xml",
+        success: function (pageXml) {
+                     var $page         = $(pageXml).find("page");
+                     var oldRevision   = $page.attr("revision");
+                     var defaultAction = $page.attr("isBinary") == "yes"          ? "uploadFile"
+                                       : $page.attr("type")     == "text/x-rakka" ? "editAsWiki"
+                                       : $page.attr("type")     == "text/css"     ? "editAsCSS"
+                                       :                                            "unknown"
+                                       ;
+                     var source        = $page.find("source").text();
+                     Rakka.displayPageEditor($body, pageName, oldRevision, defaultAction, source);
+                 },
+        error  : function (req) {
+                     if (req.status == 404) {
+                         Rakka.displayPageEditor($body, pageName, null, "editAsWiki");
+                     }
+                     else {
+                         $body.text("Error: " + req.status + " " + req.statusText);
+                     }
+                 }
+        });
+};
+
+Rakka.displayPageEditor = function ($place, pageName, oldRevision, defaultAction, source) {
+    $place.empty();
+
+    var fldPageName
+      = $.INPUT({type : "text", value: pageName});
+
+    var btnEditAsWiki
+      = $.INPUT({type   : "radio",
+                 name   : "action",
+                 checked: (defaultAction == "editAsWiki" ? "checked" : "")});
+
+    var btnEditAsCSS
+      = $.INPUT({type   : "radio",
+                 name   : "action",
+                 checked: (defaultAction == "editAsCSS"  ? "checked" : "")});
+
+    var btnUploadFile
+      = $.INPUT({type   : "radio",
+                 name   : "action",
+                 checked: (defaultAction == "uploadFile" ? "checked" : "")});
+
+    var btnDelete
+      = $.INPUT({type   : "radio",
+                 name   : "action",
+                 checked: ""});
+
+    var pageEditor
+      = $.TABLE({className: "pageEditor"},
+          $.TBODY({},
+            $.TR({},
+              $.TH({}, "Name of the page"),
+              $.TD({}, fldPageName)
+            ),
+            $.TR({},
+              $.TH({}, "Action"),
+              $.TD({},
+                $.UL({},
+                  $.LI({},
+                    $.LABEL({},
+                      btnEditAsWiki,
+                      "Edit as a Wiki page"
+                    )
+                  ),
+                  $.LI({},
+                    $.LABEL({},
+                      btnEditAsCSS,
+                      "Edit as a style sheet"
+                    )
+                  ),
+                  $.LI({},
+                    $.LABEL({},
+                      btnUploadFile,
+                      "Upload a file"
+                    )
+                  ),
+                  (oldRevision != "" && oldRevision != 0
+                     ? $.LI({},
+                         $.LABEL({},
+                           btnDelete,
+                           "Delete this page"
+                         )
+                       )
+                     : [])
+                )
+              )
+            )
+          )
+        );
+
+    $place.append(pageEditor);
+};