1. John Lenz
  2. notmuch-web


John Lenz  committed 3d6bd64

Cleanup/linting to foundation code

  • Participants
  • Parent commits 47aa6db
  • Branches default

Comments (0)

Files changed (5)

File config/routes

View file
 /                               HomeR GET
 /search                         SearchPostR POST
 /search/#String                 SearchR GET
-/retag/thread/#ThreadID/#T.Text RetagThreadR POST
+/retag/thread/#ThreadID/#Text RetagThreadR POST
 /customretag/thread/#ThreadID   CustomRetagThreadR POST
 /thread/#ThreadID                 ThreadR GET
-/retag/message/#MessageID/#T.Text RetagMessageR POST
+/retag/message/#MessageID/#Text RetagMessageR POST
 /customretag/message/#MessageID   CustomRetagMessageR POST
 /messagepart/#MessageID/#Int      MessagePartR GET

File src/Application.hs

View file
 import Handler.Raw
 import Handler.Compose
--- This line actually creates our YesodDispatch instance. It is the second half
--- of the call to mkYesodData which occurs in Foundation.hs. Please see the
--- comments there for more details.
 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.
 makeApplication :: AppConfig DefaultEnv Extra -> IO Application
 makeApplication conf = do
     foundation <- makeFoundation conf

File src/Foundation.hs

View file
 module Foundation where
 import Prelude
+import Blaze.ByteString.Builder.Char.Utf8 (fromText)
+import Control.Applicative
+import Data.ByteString (ByteString)
+import Data.Maybe (isJust)
+import Data.Monoid (mappend)
+import Data.Text (Text)
+import Data.Text.Encoding (encodeUtf8)
+import Network.HTTP.Conduit (Manager)
+import Network.Wai (requestHeaders)
+import NotmuchCmd (ThreadID, MessageID)
+import Settings (widgetFile, Extra (..), development)
+import StaticFiles
+import Text.Hamlet (hamletFile)
+import Text.Jasmine (minifym)
 import Yesod
 import Yesod.Auth
-import Yesod.Static
 import Yesod.Default.Config
 import Yesod.Default.Util (addStaticContentExternal)
-import Network.HTTP.Conduit (Manager)
-import Data.Monoid (mappend)
-import qualified Settings
-import StaticFiles
-import Settings (widgetFile, Extra (..))
-import Network.Wai (requestHeaders)
-import Data.Maybe (isJust)
-import Text.Jasmine (minifym)
-import Text.Hamlet (hamletFile)
-import NotmuchCmd (ThreadID, MessageID)
-import Control.Applicative
-import Blaze.ByteString.Builder.Char.Utf8 (fromText)
-import Data.Text (Text)
+import Yesod.Static
 import qualified Crypto.PasswordStore as PS
