diff options
Diffstat (limited to 'templates/encode.hs.ede')
-rw-r--r-- | templates/encode.hs.ede | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/templates/encode.hs.ede b/templates/encode.hs.ede new file mode 100644 index 0000000..f305eb1 --- /dev/null +++ b/templates/encode.hs.ede | |||
@@ -0,0 +1,26 @@ | |||
1 | -- generated file, do not modify! | ||
2 | -- {{ dateTime }} | ||
3 | |||
4 | {-# LANGUAGE OverloadedStrings, RecordWildCards #-} | ||
5 | module {{ moduleName }}Encode where | ||
6 | |||
7 | import Data.Text | ||
8 | import Data.Aeson hiding (Value,Bool) | ||
9 | import Data.Aeson.Types hiding (Value,Bool) | ||
10 | import Linear | ||
11 | |||
12 | import {{ moduleName }} | ||
13 | |||
14 | (.-) :: Text -> Text -> Pair | ||
15 | a .- b = a .= b | ||
16 | |||
17 | {% for t in definitions %} | ||
18 | instance ToJSON {{ t.value.dataName }} where | ||
19 | toJSON v = case v of{% for c in t.value.constructors %}{% if c.value.fields | hasFieldNames %} | ||
20 | {{ c.value.name }}{..} -> object | ||
21 | [ "tag" .- "{{ c.value.name }}"{% for f in c.value.fields %} | ||
22 | , "{{ f.value.fieldName }}" .= {{ f.value.fieldName }}{% endfor %} | ||
23 | ]{% else %} | ||
24 | {{ c.value.name }}{% for f in c.value.fields %} arg{{ f.index0 }}{% endfor %} -> object [ "tag" .- "{{ c.value.name }}"{% for f in c.value.fields %}, "arg{{ f.index0 }}" .= arg{{ f.index0 }}{% endfor %}]{% endif %}{% endfor %} | ||
25 | |||
26 | {% endfor %} \ No newline at end of file | ||