-
Notifications
You must be signed in to change notification settings - Fork 107
/
Copy pathconsts_haskell.qtpl
76 lines (73 loc) · 3.5 KB
/
consts_haskell.qtpl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
{% import "strings" %}
{% import "strconv" %}
{% import "fmt" %}
{% func PadRight(s string, maxLen int) %}{% stripspace %}
{%s s %}{%s strings.Repeat(" ", maxLen-len(s)) %}
{% endstripspace %}{% endfunc %}
{%- func haskellConsts(data *ConstTemplateData) -%}
-- {%s data.DoNotEdit %}
module ServerSentEventGenerator.Constants where
import Prelude
import ServerSentEventGenerator.Class (StringLike)
-- taken from consts.ts
-- why?
-- functions must start with a lower case letter
-- I could have used a type class, but it would have required
-- a function call in front of each data constructor, so I
-- decided to just use the prefix "c"
cDatastarKey :: StringLike a => a
cDatastarKey = "{%s data.DatastarKey %}"
cVersion :: StringLike a => a
cVersion = "{%s data.Version %}"
cVersionClientByteSize :: Int
cVersionClientByteSize = {%d data.VersionClientByteSize %}
cVersionClientByteSizeGzip :: Int
cVersionClientByteSizeGzip = {%d data.VersionClientByteSizeGzip %}
{%- for _, d := range data.DefaultDurations -%}
{%s PadRight(fmt.Sprintf("cDefault%s", d.Name.Pascal), 40) %} :: Int
{%s PadRight(fmt.Sprintf("cDefault%s", d.Name.Pascal), 40) %} = {%d durationToMs(d.Duration) %} -- milliseconds
{%- endfor -%}
{%- for _, s := range data.DefaultStrings -%}
{%s PadRight(fmt.Sprintf("c%s", s.Name.Pascal), 40) %} :: StringLike a => a
{%s PadRight(fmt.Sprintf("c%s", s.Name.Pascal), 40) %} = "{%s s.Value %}"
{%- endfor -%}
{%- for _, literal := range data.DatalineLiterals -%}
{%s PadRight(fmt.Sprintf("c%s", literal.Pascal), 40) %} :: StringLike a => a
{%s PadRight(fmt.Sprintf("c%s", literal.Pascal), 40) %} = "{%s literal.Camel %}"
{%- endfor -%}
{%- for _, b := range data.DefaultBools -%}
{% code
boolStr := strconv.FormatBool(b.Value)
capitalizedBool := strings.ToUpper(boolStr[:1]) + boolStr[1:]
-%}
{%s PadRight(fmt.Sprintf("cDefault%s", b.Name.Pascal), 40) %} :: Bool
{%s PadRight(fmt.Sprintf("cDefault%s", b.Name.Pascal), 40) %} = {%s capitalizedBool %}
{%- endfor -%}
{%- for _, enum := range data.Enums -%}
{%- for _, entry := range enum.Values -%}
{%s PadRight(fmt.Sprintf("c%s", entry.Name.Pascal), 40) %} :: StringLike a => a
{%s PadRight(fmt.Sprintf("c%s", entry.Name.Pascal), 40) %} = "{%v entry.Value %}"
{%- endfor -%}
{%- endfor -%}
-- Added by Henry
cData :: StringLike a => a
cData = "data"
cEvent :: StringLike a => a
cEvent = "event"
cEventId :: StringLike a => a
cEventId = "id"
cRetryDuration :: StringLike a => a
cRetryDuration = "retry"
cSColon :: StringLike a => a
cSColon = ": "
cSpace :: StringLike a => a
cSpace = " "
cDefaultSelector :: StringLike a => a
cDefaultSelector = ""
cDefaultEventId :: StringLike a => a
cDefaultEventId = ""
cDefaultOnlyIfMissing :: Bool
cDefaultOnlyIfMissing = False
cDefaultAttributes :: StringLike a => a
cDefaultAttributes = ""
{%- endfunc -%}