Permalink
Browse files

yesod 1.1

  • Loading branch information...
snoyberg committed Jul 8, 2012
1 parent 6f528af commit 85e0fde05163193e99c4f704ba50cdeabcb56083
Showing with 13,248 additions and 496 deletions.
  1. +53 −45 Application.hs
  2. +114 −130 Foundation.hs
  3. +3 −6 Handler/Admin.hs
  4. +2 −2 Handler/Bling.hs
  5. +2 −2 Handler/Email.hs
  6. +2 −3 Handler/Faq.hs
  7. +5 −10 Handler/Job.hs
  8. +5 −5 Handler/News.hs
  9. +1 −1 Handler/Package.hs
  10. +1 −1 Handler/Poll.hs
  11. +3 −5 Handler/Profile.hs
  12. +5 −4 Handler/Root.hs
  13. +3 −5 Handler/Skills.hs
  14. +11 −13 Handler/Team.hs
  15. +3 −5 Handler/Topic.hs
  16. +5 −10 Handler/User.hs
  17. +34 −0 Import.hs
  18. +1 −1 LICENSE
  19. +10 −14 Model.hs
  20. +55 −115 Settings.hs
  21. +14 −0 Settings/Development.hs
  22. +18 −0 Settings/StaticFiles.hs
  23. BIN config/favicon.ico
  24. +4 −0 config/keter.yaml
  25. +116 −0 config/models
  26. +24 −0 config/postgresql.yml
  27. +1 −0 config/robots.txt
  28. +91 −0 config/routes
  29. +19 −0 config/settings.yml
  30. +116 −87 haskellers.cabal
  31. +6 −29 main.hs
  32. BIN static/img/glyphicons-halflings-white.png
  33. BIN static/img/glyphicons-halflings.png
  34. 0 {cassius → templates}/admin-controls.cassius
  35. 0 {hamlet → templates}/admin-controls.hamlet
  36. 0 {cassius → templates}/admin-users.cassius
  37. 0 {hamlet → templates}/admin-users.hamlet
  38. 0 {julius → templates}/admin-users.julius
  39. 0 {julius → templates}/analytics.julius
  40. 0 {cassius → templates}/bling.cassius
  41. 0 {hamlet → templates}/bling.hamlet
  42. +48 −0 templates/default-layout-wrapper.hamlet
  43. 0 {cassius → templates}/default-layout.cassius
  44. 0 {hamlet → templates}/default-layout.hamlet
  45. 0 {julius → templates}/default-layout.julius
  46. 0 {cassius → templates}/faq.cassius
  47. 0 {hamlet → templates}/faq.hamlet
  48. 0 {cassius → templates}/flag.cassius
  49. 0 {hamlet → templates}/flag.hamlet
  50. 0 {cassius → templates}/homepage.cassius
  51. 0 {hamlet → templates}/homepage.hamlet
  52. 0 {julius → templates}/homepage.julius
  53. 0 {cassius → templates}/job.cassius
  54. 0 {hamlet → templates}/job.hamlet
  55. 0 {cassius → templates}/jobs.cassius
  56. 0 {hamlet → templates}/jobs.hamlet
  57. 0 {cassius → templates}/login-status.cassius
  58. 0 {hamlet → templates}/login-status.hamlet
  59. 0 {hamlet → templates}/login.hamlet
  60. 0 {cassius → templates}/messages.cassius
  61. 0 {hamlet → templates}/messages.hamlet
  62. 0 {hamlet → templates}/navbar-section.hamlet
  63. 0 {cassius → templates}/news-admin.cassius
  64. 0 {hamlet → templates}/news-item.hamlet
  65. 0 {cassius → templates}/news.cassius
  66. 0 {hamlet → templates}/news.hamlet
  67. +439 −0 templates/normalize.lucius
  68. 0 {hamlet → templates}/poll.hamlet
  69. 0 {lucius → templates}/poll.lucius
  70. 0 {hamlet → templates}/polls.hamlet
  71. 0 {cassius → templates}/profile.cassius
  72. 0 {hamlet → templates}/profile.hamlet
  73. 0 {julius → templates}/profile.julius
  74. 0 {hamlet → templates}/skill.hamlet
  75. 0 {cassius → templates}/skills.cassius
  76. 0 {hamlet → templates}/skills.hamlet
  77. 0 {hamlet → templates}/team-form.hamlet
  78. 0 {cassius → templates}/team.cassius
  79. 0 {hamlet → templates}/team.hamlet
  80. 0 {hamlet → templates}/teams-form.hamlet
  81. 0 {cassius → templates}/teams.cassius
  82. 0 {hamlet → templates}/teams.hamlet
  83. 0 {cassius → templates}/topic.cassius
  84. 0 {hamlet → templates}/topic.hamlet
  85. 0 {cassius → templates}/topics.cassius
  86. 0 {hamlet → templates}/topics.hamlet
  87. 0 {cassius → templates}/user.cassius
  88. 0 {hamlet → templates}/user.hamlet
  89. 0 {julius → templates}/user.julius
  90. 0 {cassius → templates}/users.cassius
  91. 0 {hamlet → templates}/users.hamlet
  92. +135 −0 tests/Application.hs
  93. +592 −0 tests/Foundation.hs
  94. +90 −0 tests/Handler/Admin.hs
  95. +12 −0 tests/Handler/Bling.hs
  96. +95 −0 tests/Handler/Email.hs
  97. +46 −0 tests/Handler/Faq.hs
  98. +106 −0 tests/Handler/Job.hs
  99. +91 −0 tests/Handler/News.hs
  100. +30 −0 tests/Handler/Package.hs
  101. +120 −0 tests/Handler/Poll.hs
  102. +311 −0 tests/Handler/Profile.hs
  103. +230 −0 tests/Handler/Root.hs
  104. +81 −0 tests/Handler/Skills.hs
  105. +320 −0 tests/Handler/Team.hs
  106. +167 −0 tests/Handler/Topic.hs
  107. +172 −0 tests/Handler/User.hs
  108. +24 −0 tests/HomeTest.hs
  109. +34 −0 tests/Import.hs
  110. +25 −0 tests/LICENSE
  111. +51 −0 tests/Model.hs
  112. +89 −0 tests/Settings.hs
  113. +14 −0 tests/Settings/Development.hs
  114. +18 −0 tests/Settings/StaticFiles.hs
  115. BIN tests/config/favicon.ico
  116. +4 −0 tests/config/keter.yaml
  117. +116 −0 tests/config/models
  118. +24 −0 tests/config/postgresql.yml
  119. +1 −0 tests/config/robots.txt
  120. +91 −0 tests/config/routes
  121. +19 −0 tests/config/settings.yml
  122. +97 −0 tests/deploy/Procfile
  123. +26 −0 tests/devel.hs
  124. +135 −0 tests/haskellers.cabal
  125. +8 −0 tests/main.hs
  126. +26 −0 tests/messages/en.msg
  127. +2 −0 tests/messages/he.msg
  128. +21 −0 tests/messages/ja.msg
  129. +26 −0 tests/messages/ru.msg
  130. +26 −0 tests/messages/ua.msg
  131. BIN tests/static/background.png
  132. BIN tests/static/badge.png
  133. BIN tests/static/bling/monads-in-disguise.png
  134. BIN tests/static/browserid.png
  135. BIN tests/static/buttons.png
  136. +3,990 −0 tests/static/css/bootstrap.css
  137. BIN tests/static/facebook.gif
  138. BIN tests/static/google.gif
  139. BIN tests/static/hslogo_16.png
  140. BIN tests/static/images/ui-bg_diagonals-thick_65_a6a6a6_40x40.png
  141. BIN tests/static/images/ui-bg_diagonals-thick_75_f3d8d8_40x40.png
  142. BIN tests/static/images/ui-bg_dots-small_65_a6a6a6_2x2.png
  143. BIN tests/static/images/ui-bg_flat_0_333333_40x100.png
  144. BIN tests/static/images/ui-bg_flat_0_aaaaaa_40x100.png
  145. BIN tests/static/images/ui-bg_flat_100_506982_40x100.png
  146. BIN tests/static/images/ui-bg_flat_100_e5eef9_40x100.png
  147. BIN tests/static/images/ui-bg_flat_100_fafafa_40x100.png
  148. BIN tests/static/images/ui-bg_flat_10_333333_40x100.png
  149. BIN tests/static/images/ui-bg_flat_15_2a2d38_40x100.png
  150. BIN tests/static/images/ui-bg_flat_50_e5eef9_40x100.png
  151. BIN tests/static/images/ui-bg_flat_65_506982_40x100.png
  152. BIN tests/static/images/ui-bg_flat_75_506982_40x100.png
  153. BIN tests/static/images/ui-bg_flat_75_ffffff_40x100.png
  154. BIN tests/static/images/ui-bg_glass_55_fbf8ee_1x400.png
  155. BIN tests/static/images/ui-bg_glass_55_fbf9ee_1x400.png
  156. BIN tests/static/images/ui-bg_glass_65_ffffff_1x400.png
  157. BIN tests/static/images/ui-bg_glass_75_dadada_1x400.png
  158. BIN tests/static/images/ui-bg_glass_75_e6e6e6_1x400.png
  159. BIN tests/static/images/ui-bg_glass_95_fef1ec_1x400.png
  160. BIN tests/static/images/ui-bg_glow-ball_60_506982_600x600.png
  161. BIN tests/static/images/ui-bg_highlight-soft_75_cccccc_1x100.png
  162. BIN tests/static/images/ui-icons_004276_256x240.png
  163. BIN tests/static/images/ui-icons_222222_256x240.png
  164. BIN tests/static/images/ui-icons_2a2d38_256x240.png
  165. BIN tests/static/images/ui-icons_2e83ff_256x240.png
  166. BIN tests/static/images/ui-icons_454545_256x240.png
  167. BIN tests/static/images/ui-icons_4b5057_256x240.png
  168. BIN tests/static/images/ui-icons_888888_256x240.png
  169. BIN tests/static/images/ui-icons_cc0000_256x240.png
  170. BIN tests/static/images/ui-icons_cd0a0a_256x240.png
  171. BIN tests/static/images/ui-icons_dbedff_256x240.png
  172. BIN tests/static/images/ui-icons_fafafa_256x240.png
  173. BIN tests/static/images/ui-icons_ffffff_256x240.png
  174. BIN tests/static/img/glyphicons-halflings-white.png
  175. BIN tests/static/img/glyphicons-halflings.png
  176. +96 −0 tests/static/jquery-cookie.js
  177. +572 −0 tests/static/jquery-ui.css
  178. BIN tests/static/logo.png
  179. BIN tests/static/openid-icon-small.gif
  180. BIN tests/static/openid.gif
  181. +53 −0 tests/static/reset.css
  182. +385 −0 tests/static/tmp/1FeJJ045.css
  183. +1 −0 tests/static/tmp/1tiBEplC.js
  184. +465 −0 tests/static/tmp/4v_LoG7D.css
  185. +2 −0 tests/static/tmp/GdF0ULLk.js
  186. +1 −0 tests/static/tmp/Vr2Vi3z6.js
  187. +370 −0 tests/static/tmp/YqZ5RxCQ.css
  188. +463 −0 tests/static/tmp/myAOxsSB.css
  189. BIN tests/static/yahoo.gif
  190. +4 −0 tests/templates/admin-controls.cassius
  191. +25 −0 tests/templates/admin-controls.hamlet
  192. +7 −0 tests/templates/admin-users.cassius
  193. +26 −0 tests/templates/admin-users.hamlet
  194. +3 −0 tests/templates/admin-users.julius
  195. +10 −0 tests/templates/analytics.julius
  196. +6 −0 tests/templates/bling.cassius
  197. +13 −0 tests/templates/bling.hamlet
  198. +48 −0 tests/templates/default-layout-wrapper.hamlet
  199. +289 −0 tests/templates/default-layout.cassius
  200. +87 −0 tests/templates/default-layout.hamlet
  201. +27 −0 tests/templates/default-layout.julius
  202. +28 −0 tests/templates/faq.cassius
  203. +9 −0 tests/templates/faq.hamlet
  204. +3 −0 tests/templates/flag.cassius
  205. +14 −0 tests/templates/flag.hamlet
  206. +6 −0 tests/templates/homepage.cassius
  207. +25 −0 tests/templates/homepage.hamlet
  208. +23 −0 tests/templates/homepage.julius
  209. +20 −0 tests/templates/job.cassius
  210. +37 −0 tests/templates/job.hamlet
  211. +15 −0 tests/templates/jobs.cassius
  212. +37 −0 tests/templates/jobs.hamlet
  213. +9 −0 tests/templates/login-status.cassius
  214. +13 −0 tests/templates/login-status.hamlet
  215. +17 −0 tests/templates/login.hamlet
  216. +4 −0 tests/templates/messages.cassius
  217. +25 −0 tests/templates/messages.hamlet
  218. +6 −0 tests/templates/navbar-section.hamlet
  219. +18 −0 tests/templates/news-admin.cassius
  220. +12 −0 tests/templates/news-item.hamlet
  221. +5 −0 tests/templates/news.cassius
  222. +15 −0 tests/templates/news.hamlet
  223. +439 −0 tests/templates/normalize.lucius
  224. +40 −0 tests/templates/poll.hamlet
  225. +4 −0 tests/templates/poll.lucius
  226. +19 −0 tests/templates/polls.hamlet
  227. +69 −0 tests/templates/profile.cassius
  228. +180 −0 tests/templates/profile.hamlet
  229. +42 −0 tests/templates/profile.julius
  230. +4 −0 tests/templates/skill.hamlet
  231. +7 −0 tests/templates/skills.cassius
  232. +27 −0 tests/templates/skills.hamlet
  233. +6 −0 tests/templates/team-form.hamlet
  234. +5 −0 tests/templates/team.cassius
  235. +111 −0 tests/templates/team.hamlet
  236. +6 −0 tests/templates/teams-form.hamlet
  237. +3 −0 tests/templates/teams.cassius
  238. +14 −0 tests/templates/teams.hamlet
  239. +25 −0 tests/templates/topic.cassius
  240. +38 −0 tests/templates/topic.hamlet
  241. 0 tests/templates/topics.cassius
  242. +28 −0 tests/templates/topics.hamlet
  243. +47 −0 tests/templates/user.cassius
  244. +69 −0 tests/templates/user.hamlet
  245. +7 −0 tests/templates/user.julius
  246. +55 −0 tests/templates/users.cassius
  247. +28 −0 tests/templates/users.hamlet
  248. +2 −3 upload.sh