-import qualified Data.ByteString as B
-import qualified Data.Text as T
-import qualified Data.Text.Encoding as T
--- | The site argument for your application. This can be a good place to
--- keep settings and values requiring initialization before your application
--- starts running, such as database connections. Every handler will have
--- access to the data present here.
 data App = App
     { settings :: AppConfig DefaultEnv Extra
     , getStatic :: Static -- ^ Settings for static file serving.
     , httpManager :: Manager
-    , passwordHash :: B.ByteString -- ^ hashed password from "Crypto.PasswordStore"
+    , passwordHash :: ByteString -- ^ hashed password from "Crypto.PasswordStore"
--- Set up i18n messages. See the message folder.
 mkMessage "App" "messages" "en"
--- This is where we define all of the routes in our application. For a full
--- explanation of the syntax, please see:
--- http://www.yesodweb.com/book/handler
--- This function does three things:
--- * Creates the route datatype AppRoute. Every valid URL in your
---   application can be represented as a value of this type.
--- * Creates the associated type:
---       type instance Route App = AppRoute
--- * Creates the value resourcesApp which contains information on the
---   resources declared below. This is used in Handler.hs by the call to
---   mkYesodDispatch
--- What this function does *not* do is create a YesodSite instance for
--- App. Creating that instance requires all of the handler functions
--- for our application to be in scope. However, the handler functions
--- usually require access to the AppRoute datatype. Therefore, we
--- split these actions into two functions and place them in separate files.
 mkYesodData "App" $(parseRoutesFile "config/routes")
 type Form x = Html -> MForm (HandlerT App IO) (FormResult x, Widget)
--- Please see the documentation for the Yesod typeclass. There are a number
--- of settings which can be configured by overriding methods here.
 instance Yesod App where
     approot = ApprootMaster $ appRoot . settings
                   hamletToRepHtml $(hamletFile "templates/default-layout-wrapper.hamlet")
-    -- This is done to provide an optimization for serving static files from
-    -- a separate domain. Please see the staticRoot setting in Settings.hs
-    urlRenderOverride y (StaticR s) =
-        Just $ uncurry (joinPath y (Settings.staticRoot $ settings y)) $ renderRoute s
     -- The opensearch.xml file must include {searchTerms} in the url template, but
     -- the default url renderer percent encodes the braces which doesn't work.  So we
     -- need to directly render just this single example, leaving the rest of the search
     -- and names them based on a hash of their content. This allows
     -- expiration dates to be set far in the future without worry of
     -- users receiving stale content.
-    addStaticContent = addStaticContentExternal mini base64md5 Settings.staticDir (StaticR . flip StaticRoute [])
-      where mini = if Settings.development then Right else minifym
+    addStaticContent = addStaticContentExternal mini base64md5 "static" (StaticR . flip StaticRoute [])
+      where mini = if development then Right else minifym
     -- Place Javascript at bottom of the body tag so the rest of the page loads first
     jsLoader _ = BottomOfBody
     -- What messages should be logged. The following includes all messages when
     -- in development, and warnings and errors in production.
     shouldLog _ _source level =
-        Settings.development || level == LevelWarn || level == LevelError
+        development || level == LevelWarn || level == LevelError
--- This instance is required to use forms. You can modify renderMessage to
--- achieve customized and internationalized form validation messages.
 instance RenderMessage App FormMessage where
     renderMessage _ _ = defaultFormMessage
 isPjax = do r <- waiRequest
             return $ isJust $ lookup "X-PJAX" $ requestHeaders r
-loginForm :: AForm (HandlerT App IO) B.ByteString
-loginForm = T.encodeUtf8 <$> areq passwordField pwd Nothing
+loginForm :: AForm (HandlerT App IO) ByteString
+loginForm = encodeUtf8 <$> areq passwordField pwd Nothing
   where pwd = FieldSettings (SomeMessage MsgPassword) Nothing (Just "Password") Nothing []
 instance YesodAuth App where
-    type AuthId App = T.Text
+    type AuthId App = Text
     loginDest _  = HomeR
     logoutDest _ = HomeR
     getAuthId (Creds _ n _) = return $ Just n

File src/Settings.hs

View file
 along with this program.  If not, see <http://www.gnu.org/licenses/>.
--- | Settings are centralized, as much as possible, into this file. This
--- includes database connection settings, static file locations, etc.
--- In addition, you can configure a number of different aspects of Yesod
--- by overriding methods in the Yesod typeclass. That instance is
--- declared in the Foundation.hs file.
 module Settings where
 import Prelude
+import Control.Applicative
 import Data.Aeson
-import Text.Shakespeare.Text (st)
-import Language.Haskell.TH.Syntax
+import Data.ByteString (ByteString)
+import Data.Default (def)
+import Data.Maybe (fromMaybe)
+import Data.Text (Text)
+import Data.Text.Encoding (encodeUtf8)
+import Data.Yaml
+import Language.Haskell.TH.Syntax (Q, Exp)
+import Text.Hamlet
 import Yesod.Default.Config
 import Yesod.Default.Util
-import Data.Text (Text)
-import qualified Data.Text.Encoding as TE
-import Data.ByteString (ByteString)
-import Data.Yaml
-import Control.Applicative
-import Data.Default (def)
-import Text.Hamlet
--- Static setting below. Changing these requires a recompile
--- | The location of static files on your system. This is a file system
--- path. The default value works properly with your scaffolded site.
-staticDir :: FilePath
-staticDir = "static"
--- | The base URL for your static files. As you can see by the default
--- value, this can simply be "static" appended to your application root.
--- A powerful optimization can be serving static files from a separate
--- domain name. This allows you to use a web server optimized for static
--- files, more easily set expires and cache values, and avoid possibly
--- costly transference of cookies on static files. For more information,
--- please see:
---   http://code.google.com/speed/page-speed/docs/request.html#ServeFromCookielessDomain
--- If you change the resource pattern for StaticR in Foundation.hs, you will
--- have to make a corresponding change here.
--- To see how this value is used, see urlRenderOverride in Foundation.hs
-staticRoot :: AppConfig DefaultEnv x -> Text
-staticRoot conf = [st|#{appRoot conf}/static|]
--- | Settings for 'widgetFile', such as which template languages to support and
--- default Hamlet settings.
 widgetFileSettings :: WidgetFileSettings
 widgetFileSettings = def
     { wfsHamletSettings = defaultHamletSettings
 parseExtra :: DefaultEnv -> Object -> Parser Extra
 parseExtra _ o = do
-    pwd <- TE.encodeUtf8 <$> o .: "hashed-password"
+    pwd <- encodeUtf8 <$> o .: "hashed-password"
     fdl <- o .: "folders" >>= mapM parseFolder
     retag <- o .: "retag"
     from <- o .:? "from-address" .!= "<test@example.com>"
     fromlst <- o .:? "from-addresses"
-    let f = maybe [from] id fromlst
+    let f = fromMaybe [from] fromlst
     sent <- o .:? "sent-box"
     dom <- o .:? "message-id-domain" .!= ""
     return $ Extra pwd fdl retag f sent dom

File src/StaticFiles.hs

View file
 import Prelude (IO)
 import Yesod.Static
 import qualified Yesod.Static as Static
-import Settings (staticDir, development)
+import Settings (development)
--- | use this to create your static file serving site
 staticSite :: IO Static.Static
-staticSite = if development then Static.staticDevel staticDir
-                            else Static.static      staticDir
+staticSite = if development then Static.staticDevel "static"
+                            else Static.static      "static"
--- | This generates easy references to files in the static directory at compile time,
---   giving you compile-time verification that referenced files exist.
---   Warning: any files added to your static directory during run-time can't be
---   accessed this way. You'll have to use their FilePath or URL to access them.
-$(staticFiles Settings.staticDir)
+$(staticFiles "static")