mirror of
https://github.com/nix-community/nixvim.git
synced 2025-06-21 16:39:00 +02:00
helpers/lib: toLuaObject ignore empty attrs (#312)
This commit is contained in:
parent
3d64fab719
commit
35c56b62a1
2 changed files with 26 additions and 3 deletions
|
@ -12,6 +12,8 @@ with lib; rec {
|
||||||
then
|
then
|
||||||
if hasAttr "__raw" args
|
if hasAttr "__raw" args
|
||||||
then args.__raw
|
then args.__raw
|
||||||
|
else if hasAttr "__empty" args
|
||||||
|
then "{ }"
|
||||||
else
|
else
|
||||||
"{"
|
"{"
|
||||||
+ (concatStringsSep ","
|
+ (concatStringsSep ","
|
||||||
|
@ -20,7 +22,12 @@ with lib; rec {
|
||||||
if head (stringToCharacters n) == "@"
|
if head (stringToCharacters n) == "@"
|
||||||
then toLuaObject v
|
then toLuaObject v
|
||||||
else "[${toLuaObject n}] = " + (toLuaObject v))
|
else "[${toLuaObject n}] = " + (toLuaObject v))
|
||||||
(filterAttrs (n: v: !isNull v) args)))
|
(filterAttrs
|
||||||
|
(
|
||||||
|
n: v:
|
||||||
|
!isNull v && (toLuaObject v != "{}")
|
||||||
|
)
|
||||||
|
args)))
|
||||||
+ "}"
|
+ "}"
|
||||||
else if builtins.isList args
|
else if builtins.isList args
|
||||||
then "{" + concatMapStringsSep "," toLuaObject args + "}"
|
then "{" + concatMapStringsSep "," toLuaObject args + "}"
|
||||||
|
@ -40,6 +47,8 @@ with lib; rec {
|
||||||
then "nil"
|
then "nil"
|
||||||
else "";
|
else "";
|
||||||
|
|
||||||
|
emptyTable = {"__empty" = null;};
|
||||||
|
|
||||||
# Generates maps for a lua config
|
# Generates maps for a lua config
|
||||||
genMaps = mode: maps: let
|
genMaps = mode: maps: let
|
||||||
normalized =
|
normalized =
|
||||||
|
|
|
@ -68,7 +68,7 @@
|
||||||
expected = ''"foo\\bar\nbaz"'';
|
expected = ''"foo\\bar\nbaz"'';
|
||||||
};
|
};
|
||||||
|
|
||||||
testToLuaObjectShouldFilterNullAttrs = {
|
testToLuaObjectFilters = {
|
||||||
expr = helpers.toLuaObject {
|
expr = helpers.toLuaObject {
|
||||||
a = null;
|
a = null;
|
||||||
b = {};
|
b = {};
|
||||||
|
@ -78,7 +78,21 @@
|
||||||
f = {};
|
f = {};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
expected = ''{["b"] = {},["c"] = {},["d"] = {["f"] = {}}}'';
|
expected = ''{}'';
|
||||||
|
};
|
||||||
|
|
||||||
|
testToLuaObjectEmptyTable = {
|
||||||
|
expr = helpers.toLuaObject {
|
||||||
|
a = null;
|
||||||
|
b = {};
|
||||||
|
c = {__empty = null;};
|
||||||
|
d = {
|
||||||
|
e = null;
|
||||||
|
f = {};
|
||||||
|
g = helpers.emptyTable;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
expected = ''{["c"] = { },["d"] = {["g"] = { }}}'';
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
in
|
in
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue