Generate preference type

This commit is contained in:
Zed 2019-09-08 13:01:20 +02:00
parent f1d566fff6
commit 8208676e6e
2 changed files with 16 additions and 13 deletions

View File

@ -105,3 +105,16 @@ macro genUpdatePrefs*(): untyped =
result.add quote do: result.add quote do:
cache(prefs) cache(prefs)
macro genPrefsType*(): untyped =
let name = nnkPostfix.newTree(ident("*"), ident("Prefs"))
result = quote do:
type `name` = object
id* {.pk, ro.}: int
for pref in allPrefs():
result[0][2][2].add nnkIdentDefs.newTree(
nnkPostfix.newTree(ident("*"), ident(pref.name)),
(case pref.kind
of checkbox: ident("bool")
of input, select: ident("string")),
newEmptyNode())

View File

@ -1,6 +1,8 @@
import times, sequtils, options import times, sequtils, options
import norm/sqlite import norm/sqlite
import prefs_impl
export sqlite, options export sqlite, options
type type
@ -50,19 +52,7 @@ dbTypes:
formatIt: dbValue($it) formatIt: dbValue($it)
.}: VideoType .}: VideoType
Prefs* = object genPrefsType()
hlsPlayback*: bool
mp4Playback*: bool
proxyVideos*: bool
muteVideos*: bool
autoplayGifs*: bool
hideTweetStats*: bool
hideBanner*: bool
stickyProfile*: bool
replaceYouTube*: string
replaceTwitter*: string
dbFromTypes("cache.db", "", "", "", [Profile, Video]) dbFromTypes("cache.db", "", "", "", [Profile, Video])
type type