Przeglądaj źródła

a tiny post thingie with elm

elm is fun, but you'll likely have to write quite a few libraries
yourself.
Lucas Stadler 11 lat temu
rodzic
commit
90cd6c7af3
3 zmienionych plików z 55 dodań i 0 usunięć
  1. 2 0
      elm/.gitignore
  2. 38 0
      elm/Stream.elm
  3. 15 0
      elm/elm-package.json

+ 2 - 0
elm/.gitignore

@ -0,0 +1,2 @@
1
elm.js
2
elm-stuff

+ 38 - 0
elm/Stream.elm

@ -0,0 +1,38 @@
1
module Stream where
2
3
import Date
4
import Date (Date)
5
import FormatDate (formatDate)
6
import Html (..)
7
import Html.Attributes as Attr
8
import List
9
import String
10
11
type alias Post = { title:String, content:String, created:Date }
12
13
date s = case (Date.fromString s) of
14
    Ok  d -> d
15
    Err e -> Date.fromTime 0
16
17
posts : List Post
18
posts = [{title = "Something else", content = "Well, I can say more than \"Hello\", I guess!", created = date "2015-03-01T14:03"},
19
         {title = "Hello, Other Things?", content = "There are other things?", created = date "2015-03-01T12:53:21"},
20
         {title = "Hello, World!", content = "This is my very first post!", created = date "2015-03-01T12:27:00"},
21
         {title = "Blog setup", content = "I guess I should post something now?", created = date "2014-12-24T10:57:03"},
22
         {title = "Ancient history", content = "Teenage angst!!!!", created = date "2009-06-07T02:54:29"}
23
        ]
24
25
referenceDate = date "2015-03-01T14:09"
26
27
viewDate : Date -> Html
28
viewDate d = let isoDate = formatDate "%Y-%m-%dT%H:%M:%SZ" d
29
             in time [Attr.title isoDate, Attr.datetime isoDate] [(text isoDate)]
30
31
viewPost : Post -> Html
32
viewPost post = div [] [
33
                 h3 [] [text post.title],
34
                 p [] [text post.content],
35
                 span [] [text "Written ", viewDate post.created]
36
                ]
37
38
main = div [] (List.map viewPost posts)

+ 15 - 0
elm/elm-package.json

@ -0,0 +1,15 @@
1
{
2
    "version": "0.1.0",
3
    "summary": "Playing around with Elm",
4
    "repository": "https://github.com/heyLu/lp.git",
5
    "license": "MIT",
6
    "source-directories": [
7
        "."
8
    ],
9
    "exposed-modules": [],
10
    "dependencies": {
11
        "elm-lang/core": "1.1.1 <= v < 2.0.0",
12
        "evancz/elm-html": "2.0.0 <= v < 3.0.0",
13
        "heyLu/elm-format-date": "1.0.0 <= v < 2.0.0"
14
    }
15
}