View
@@ -1,31 +1,29 @@
-{-# LANGUAGE TemplateHaskell #-}
-{-# LANGUAGE MultiParamTypeClasses #-}
-{-# LANGUAGE OverloadedStrings #-}
-{-# LANGUAGE CPP #-}
-{-# LANGUAGE TypeFamilies #-}
{-# OPTIONS_GHC -fno-warn-orphans #-}
module Application
- ( getApplication
+ ( makeApplication
, getApplicationDev
+ , makeFoundation
) where
-import Foundation hiding (approot)
+import Import
import Settings
-import Yesod.Static
import Yesod.Auth
-import Database.Persist.GenericSql
+import Yesod.Default.Config
+import Yesod.Default.Main
+import Yesod.Default.Handlers
+import Network.Wai.Middleware.RequestLogger (logStdout, logStdoutDev)
+import qualified Database.Persist.Store
+import Database.Persist.GenericSql (runMigration)
+import Network.HTTP.Conduit (newManager, def)
import Data.IORef
-import Data.Text (Text)
-#if PRODUCTION
-import Control.Concurrent (forkIO, threadDelay)
-import Control.Monad (forever)
-#endif
-import Data.Maybe (catMaybes)
+import Control.Monad
+import Control.Concurrent
+import Database.Persist.GenericSql
+import Data.Maybe
import qualified Data.Set as Set
-import Data.ByteString (ByteString)
-import Network.HTTP.Conduit (newManager, def)
-- Import all relevant handler modules here.
+-- Don't forget to add new modules to your cabal file!
import Handler.Root
import Handler.Profile
import Handler.User
@@ -42,46 +40,56 @@ import Handler.Bling
import Handler.Poll
-- This line actually creates our YesodSite instance. It is the second half
--- of the call to mkYesodData which occurs in Haskellers.hs. Please see
+-- of the call to mkYesodData which occurs in Foundation.hs. Please see
-- the comments there for more details.
-mkYesodDispatch "Haskellers" resourcesHaskellers
-
--- Some default handlers that ship with the Yesod site template. You will
--- very rarely need to modify this.
-getFaviconR :: Handler ()
-getFaviconR = sendFile "image/x-icon" "favicon.ico"
-
-getRobotsR :: Handler RepPlain
-getRobotsR = return $ RepPlain $ toContent ("User-agent: *" :: ByteString)
+mkYesodDispatch "App" resourcesApp
-- This function allocates resources (such as a database connection pool),
-- performs initialization and creates a WAI application. This is also the
-- place to put your migrate statements to have automatic database
-- migrations handled by Yesod.
-getApplication :: Text -> IO Application
-getApplication approot = do
- p <- Settings.createConnectionPool
+makeApplication :: AppConfig DefaultEnv Extra -> IO Application
+makeApplication conf = do
+ foundation <- makeFoundation conf
+ app <- toWaiAppPlain foundation
+ return $ logWare app
+ where
+ logWare = if development then logStdoutDev
+ else logStdout
+
+makeFoundation :: AppConfig DefaultEnv Extra -> IO App
+makeFoundation conf = do
manager <- newManager def
- flip runConnectionPool p $ runMigration migrateAll
+ s <- staticSite
+ dbconf <- withYamlEnvironment "config/postgresql.yml" (appEnv conf)
+ Database.Persist.Store.loadConfig >>=
+ Database.Persist.Store.applyEnv
+ p <- Database.Persist.Store.createPoolConfig (dbconf :: Settings.PersistConfig)
+ Database.Persist.Store.runPool dbconf (runMigration migrateAll) p
+
hprofs <- newIORef ([], 0)
pprofs <- newIORef []
-#if PRODUCTION
- _ <- forkIO $ forever $ fillProfs p hprofs pprofs
- >> threadDelay (1000 * 1000 * 60 * 5)
-#else
- fillProfs p hprofs pprofs
-#endif
- s' <- s
- let h = Haskellers s' p hprofs pprofs approot manager
- toWaiApp h
- where
- s = static Settings.staticdir
+ if production
+ then do
+ _ <- forkIO $ forever $ do
+ _ <- fillProfs p hprofs pprofs
+ threadDelay (1000 * 1000 * 60 * 5)
+ return ()
+ else fillProfs p hprofs pprofs
+
+ return $ App conf s p manager dbconf hprofs pprofs
+-- for yesod devel
getApplicationDev :: IO (Int, Application)
-getApplicationDev = ((,) 3000) `fmap` getApplication "http://localhost:3000"
+getApplicationDev =
+ defaultDevelApp loader makeApplication
+ where
+ loader = loadConfig (configSettings Development)
+ { csParseExtra = parseExtra
+ }
getHomepageProfs :: ConnectionPool -> IO [Profile]
-getHomepageProfs pool = flip runConnectionPool pool $ do
+getHomepageProfs pool = flip runSqlPool pool $ do
users <-
selectList [ UserVerifiedEmail ==. True
, UserVisible ==. True
@@ -92,7 +100,7 @@ getHomepageProfs pool = flip runConnectionPool pool $ do
fmap catMaybes $ mapM userToProfile users
getPublicProfs :: ConnectionPool -> IO [Profile]
-getPublicProfs pool = flip runConnectionPool pool $ do
+getPublicProfs pool = flip runSqlPool pool $ do
users <-
selectList [ UserVerifiedEmail ==. True
, UserVisible ==. True
Oops, something went wrong.

0 comments on commit 85e0fde

Please sign in to comment.