]> gitweb @ CieloNegro.org - Rakka.git/commitdiff
preparation for javascripts
authorpho <pho@cielonegro.org>
Sun, 28 Oct 2007 01:14:55 +0000 (10:14 +0900)
committerpho <pho@cielonegro.org>
Sun, 28 Oct 2007 01:14:55 +0000 (10:14 +0900)
darcs-hash:20071028011455-62b54-c3e5018130a8fa923d2fdbfb1a1529af29bcf09a.gz

.boring
Main.hs
Makefile
Rakka.cabal
Rakka/Page.hs
Rakka/Resource/Render.hs
Rakka/Wiki/Engine.hs
Rakka/Wiki/Formatter.hs
Rakka/Wiki/Interpreter/PageList.hs
defaultPages/StyleSheet/Default
js/Makefile [new file with mode: 0644]

diff --git a/.boring b/.boring
index 0a5b28a5da72eaa6824c05dca00a25a9ea942898..d833803d4900b341a5ed67dd594dacce9e29954c 100644 (file)
--- a/.boring
+++ b/.boring
@@ -55,3 +55,7 @@
 ^configure$
 ^dist(/|$)
 ^repos(/|$)
+
+^Rakka/Resource/JavaScript\.hs$
+^js/jquery-
+^js/yuicompressor\.jar$
diff --git a/Main.hs b/Main.hs
index 90a47efd726f7c0e75ae431f24644f2e493ec04a..8027c7ec0978a4caf2aec2cae6ed90cd2c2e3f59 100644 (file)
--- a/Main.hs
+++ b/Main.hs
@@ -6,6 +6,7 @@ import           Network
 import           Network.HTTP.Lucu
 import           Rakka.Environment
 import           Rakka.Resource.Index
+import           Rakka.Resource.JavaScript
 import           Rakka.Resource.Object
 import           Rakka.Resource.Render
 import           Rakka.Storage
@@ -134,6 +135,7 @@ resTree :: Environment -> ResTree
 resTree env
     = mkResTree [ ([]        , resIndex  env)
                 , (["object"], resObject env)
+                , (["js"    ], javaScript   )
                 ]
 
 
index a130eff0418635f3709df1ad69eef0ec620f3bb6..99956d437dc23cd454f3257387863f7fd8cdbc80 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -3,6 +3,7 @@ GHC        = ghc
 EXECUTABLE = sudo ./dist/build/rakka/rakka -p 8989 -l DEBUG
 
 build: .setup-config Setup
+       $(MAKE) -C js $@
        ./Setup build
 
 run: build
index d536f4f22de50cf40dc290468ef89e698b86bc4d..c8b62c10c1020bafe1e4795b654c9c36b4d60d1c 100644 (file)
@@ -23,7 +23,7 @@ Tested-With:
 Build-Depends:
     Crypto, FileManip, HUnit, HsHyperEstraier >= 0.2, HsSVN, Lucu,
     base, encoding, filepath, hslogger, hxt, mtl, network, parsec,
-    stm, unix
+    stm, unix, zlib
 Data-Files:
     defaultpages/Help/SampleImage/Large
     defaultpages/Help/SampleImage/Small
@@ -45,6 +45,7 @@ Other-Modules:
     Rakka.Page
     Rakka.Resource
     Rakka.Resource.Index
+    Rakka.Resource.JavaScript
     Rakka.Resource.Object
     Rakka.Resource.Render
     Rakka.Storage
index 1fd54c92f326ad1e84e348b0452c3d0541c780b4..ec6ce8008209b498afb4064d9560f26e2df4d85c 100644 (file)
@@ -12,6 +12,7 @@ module Rakka.Page
     , mkPageURI
     , mkPageFragmentURI
     , mkObjectURI
+    , mkFragmentURI
     , mkAuxiliaryURI
     , mkRakkaURI
     )
@@ -64,24 +65,29 @@ data Page
 
 -- UTF-8 に encode してから 0x20 - 0x7E の範圍を除いて URI escape する。
 encodePageName :: PageName -> FilePath
-encodePageName = escapeURIString isSafe . C8.unpack . encode UTF8 . fixPageName
+encodePageName = escapeURIString isSafeChar . C8.unpack . encode UTF8 . fixPageName
     where
-      isSafe :: Char -> Bool
-      isSafe c
-          | c == '/'             = True
-          | isReserved c         = False
-          | c >= ' ' && c <= '~' = True
-          | otherwise            = False
-
       fixPageName :: PageName -> PageName
       fixPageName = (\ (x:xs) -> toUpper x : xs) . map (\ c -> if c == ' ' then '_' else c)
 
 
+isSafeChar :: Char -> Bool
+isSafeChar c
+    | c == '/'            = True
+    | isReserved c        = False
+    | c > ' ' && c <= '~' = True
+    | otherwise           = False
+
+
 -- URI unescape して UTF-8 から decode する。
 decodePageName :: FilePath -> PageName
 decodePageName = decode UTF8 . C8.pack . unEscapeString
 
 
+encodeFragment :: String -> String
+encodeFragment = escapeURIString isSafeChar . C8.unpack . encode UTF8
+
+
 pageFileName' :: Page -> String
 pageFileName' page = fromMaybe (defaultFileName page) (pageFileName page)
 
@@ -107,7 +113,14 @@ mkPageFragmentURI :: URI -> PageName -> String -> URI
 mkPageFragmentURI baseURI name fragment
     = baseURI {
         uriPath     = foldl (</>) "/" [uriPath baseURI, encodePageName name ++ ".html"]
-      , uriFragment = ('#':fragment)
+      , uriFragment = ('#' : encodeFragment fragment)
+      }
+
+
+mkFragmentURI :: String -> URI
+mkFragmentURI fragment
+    = nullURI {
+        uriFragment = ('#' : encodeFragment fragment)
       }
 
 
