mirror of
https://github.com/nix-community/nixvim.git
synced 2025-06-21 00:25:42 +02:00
create helpers.toLuaObject
This commit is contained in:
parent
18d6f8da5f
commit
005df95e7b
2 changed files with 28 additions and 4 deletions
|
@ -35,7 +35,7 @@ in
|
|||
|
||||
extraPlugins = mkOption {
|
||||
type = with types; listOf (either package pluginWithConfigType);
|
||||
default = [ ];
|
||||
default = [];
|
||||
description = "List of vim plugins to install.";
|
||||
};
|
||||
|
||||
|
|
|
@ -1,6 +1,30 @@
|
|||
{ lib, ... }:
|
||||
{
|
||||
with lib;
|
||||
rec {
|
||||
# vim dictionaries are, in theory, compatible with JSON
|
||||
toVimDict = args: builtins.toJSON
|
||||
(lib.filterAttrs (n: v: !builtins.isNull v) args);
|
||||
toVimDict = args: toJSON
|
||||
(lib.filterAttrs (n: v: !isNull v) args);
|
||||
|
||||
# Black functional magic that converts a bunch of different Nix types to their
|
||||
# lua equivalents!
|
||||
toLuaObject = args:
|
||||
if builtins.isAttrs args then
|
||||
"{" + (concatStringsSep ","
|
||||
(mapAttrsToList
|
||||
(n: v: "[${toLuaObject n}] = " + (toLuaObject v))
|
||||
args)) + "}"
|
||||
else if builtins.isList args then
|
||||
"{" + concatMapStringsSep "," toLuaObject args + "}"
|
||||
else if builtins.isString args then
|
||||
# This should be enough!
|
||||
escapeShellArg args
|
||||
else if builtins.isBool args then
|
||||
"${ boolToString args }"
|
||||
else if builtins.isFloat args then
|
||||
"${ toString args }"
|
||||
else if builtins.isInt args then
|
||||
"${ toString args }"
|
||||
else if isNull args then
|
||||
"nil"
|
||||
else "";
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue