Move some files around, tweak the generated code a bit
This commit is contained in:
parent
952f6baafd
commit
f4dcf17f3f
25 changed files with 314 additions and 148 deletions
|
@ -1,16 +0,0 @@
|
|||
-- | Common handler functions.
|
||||
module Handler.Common where
|
||||
|
||||
import Data.FileEmbed (embedFile)
|
||||
import Import
|
||||
|
||||
-- These handlers embed files in the executable at compile time to avoid a
|
||||
-- runtime dependency, and for efficiency.
|
||||
|
||||
getFaviconR :: Handler TypedContent
|
||||
getFaviconR = return $ TypedContent "image/x-icon"
|
||||
$ toContent $(embedFile "config/favicon.ico")
|
||||
|
||||
getRobotsR :: Handler TypedContent
|
||||
getRobotsR = return $ TypedContent typePlain
|
||||
$ toContent $(embedFile "config/robots.txt")
|
|
@ -1,6 +0,0 @@
|
|||
module Import
|
||||
( module Import
|
||||
) where
|
||||
|
||||
import Foundation as Import
|
||||
import Import.NoFoundation as Import
|
|
@ -1,11 +0,0 @@
|
|||
module Import.NoFoundation
|
||||
( module Import
|
||||
) where
|
||||
|
||||
import ClassyPrelude.Yesod as Import
|
||||
import Model as Import
|
||||
import Settings as Import
|
||||
import Settings.StaticFiles as Import
|
||||
import Yesod.Auth as Import
|
||||
import Yesod.Core.Types as Import (loggerSet)
|
||||
import Yesod.Default.Config2 as Import
|
13
Model.hs
13
Model.hs
|
@ -1,13 +0,0 @@
|
|||
{-# LANGUAGE FlexibleInstances #-}
|
||||
|
||||
module Model where
|
||||
|
||||
import ClassyPrelude.Yesod
|
||||
import Database.Persist.Quasi
|
||||
|
||||
-- You can define all of your database entities in the entities file.
|
||||
-- You can find more information on persistent and how to declare entities
|
||||
-- at:
|
||||
-- http://www.yesodweb.com/book/persistent/
|
||||
share [mkPersist sqlSettings, mkMigrate "migrateAll"]
|
||||
$(persistFileWith lowerCaseSettings "config/models")
|
|
@ -1,3 +1,18 @@
|
|||
{- This file is part of Vervis.
|
||||
-
|
||||
- Written in 2016 by fr33domlover <fr33domlover@riseup.net>.
|
||||
-
|
||||
- ♡ Copying is an act of love. Please copy, reuse and share.
|
||||
-
|
||||
- The author(s) have dedicated all copyright and related and neighboring
|
||||
- rights to this software to the public domain worldwide. This software is
|
||||
- distributed without any warranty.
|
||||
-
|
||||
- You should have received a copy of the CC0 Public Domain Dedication along
|
||||
- with this software. If not, see
|
||||
- <http://creativecommons.org/publicdomain/zero/1.0/>.
|
||||
-}
|
||||
|
||||
-- | Running your app inside GHCi.
|
||||
--
|
||||
-- To start up GHCi for usage with Yesod, first make sure you are in dev mode:
|
||||
|
|
16
app/devel.hs
16
app/devel.hs
|
@ -1,4 +1,20 @@
|
|||
{- This file is part of Vervis.
|
||||
-
|
||||
- Written in 2016 by fr33domlover <fr33domlover@riseup.net>.
|
||||
-
|
||||
- ♡ Copying is an act of love. Please copy, reuse and share.
|
||||
-
|
||||
- The author(s) have dedicated all copyright and related and neighboring
|
||||
- rights to this software to the public domain worldwide. This software is
|
||||
- distributed without any warranty.
|
||||
-
|
||||
- You should have received a copy of the CC0 Public Domain Dedication along
|
||||
- with this software. If not, see
|
||||
- <http://creativecommons.org/publicdomain/zero/1.0/>.
|
||||
-}
|
||||
|
||||
{-# LANGUAGE PackageImports #-}
|
||||
|
||||
import "vervis" Application (develMain)
|
||||
import Prelude (IO)
|
||||
|
||||
|
|
15
app/main.hs
15
app/main.hs
|
@ -1,3 +1,18 @@
|
|||
{- This file is part of Vervis.
|
||||
-
|
||||
- Written in 2016 by fr33domlover <fr33domlover@riseup.net>.
|
||||
-
|
||||
- ♡ Copying is an act of love. Please copy, reuse and share.
|
||||
-
|
||||
- The author(s) have dedicated all copyright and related and neighboring
|
||||
- rights to this software to the public domain worldwide. This software is
|
||||
- distributed without any warranty.
|
||||
-
|
||||
- You should have received a copy of the CC0 Public Domain Dedication along
|
||||
- with this software. If not, see
|
||||
- <http://creativecommons.org/publicdomain/zero/1.0/>.
|
||||
-}
|
||||
|
||||
import Prelude (IO)
|
||||
import Application (appMain)
|
||||
|
||||
|
|
|
@ -1,3 +1,17 @@
|
|||
-- This file is part of Vervis.
|
||||
--
|
||||
-- Written in 2016 by fr33domlover <fr33domlover@riseup.net>.
|
||||
--
|
||||
-- ♡ Copying is an act of love. Please copy, reuse and share.
|
||||
--
|
||||
-- The author(s) have dedicated all copyright and related and neighboring
|
||||
-- rights to this software to the public domain worldwide. This software is
|
||||
-- distributed without any warranty.
|
||||
--
|
||||
-- You should have received a copy of the CC0 Public Domain Dedication along
|
||||
-- with this software. If not, see
|
||||
-- <http://creativecommons.org/publicdomain/zero/1.0/>.
|
||||
|
||||
User
|
||||
ident Text
|
||||
password Text Maybe
|
||||
|
|
|
@ -1,9 +1,23 @@
|
|||
/static StaticR Static appStatic
|
||||
/auth AuthR Auth getAuth
|
||||
-- This file is part of Vervis.
|
||||
--
|
||||
-- Written in 2016 by fr33domlover <fr33domlover@riseup.net>.
|
||||
--
|
||||
-- ♡ Copying is an act of love. Please copy, reuse and share.
|
||||
--
|
||||
-- The author(s) have dedicated all copyright and related and neighboring
|
||||
-- rights to this software to the public domain worldwide. This software is
|
||||
-- distributed without any warranty.
|
||||
--
|
||||
-- You should have received a copy of the CC0 Public Domain Dedication along
|
||||
-- with this software. If not, see
|
||||
-- <http://creativecommons.org/publicdomain/zero/1.0/>.
|
||||
|
||||
/static StaticR Static appStatic
|
||||
/auth AuthR Auth getAuth
|
||||
|
||||
/favicon.ico FaviconR GET
|
||||
/robots.txt RobotsR GET
|
||||
/robots.txt RobotsR GET
|
||||
|
||||
/ HomeR GET POST
|
||||
/ HomeR GET POST
|
||||
|
||||
/comments CommentR POST
|
||||
/comments CommentR POST
|
||||
|
|
|
@ -1,9 +1,15 @@
|
|||
# Values formatted like "_env:ENV_VAR_NAME:default_value" can be overridden by the specified environment variable.
|
||||
# See https://github.com/yesodweb/yesod/wiki/Configuration#overriding-configuration-values-with-environment-variables
|
||||
# Values formatted like "_env:ENV_VAR_NAME:default_value" can be overridden by
|
||||
# the specified environment variable. See the Yesod wiki, Configuration page.
|
||||
|
||||
static-dir: "_env:STATIC_DIR:static"
|
||||
host: "_env:HOST:*4" # any IPv4 host
|
||||
port: "_env:PORT:3000" # NB: The port `yesod devel` uses is distinct from this value. Set the `yesod devel` port from the command line.
|
||||
|
||||
# any IPv4 host
|
||||
host: "_env:HOST:*4"
|
||||
|
||||
# The port `yesod devel` uses is distinct from this value. Set the
|
||||
# `yesod devel` port from the command line.
|
||||
port: "_env:PORT:3000"
|
||||
|
||||
ip-from-header: "_env:IP_FROM_HEADER:false"
|
||||
|
||||
# Default behavior: determine the application root from the request headers.
|
||||
|
@ -20,16 +26,16 @@ ip-from-header: "_env:IP_FROM_HEADER:false"
|
|||
# mutable-static: false
|
||||
# skip-combining: false
|
||||
|
||||
# NB: If you need a numeric value (e.g. 123) to parse as a String, wrap it in single quotes (e.g. "_env:PGPASS:'123'")
|
||||
# See https://github.com/yesodweb/yesod/wiki/Configuration#parsing-numeric-values-as-strings
|
||||
# If you need a numeric value (e.g. 123) to parse as a String, wrap it in
|
||||
# single quotes (e.g. "_env:PGPASS:'123'"). See the Yesod wiki, Configuration
|
||||
# page.
|
||||
|
||||
database:
|
||||
user: "_env:PGUSER:vervis_LOWER"
|
||||
password: "_env:PGPASS:vervis"
|
||||
user: "_env:PGUSER:vervis"
|
||||
password: "_env:PGPASS:vervis_password_here"
|
||||
host: "_env:PGHOST:localhost"
|
||||
port: "_env:PGPORT:5432"
|
||||
database: "_env:PGDATABASE:vervis_LOWER"
|
||||
database: "_env:PGDATABASE:vervis"
|
||||
poolsize: "_env:PGPOOLSIZE:10"
|
||||
|
||||
copyright: Insert copyright statement here
|
||||
#analytics: UA-YOURCODE
|
||||
copyright: Insert your statement against copyright here
|
||||
|
|
|
@ -1,2 +1,2 @@
|
|||
database:
|
||||
database: vervis_LOWER_test
|
||||
database: vervis_dev_test
|
||||
|
|
|
@ -1,4 +1,20 @@
|
|||
{- This file is part of Vervis.
|
||||
-
|
||||
- Written in 2016 by fr33domlover <fr33domlover@riseup.net>.
|
||||
-
|
||||
- ♡ Copying is an act of love. Please copy, reuse and share.
|
||||
-
|
||||
- The author(s) have dedicated all copyright and related and neighboring
|
||||
- rights to this software to the public domain worldwide. This software is
|
||||
- distributed without any warranty.
|
||||
-
|
||||
- You should have received a copy of the CC0 Public Domain Dedication along
|
||||
- with this software. If not, see
|
||||
- <http://creativecommons.org/publicdomain/zero/1.0/>.
|
||||
-}
|
||||
|
||||
{-# OPTIONS_GHC -fno-warn-orphans #-}
|
||||
|
||||
module Application
|
||||
( getApplicationDev
|
||||
, appMain
|
||||
|
@ -11,7 +27,8 @@ module Application
|
|||
-- * for GHCI
|
||||
, handler
|
||||
, db
|
||||
) where
|
||||
)
|
||||
where
|
||||
|
||||
import Control.Monad.Logger (liftLoc, runLoggingT)
|
||||
import Database.Persist.Postgresql (createPostgresqlPool, pgConnStr,
|
|
@ -1,3 +1,18 @@
|
|||
{- This file is part of Vervis.
|
||||
-
|
||||
- Written in 2016 by fr33domlover <fr33domlover@riseup.net>.
|
||||
-
|
||||
- ♡ Copying is an act of love. Please copy, reuse and share.
|
||||
-
|
||||
- The author(s) have dedicated all copyright and related and neighboring
|
||||
- rights to this software to the public domain worldwide. This software is
|
||||
- distributed without any warranty.
|
||||
-
|
||||
- You should have received a copy of the CC0 Public Domain Dedication along
|
||||
- with this software. If not, see
|
||||
- <http://creativecommons.org/publicdomain/zero/1.0/>.
|
||||
-}
|
||||
|
||||
module Foundation where
|
||||
|
||||
import Import.NoFoundation
|
|
@ -1,3 +1,18 @@
|
|||
{- This file is part of Vervis.
|
||||
-
|
||||
- Written in 2016 by fr33domlover <fr33domlover@riseup.net>.
|
||||
-
|
||||
- ♡ Copying is an act of love. Please copy, reuse and share.
|
||||
-
|
||||
- The author(s) have dedicated all copyright and related and neighboring
|
||||
- rights to this software to the public domain worldwide. This software is
|
||||
- distributed without any warranty.
|
||||
-
|
||||
- You should have received a copy of the CC0 Public Domain Dedication along
|
||||
- with this software. If not, see
|
||||
- <http://creativecommons.org/publicdomain/zero/1.0/>.
|
||||
-}
|
||||
|
||||
module Handler.Comment where
|
||||
|
||||
import Import
|
35
src/Handler/Common.hs
Normal file
35
src/Handler/Common.hs
Normal file
|
@ -0,0 +1,35 @@
|
|||
{- This file is part of Vervis.
|
||||
-
|
||||
- Written in 2016 by fr33domlover <fr33domlover@riseup.net>.
|
||||
-
|
||||
- ♡ Copying is an act of love. Please copy, reuse and share.
|
||||
-
|
||||
- The author(s) have dedicated all copyright and related and neighboring
|
||||
- rights to this software to the public domain worldwide. This software is
|
||||
- distributed without any warranty.
|
||||
-
|
||||
- You should have received a copy of the CC0 Public Domain Dedication along
|
||||
- with this software. If not, see
|
||||
- <http://creativecommons.org/publicdomain/zero/1.0/>.
|
||||
-}
|
||||
|
||||
-- | Common handler functions.
|
||||
module Handler.Common where
|
||||
|
||||
import Data.FileEmbed (embedFile)
|
||||
import Import
|
||||
|
||||
-- These handlers embed files in the executable at compile time to avoid a
|
||||
-- runtime dependency, and for efficiency.
|
||||
|
||||
getFaviconR :: Handler TypedContent
|
||||
getFaviconR =
|
||||
return $
|
||||
TypedContent "image/x-icon" $
|
||||
toContent $(embedFile "config/favicon.ico")
|
||||
|
||||
getRobotsR :: Handler TypedContent
|
||||
getRobotsR =
|
||||
return $
|
||||
TypedContent typePlain $
|
||||
toContent $(embedFile "config/robots.txt")
|
|
@ -1,3 +1,18 @@
|
|||
{- This file is part of Vervis.
|
||||
-
|
||||
- Written in 2016 by fr33domlover <fr33domlover@riseup.net>.
|
||||
-
|
||||
- ♡ Copying is an act of love. Please copy, reuse and share.
|
||||
-
|
||||
- The author(s) have dedicated all copyright and related and neighboring
|
||||
- rights to this software to the public domain worldwide. This software is
|
||||
- distributed without any warranty.
|
||||
-
|
||||
- You should have received a copy of the CC0 Public Domain Dedication along
|
||||
- with this software. If not, see
|
||||
- <http://creativecommons.org/publicdomain/zero/1.0/>.
|
||||
-}
|
||||
|
||||
module Handler.Home where
|
||||
|
||||
import Import
|
19
src/Import.hs
Normal file
19
src/Import.hs
Normal file
|
@ -0,0 +1,19 @@
|
|||
{- This file is part of Vervis.
|
||||
-
|
||||
- Written in 2016 by fr33domlover <fr33domlover@riseup.net>.
|
||||
-
|
||||
- ♡ Copying is an act of love. Please copy, reuse and share.
|
||||
-
|
||||
- The author(s) have dedicated all copyright and related and neighboring
|
||||
- rights to this software to the public domain worldwide. This software is
|
||||
- distributed without any warranty.
|
||||
-
|
||||
- You should have received a copy of the CC0 Public Domain Dedication along
|
||||
- with this software. If not, see
|
||||
- <http://creativecommons.org/publicdomain/zero/1.0/>.
|
||||
-}
|
||||
|
||||
module Import ( module Import ) where
|
||||
|
||||
import Foundation as Import
|
||||
import Import.NoFoundation as Import
|
24
src/Import/NoFoundation.hs
Normal file
24
src/Import/NoFoundation.hs
Normal file
|
@ -0,0 +1,24 @@
|
|||
{- This file is part of Vervis.
|
||||
-
|
||||
- Written in 2016 by fr33domlover <fr33domlover@riseup.net>.
|
||||
-
|
||||
- ♡ Copying is an act of love. Please copy, reuse and share.
|
||||
-
|
||||
- The author(s) have dedicated all copyright and related and neighboring
|
||||
- rights to this software to the public domain worldwide. This software is
|
||||
- distributed without any warranty.
|
||||
-
|
||||
- You should have received a copy of the CC0 Public Domain Dedication along
|
||||
- with this software. If not, see
|
||||
- <http://creativecommons.org/publicdomain/zero/1.0/>.
|
||||
-}
|
||||
|
||||
module Import.NoFoundation ( module Import ) where
|
||||
|
||||
import ClassyPrelude.Yesod as Import
|
||||
import Model as Import
|
||||
import Settings as Import
|
||||
import Settings.StaticFiles as Import
|
||||
import Yesod.Auth as Import
|
||||
import Yesod.Core.Types as Import (loggerSet)
|
||||
import Yesod.Default.Config2 as Import
|
28
src/Model.hs
Normal file
28
src/Model.hs
Normal file
|
@ -0,0 +1,28 @@
|
|||
{- This file is part of Vervis.
|
||||
-
|
||||
- Written in 2016 by fr33domlover <fr33domlover@riseup.net>.
|
||||
-
|
||||
- ♡ Copying is an act of love. Please copy, reuse and share.
|
||||
-
|
||||
- The author(s) have dedicated all copyright and related and neighboring
|
||||
- rights to this software to the public domain worldwide. This software is
|
||||
- distributed without any warranty.
|
||||
-
|
||||
- You should have received a copy of the CC0 Public Domain Dedication along
|
||||
- with this software. If not, see
|
||||
- <http://creativecommons.org/publicdomain/zero/1.0/>.
|
||||
-}
|
||||
|
||||
{-# LANGUAGE FlexibleInstances #-}
|
||||
|
||||
module Model where
|
||||
|
||||
import ClassyPrelude.Yesod
|
||||
import Database.Persist.Quasi
|
||||
|
||||
-- You can define all of your database entities in the entities file.
|
||||
-- You can find more information on persistent and how to declare entities
|
||||
-- at:
|
||||
-- http://www.yesodweb.com/book/persistent/
|
||||
share [mkPersist sqlSettings, mkMigrate "migrateAll"]
|
||||
$(persistFileWith lowerCaseSettings "config/models")
|
|
@ -1,4 +1,20 @@
|
|||
{- This file is part of Vervis.
|
||||
-
|
||||
- Written in 2016 by fr33domlover <fr33domlover@riseup.net>.
|
||||
-
|
||||
- ♡ Copying is an act of love. Please copy, reuse and share.
|
||||
-
|
||||
- The author(s) have dedicated all copyright and related and neighboring
|
||||
- rights to this software to the public domain worldwide. This software is
|
||||
- distributed without any warranty.
|
||||
-
|
||||
- You should have received a copy of the CC0 Public Domain Dedication along
|
||||
- with this software. If not, see
|
||||
- <http://creativecommons.org/publicdomain/zero/1.0/>.
|
||||
-}
|
||||
|
||||
{-# Language CPP #-}
|
||||
|
||||
-- | 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
|
||||
|
@ -52,8 +68,6 @@ data AppSettings = AppSettings
|
|||
-- Example app-specific configuration values.
|
||||
, appCopyright :: Text
|
||||
-- ^ Copyright text to appear in the footer of the page
|
||||
, appAnalytics :: Maybe Text
|
||||
-- ^ Google Analytics code
|
||||
}
|
||||
|
||||
instance FromJSON AppSettings where
|
||||
|
@ -78,7 +92,6 @@ instance FromJSON AppSettings where
|
|||
appSkipCombining <- o .:? "skip-combining" .!= defaultDev
|
||||
|
||||
appCopyright <- o .: "copyright"
|
||||
appAnalytics <- o .:? "analytics"
|
||||
|
||||
return AppSettings {..}
|
||||
|
||||
|
@ -99,10 +112,12 @@ combineSettings = def
|
|||
-- user.
|
||||
|
||||
widgetFile :: String -> Q Exp
|
||||
widgetFile = (if appReloadTemplates compileTimeAppSettings
|
||||
widgetFile =
|
||||
let wf =
|
||||
if appReloadTemplates compileTimeAppSettings
|
||||
then widgetFileReload
|
||||
else widgetFileNoReload)
|
||||
widgetFileSettings
|
||||
else widgetFileNoReload
|
||||
in wf widgetFileSettings
|
||||
|
||||
-- | Raw bytes at compile time of @config/settings.yml@
|
||||
configSettingsYmlBS :: ByteString
|
||||
|
@ -112,11 +127,12 @@ configSettingsYmlBS = $(embedFile configSettingsYml)
|
|||
configSettingsYmlValue :: Value
|
||||
configSettingsYmlValue = either throw id $ decodeEither' configSettingsYmlBS
|
||||
|
||||
-- | A version of @AppSettings@ parsed at compile time from @config/settings.yml@.
|
||||
-- | A version of @AppSettings@ parsed at compile time from
|
||||
-- @config/settings.yml@.
|
||||
compileTimeAppSettings :: AppSettings
|
||||
compileTimeAppSettings =
|
||||
case fromJSON $ applyEnvValue False mempty configSettingsYmlValue of
|
||||
Error e -> error e
|
||||
Error e -> error e
|
||||
Success settings -> settings
|
||||
|
||||
-- The following two functions can be used to combine multiple CSS or JS files
|
||||
|
@ -126,11 +142,13 @@ compileTimeAppSettings =
|
|||
-- > $(combineStylesheets 'StaticR [style1_css, style2_css])
|
||||
|
||||
combineStylesheets :: Name -> [Route Static] -> Q Exp
|
||||
combineStylesheets = combineStylesheets'
|
||||
(appSkipCombining compileTimeAppSettings)
|
||||
combineSettings
|
||||
combineStylesheets =
|
||||
combineStylesheets'
|
||||
(appSkipCombining compileTimeAppSettings)
|
||||
combineSettings
|
||||
|
||||
combineScripts :: Name -> [Route Static] -> Q Exp
|
||||
combineScripts = combineScripts'
|
||||
(appSkipCombining compileTimeAppSettings)
|
||||
combineSettings
|
||||
combineScripts =
|
||||
combineScripts'
|
||||
(appSkipCombining compileTimeAppSettings)
|
||||
combineSettings
|
|
@ -1,3 +1,18 @@
|
|||
{- This file is part of Vervis.
|
||||
-
|
||||
- Written in 2016 by fr33domlover <fr33domlover@riseup.net>.
|
||||
-
|
||||
- ♡ Copying is an act of love. Please copy, reuse and share.
|
||||
-
|
||||
- The author(s) have dedicated all copyright and related and neighboring
|
||||
- rights to this software to the public domain worldwide. This software is
|
||||
- distributed without any warranty.
|
||||
-
|
||||
- You should have received a copy of the CC0 Public Domain Dedication along
|
||||
- with this software. If not, see
|
||||
- <http://creativecommons.org/publicdomain/zero/1.0/>.
|
||||
-}
|
||||
|
||||
module Settings.StaticFiles where
|
||||
|
||||
import Settings (appStaticDir, compileTimeAppSettings)
|
|
@ -49,14 +49,3 @@ $newline never
|
|||
^{pageBody pc}
|
||||
<footer>
|
||||
#{appCopyright $ appSettings master}
|
||||
|
||||
$maybe analytics <- appAnalytics $ appSettings master
|
||||
<script>
|
||||
if(!window.location.href.match(/localhost/)){
|
||||
window._gaq = [['_setAccount','#{analytics}'],['_trackPageview'],['_trackPageLoadTime']];
|
||||
(function() {
|
||||
\ var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
|
||||
\ ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
|
||||
\ var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
|
||||
})();
|
||||
}
|
||||
|
|
|
@ -47,28 +47,3 @@
|
|||
^{formWidget}
|
||||
<button .btn .btn-primary type="submit">
|
||||
Send it! <span class="glyphicon glyphicon-upload"></span>
|
||||
|
||||
<section.page-header>
|
||||
<h2>JSON
|
||||
|
||||
<p>
|
||||
Yesod has JSON support baked-in.
|
||||
The form below makes an AJAX request with Javascript,
|
||||
then updates the page with your submission.
|
||||
(see <tt>Handler/Comment.hs</tt>, <tt>templates/homepage.julius</tt>,
|
||||
and <tt>Handler/Home.hs</tt> for the implementation).
|
||||
<form ##{commentFormId}>
|
||||
<.form-group>
|
||||
<textarea ##{commentTextareaId} placeholder="Your comment here..." required></textarea>
|
||||
<button .btn .btn-primary type="submit">
|
||||
Create comment
|
||||
|
||||
<ul ##{commentListId}>
|
||||
|
||||
<section.page-header>
|
||||
<h2>Testing
|
||||
|
||||
<p>
|
||||
And last but not least, Testing. In <tt>test/Spec.hs</tt> you will find a #
|
||||
test suite that performs tests on this page. #
|
||||
You can run your tests by doing: <pre>stack test</pre>
|
||||
|
|
|
@ -1,33 +0,0 @@
|
|||
document.getElementById(#{toJSON aDomId}).innerHTML = "This text was added by the Javascript part of the homepage widget.";
|
||||
|
||||
$(function() {
|
||||
$("##{rawJS commentFormId}").submit(function(event) {
|
||||
event.preventDefault();
|
||||
|
||||
var message = $("##{rawJS commentTextareaId}").val();
|
||||
// (Browsers that enforce the "required" attribute on the textarea won't see this alert)
|
||||
if (!message) {
|
||||
alert("Please fill out the comment form first.");
|
||||
return;
|
||||
}
|
||||
|
||||
// Make an AJAX request to the server to create a new comment
|
||||
$.ajax({
|
||||
url: '@{CommentR}',
|
||||
type: 'POST',
|
||||
contentType: "application/json",
|
||||
data: JSON.stringify({
|
||||
message: message,
|
||||
}),
|
||||
success: function (data) {
|
||||
var newNode = $("<li></li>");
|
||||
newNode.text(data.message);
|
||||
$("##{rawJS commentListId}").append(newNode);
|
||||
},
|
||||
error: function (data) {
|
||||
console.log("Error creating comment: " + data);
|
||||
},
|
||||
});
|
||||
|
||||
});
|
||||
});
|
|
@ -107,7 +107,7 @@ library
|
|||
, time
|
||||
, case-insensitive
|
||||
, wai
|
||||
hs-source-dirs: ., app
|
||||
hs-source-dirs: src
|
||||
default-language: Haskell2010
|
||||
|
||||
if flag(dev) || flag(library-only)
|
||||
|
|
Loading…
Reference in a new issue