わかった気になるわかった気になる  gitit-0.8  gitit-0.8   初心者Haskell勉強会  Kiwamu Okabe
1/12ルーティング
2/12   monadplushandlerをmplusで結合してるだけに見えます。失敗はmzeroになるんですが、成功した場合には次のhandlerを実行してほしくないように見えるのですが、、、そーゆーもの???
3/12ページ表示indexPage :: HandlerindexPage = do  path <- getPath  base <- getWikiBase  let prefix = if null path then "" else ...
4/12              gitアクセス                                                                                (*1) getFileStore...
5/12         認証authenticateUserThat predicate level handler = do  cfg <- getConfig  if level <= requireAuthentication cfg ...
6/12          gititプラグイン#1    gitit/Network/Gitit/Plugins.hs                                                (*2) がプラグイン読み込...
7/12       gititプラグイン#2loadPlugin :: FilePath -> IO PluginloadPlugin pluginName = do--snip--      pr <- findModule (mkModu...
8/12        ghc7だと動かない$ ghc --versionThe Glorious Glasgow Haskell Compilation System, version 6.12.1$ gitit -f default.con...
9/12plugins良いらしい
10/12     plugins使い方#1API.hs     module API where     data Test = Test {                     field :: String            } ...
11/12     plugins使い方#2Test.hs module Test where import API resource = test { field = "success" }
12/12    plugins使い方#3Main.hs     import System.Plugins     import API     main = do             m_v <- load_ "../Test.o" [...
Upcoming SlideShare
Loading in …5
×

わかった気になるgitit-0.8

2,158 views

Published on

初心者Haskell勉強会第4回 - [PARTAKE] http://partake.in/events/8ccdc151-b758-47af-9ff2-91216bd5d3c4

0 Comments
4 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
2,158
On SlideShare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
5
Comments
0
Likes
4
Embeds 0
No embeds

No notes for slide

わかった気になるgitit-0.8

  1. 1. わかった気になるわかった気になる gitit-0.8 gitit-0.8 初心者Haskell勉強会 Kiwamu Okabe
  2. 2. 1/12ルーティング
  3. 3. 2/12 monadplushandlerをmplusで結合してるだけに見えます。失敗はmzeroになるんですが、成功した場合には次のhandlerを実行してほしくないように見えるのですが、、、そーゆーもの???
  4. 4. 3/12ページ表示indexPage :: HandlerindexPage = do path <- getPath base <- getWikiBase let prefix = if null path then "" else path ++ "/" fs <- getFileStore listing <- liftIO $ directory fs prefix let isDiscussionPage (FSFile f) = isDiscussPageFile f isDiscussionPage (FSDirectory _) = False let prunedListing = filter (not . isDiscussionPage) listing let htmlIndex = fileListToHtml base prefix prunedListing formattedPage defaultPageLayout{ pgPageName = prefix, pgShowPageTools = False, pgTabs = [], pgScripts = [], pgTitle = "Contents"} htmlIndex
  5. 5. 4/12 gitアクセス (*1) getFileStoreでFileStoreを呼出 randomPage :: Handler randomPage = do fs <- getFileStore files <- liftIO $ index fs let pages = map dropExtension $ filter (f -> isPageFile f && not (isDiscussPageFile f)) files base <- getWikiBase if null pages then error "No pages found!"(*1)http://hackage.haskell.org/packages/archive/filestore/latest/doc/html/Data-FileStore-Types.html
  6. 6. 5/12 認証authenticateUserThat predicate level handler = do cfg <- getConfig if level <= requireAuthentication cfg then do mbUser <- getLoggedInUser rq <- askRq let url = rqUri rq ++ rqQuery rq case mbUser of Nothing -> tempRedirect ("/_login?" ++ urlEncodeVars [("destination", url)]) $ toResponse () Just u -> if predicate u then handler else error "Not authorized." else handler
  7. 7. 6/12 gititプラグイン#1 gitit/Network/Gitit/Plugins.hs (*2) がプラグイン読み込みコード。(*2)詳細は http://www.bluishcoder.co.nz/2008/11/dynamic-compilation-and-loading-of.html を参照
  8. 8. 7/12 gititプラグイン#2loadPlugin :: FilePath -> IO PluginloadPlugin pluginName = do--snip-- pr <- findModule (mkModuleName "Prelude") Nothing i <- findModule (mkModuleName "Network.Gitit.Interface") Nothing m <- findModule (mkModuleName modName) Nothing setContext []#if MIN_VERSION_ghc(7,0,0) [(m, Nothing), (i, Nothing), (pr, Nothing)]#else [m, i, pr]#endif value <- compileExpr (modName ++ ".plugin :: Plugin") let value = (unsafeCoerce value) :: Plugin return value
  9. 9. 8/12 ghc7だと動かない$ ghc --versionThe Glorious Glasgow Haskell Compilation System, version 6.12.1$ gitit -f default.confLoading plugin plugins/TwitterUrl.hs...Finished loading plugins.$ ghc --versionThe Glorious Glasgow Haskell Compilation System, version 7.0.3$ gitit -f default.confLoading plugin plugins/TwitterUrl.hs...gitit: This ELF file contains no symtabgitit: gitit: panic! (the impossible happened) (GHC version 7.0.3 for x86_64-unknown-linux): loadArchive "/usr/lib/ghc-7.0.3/ghc-7.0.3/libHSghc-7.0.3.a": failedPlease report this as a GHC bug: http://www.haskell.org/ghc/reportabug
  10. 10. 9/12plugins良いらしい
  11. 11. 10/12 plugins使い方#1API.hs module API where data Test = Test { field :: String } test :: Test test = Test { field = "default value" }
  12. 12. 11/12 plugins使い方#2Test.hs module Test where import API resource = test { field = "success" }
  13. 13. 12/12 plugins使い方#3Main.hs import System.Plugins import API main = do m_v <- load_ "../Test.o" ["../api"] "resource" v <- case m_v of LoadFailure _ -> error "load failed" LoadSuccess _ v -> return v let s = field v print s -- => "success"と表示

×