gdritter repos scrapboard / master
a bunch of existing crap (it honestly seems kind of bad) Getty Ritter 6 years ago
10 changed file(s) with 217 addition(s) and 0 deletion(s). Collapse all Expand all
1 *~
2 dist*
3 .ghc.environment*
1 Copyright (c) 2016, Getty Ritter
2
3 All rights reserved.
4
5 Redistribution and use in source and binary forms, with or without
6 modification, are permitted provided that the following conditions are met:
7
8 * Redistributions of source code must retain the above copyright
9 notice, this list of conditions and the following disclaimer.
10
11 * Redistributions in binary form must reproduce the above
12 copyright notice, this list of conditions and the following
13 disclaimer in the documentation and/or other materials provided
14 with the distribution.
15
16 * Neither the name of Getty Ritter nor the names of other
17 contributors may be used to endorse or promote products derived
18 from this software without specific prior written permission.
19
20 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24 OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
1 CREATE TABLE scraps
2 ( id INTEGER PRIMARY KEY
3 , name STRING
4 , id integer not null references (values.id)
5 );
6
7 CREATE TABLE values
8 ( id INTEGER PRIMARY KEY
9 , datum STRING
10 );
1 name: scrapboard
2 version: 0.1.0.0
3 -- synopsis:
4 -- description:
5 license: BSD3
6 license-file: LICENSE
7 author: Getty Ritter
8 maintainer: gettylefou@gmail.com
9 -- copyright:
10 -- category:
11 build-type: Simple
12 extra-source-files: ChangeLog.md
13 cabal-version: >=1.10
14
15 executable scrapboard
16 main-is: Main.hs
17 default-extensions: OverloadedStrings
18 -- other-modules:
19 -- other-extensions:
20 build-depends: base >=4.8 && <5,
21 scotty,
22 sqlite-simple,
23 text,
24 lucid,
25 aeson
26 hs-source-dirs: src
27 default-language: Haskell2010
1 {-# LANGUAGE OverloadedStrings #-}
2
3 import Data.Monoid ((<>))
4 import Web.Scotty
5
6 import Templates
7
8 main :: IO ()
9 main = do
10 scotty 3000 $ do
11 get "/" $ do
12 html $ page "stuff" (return ())
13 get (regex "^/u:([A-Za-z]*)$") $ do
14 user <- param "1"
15 text $ "got: " <> user
1 module Routes where
2
3 import Web.Scotty
4
5 data Route
6 = RIndex
7 | RSettings
8 | RLogout
9 | RRecent
10 | RQuery [QueryData]
11 deriving (Eq, Show)
12
13 data QueryData
14 = QTag String
15 | QType String
16
17 route :: Route -> RoutePattern
18 route stuff = regex ("^/" ++ stuff ++ "/?$")
1 {-# LANGUAGE RecordWildCards #-}
2
3 module Storage where
4
5 import Types
6
7 readScrap :: Integer -> Connection -> IO Scrap
8 readScrap ident c = do
9 return Scrap { .. }
1 {-# LANGUAGE OverloadedStrings #-}
2 {-# LANGUAGE RecordWildCards #-}
3
4 module Templates where
5
6 import Data.Monoid ((<>))
7 import Lucid
8 import Data.Text.Lazy (Text)
9
10 page :: Text -> Html () -> Text
11 page title content = renderText $ do
12 head_ $ do
13 title_ ("scrapboard: " <> toHtml title)
14 meta_ [ httpEquiv_ "content-type"
15 , content_ "text/html; charset=utf-8"
16 ]
17 body_ $ do
18 div_ [id_ "content"] $ do
19 banner
20 div_ [id_ "main_column"] ""
21 div_ [id_ "right_bar"] ""
22 div_ [id_ "tag_cloud"] ""
23
24 banner :: Html ()
25 banner = div_ [id_ "banner"] $ do
26 div_ [id_ "logo"] $ do
27 a_ [href_ "/recent"] $ img_ [ class_ "logo"
28 , src_ "/static/thumb.png"
29 ]
30 a_ [id_ "scrapboard_name", href_ "/"] "Scrapboard"
31 div_ [id_ "top_menu"] $ do
32 a_ [href_ "/history/"] "history"
33 a_ [href_ "/add/"] "add"
34 a_ [href_ "/settings/"] "settings"
35 a_ [href_ "/logout/"] "logout"
1 > module Types where
2
3 > import Database.SQLite.Simple
4 > import Data.Text (Text)
5 > import qualified Data.Text as T
6
7 Our 'scraps' are chunks of structured data with some kind of
8 identifying information. In this case, our identifier is an
9 integer, because we explicitly don't want users to have to
10 name new every new scrap.
11
12 > data Scrap = Scrap
13 > { scIdent :: Integer
14 > , scDatum :: Datum
15 > } deriving (Eq, Show)
16
17 Our 'Datum' type is not unlike a JSON value, and there's a
18 pretty clear
19
20 > data Datum
21 > = DString Text
22 > | DLink Text Text
23 > | DTag Text
24 > | DRef Text
25 > | DList [Datum]
26 > | DRec [(Text, Datum)]
27 > deriving (Eq, Show)
28
29 > data ScrapType = ScrapType
30 > { scrapName :: Text
31 > , scrapFields :: [Field]
32 > } deriving (Eq, Show)
33
34 > data Field = Field
35 > { fieldName :: Text
36 > , fieldType :: FieldType
37 > } deriving (Eq, Show)
38
39 > data FieldType
40 > = FTString
41 > | FTLink
42 > | FTTag
43 > | FTRef
44 > | FTList FieldType
45 > | FTRec [Field]
46 > deriving (Eq, Show)
1 <!DOCTYPE html>
2 <html>
3 <head>
4 <meta http-equiv="content-type" content="text/html; charset=utf-8"/>
5 <meta property="og:title" content="scrapbook: {{title}}"/>
6 <meta property="og:url" content="{{url}}"/>
7 <title>{{title}}</title>
8 </head>
9 <body>
10 <div class="banner">
11 <a href="/recent">recent</a>
12 <a href="/history">history</a>
13 <a href="/add">add</a>
14 <a href="/settings">settings</a>
15 <a href="/logout">logout</a>
16 </div>
17 <div class="main_column">
18 </div>
19 <div class="right_bar"
20 </div>
21 <div class="tag_cloud">
22 </div>
23 </body>
24 </html>