From 8208676e6e0a5ba64db932e8e4b0380e21def7f9 Mon Sep 17 00:00:00 2001 From: Zed Date: Sun, 8 Sep 2019 13:01:20 +0200 Subject: [PATCH] Generate preference type --- src/prefs_impl.nim | 13 +++++++++++++ src/types.nim | 16 +++------------- 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/src/prefs_impl.nim b/src/prefs_impl.nim index 27bc76c..011527b 100644 --- a/src/prefs_impl.nim +++ b/src/prefs_impl.nim @@ -105,3 +105,16 @@ macro genUpdatePrefs*(): untyped = result.add quote do: 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()) diff --git a/src/types.nim b/src/types.nim index 07cd332..d970cb7 100644 --- a/src/types.nim +++ b/src/types.nim @@ -1,6 +1,8 @@ import times, sequtils, options import norm/sqlite +import prefs_impl + export sqlite, options type @@ -50,19 +52,7 @@ dbTypes: formatIt: dbValue($it) .}: VideoType - Prefs* = object - hlsPlayback*: bool - mp4Playback*: bool - proxyVideos*: bool - muteVideos*: bool - autoplayGifs*: bool - hideTweetStats*: bool - hideBanner*: bool - stickyProfile*: bool - replaceYouTube*: string - replaceTwitter*: string - - +genPrefsType() dbFromTypes("cache.db", "", "", "", [Profile, Video]) type