index 66a1516df6f8b1ef2a09ba58dcac441c036baefd..cb01bcd35f3aa5abca2c7da7f97a9b6d47944261 100644 (file)
@@ -70,7 +70,6 @@ handleRedirect env
 
 {-
   <page site="CieloNegro"
-        styleSheet="http://example.org/object/StyleSheet/Default"
         name="Foo/Bar"
         type="text/x-rakka"
         lang="ja"            -- 存在しない場合もある
@@ -82,6 +81,14 @@ handleRedirect env
         revision="112">      -- デフォルトでない場合のみ存在
         lastModified="2000-01-01T00:00:00">
 
+    <styleSheets>
+      <styleSheet src="http://example.org/object/StyleSheet/Default" />
+    </styleSheets>
+
+    <scripts>
+      <script src="http://example.org/js" />
+    </scripts>
+
     <summary>
         blah blah...
     </summary> -- 存在しない場合もある
@@ -143,11 +150,20 @@ entityToXHTML
                      += txt " - "
                      += getXPathTreesInDoc "/page/@name/text()"
                    )
-                += ( eelem "link"
+                += ( getXPathTreesInDoc "/page/styleSheets/styleSheet"
+                     >>>
+                     eelem "link"
                      += sattr "rel"  "stylesheet"
                      += sattr "type" "text/css"
                      += attr "href"
-                            ( getXPathTreesInDoc "/page/@styleSheet/text()" )
+                            ( getXPathTrees "/styleSheet/@src/text()" )
+                   )
+                += ( getXPathTreesInDoc "/page/scripts/script"
+                     >>>
+                     eelem "script"
+                     += sattr "type" "text/javascript"
+                     += attr "src"
+                            ( getXPathTrees "/script/@src/text()" )
                    )
               )
            += ( eelem "body"
index afbc610ab0f1497ec94f9b9b8991fb819049c7c2..0f18fb1187fe3df6e3c2733441314b4116af9551 100644 (file)
@@ -53,7 +53,6 @@ formatEntirePage sto sysConf interpTable
           tree <- ( eelem "/"
                     += ( eelem "page"
                          += sattr "site"       siteName
-                         += sattr "styleSheet" (uriToString id (mkObjectURI baseURI cssName) "")
                          += sattr "name"       (pageName page)
                          += sattr "type"       (show $ pageType page)
                          += ( case pageLanguage page of
@@ -80,6 +79,18 @@ formatEntirePage sto sysConf interpTable
                          += 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
index 3f0960604887663d1a479719339d0d8a480339bb..1c3abe549d2a2445d22bd799fc15d1cf38c043a5 100644 (file)
@@ -229,7 +229,7 @@ formatPageLink
     -> let uri    = case (page, fragment) of
                       (Just  x, Just  y) -> mkPageFragmentURI baseURI x y
                       (Just  x, Nothing) -> mkPageURI baseURI x
-                      (Nothing, Just  y) -> nullURI { uriFragment = ('#':y) }
+                      (Nothing, Just  y) -> mkFragmentURI y
            href   = uriToString id uri ""
            dLabel = fromMaybe "" page ++ fromMaybe "" (fmap ('#':) fragment)
            label  = fromMaybe dLabel text
index 2a10372d1b4e253c6cf174e11cb2ca7d2236e1c1..69ff0e72ee9697f1a913c892f786bddcecf65381 100644 (file)
@@ -20,7 +20,7 @@ interpreters = [ recentUpdatesInterp ]
 --   <ul>
 --     <li>
 --       <a href="...">...</a>
---       <span class="date">...</span>
+--       <div class="date">...</div>
 --       <p> <!-- サマリが無ければ存在しない -->
 --         blah blah...
 --       </p>
@@ -65,9 +65,9 @@ recentUpdatesInterp
                        , linkText     = Nothing
                        }
                     )
-            , Inline ( Span [("class", "date")]
-                                [Text (formatRFC1123DateTime (pageLastMod page))]
-                     )
+            , Block ( Div [("class", "date")]
+                              [Inline (Text (formatRFC1123DateTime (pageLastMod page)))]
+                    )
             ]
             ++
             case pageSummary page of
index 562e02b3a77e09535c6b523684c1df03dfa49d75..b2c369359fc38eb7a1f59c640d2fa5e3bd2ace05 100644 (file)
     margin-top: 1.2em;
 }
 
+.sideBar .date {
+    padding: 0.2em 0 0 0;
+}
+
 /* color and text *************************************************************/
 * {
     font-family: sans-serif;
diff --git a/js/Makefile b/js/Makefile
new file mode 100644 (file)
index 0000000..a5c163b
--- /dev/null
@@ -0,0 +1,29 @@
+SOURCES = \
+       jquery-1.2.1.js \
+       $(NULL)
+
+
+build: ../Rakka/Resource/JavaScript.hs
+
+
+../Rakka/Resource/JavaScript.hs: $(SOURCES) yuicompressor.jar
+       cat $(SOURCES) > tmp.js
+       java -jar yuicompressor.jar --type js --charset UTF-8 -o tmp.packed.js --warn tmp.js
+       lucu-implant-file -o $@ -m Rakka.Resource.JavaScript -t text/javascript tmp.packed.js
+       rm tmp.js tmp.packed.js
+
+
+jquery-%.js:
+       @echo "Error: $@ has to be placed on this directory."
+       @echo "       See http://jquery.com/"
+       @exit 1
+
+
+clean:
+       rm -f ../Rakka/Resource/JavaScript.hs
+
+
+yuicompressor.jar:
+       @echo "Error: yuicompressor.jar has to be placed on this directory."
+       @echo "       See http://www.julienlecomte.net/yuicompressor/"
+       @exit 1