File tree Expand file tree Collapse file tree 4 files changed +26
-1
lines changed
Expand file tree Collapse file tree 4 files changed +26
-1
lines changed Original file line number Diff line number Diff line change 7676 },
7777 -- Jump to request line on run
7878 jump_to_request = false ,
79- env_file = ' .env'
79+ env_file = ' .env' ,
80+ custom_dynamic_variables = {},
8081 })
8182 end
8283}
@@ -113,6 +114,8 @@ To run `rest.nvim` you should map the following commands:
113114- ` highlight ` allows to enable and configure the highlighting of the selected request when send,
114115- ` jump_to_request ` moves the cursor to the selected request line when send,
115116- ` env_file ` specifies file name that consist environment variables (default: .env)
117+ - ` custom_dynamic_variables ` allows to extend or overwrite built-in dynamic variable functions
118+ (default: {})
116119
117120## Usage
118121
Original file line number Diff line number Diff line change @@ -162,6 +162,23 @@ The following dynamic variables are currenty supported:
162162To use dynamic variables, the following syntax is used: `{{DYNAMIC_VARIABLE}}`,
163163e.g. `{{$uuid}}`
164164
165+ You can extend or overwrite built-in dynamic variables, with the config key
166+ `custom_dynamic_variables`:
167+
168+ `require("rest-nvim").setup({`
169+ ` custom_dynamic_variables = {`
170+ ` -- overwrite built-in`
171+ ` ['$uuid'] = function()`
172+ ` return "$uuid"`
173+ ` end,`
174+ ` -- add new dynamic variable function`
175+ ` ["$date"] = function()`
176+ ` local os_date = os.date('%Y-%m-%d')`
177+ ` return os_date`
178+ ` end,`
179+ ` },`
180+ `})`
181+
165182
166183===============================================================================
167184KNOWN ISSUES *rest-nvim-issues*
Original file line number Diff line number Diff line change @@ -14,6 +14,7 @@ local config = {
1414 },
1515 jump_to_request = false ,
1616 env_file = " .env" ,
17+ custom_dynamic_variables = {},
1718}
1819
1920--- Get a configuration value
Original file line number Diff line number Diff line change @@ -76,13 +76,17 @@ M.read_env_file = function()
7676end
7777
7878M .read_dynamic_variables = function ()
79+ local from_config = config .get (" custom_dynamic_variables" ) or {}
7980 local dynamic_variables = {
8081 [" $uuid" ] = M .uuid ,
8182 [" $timestamp" ] = os.time ,
8283 [" $randomInt" ] = function ()
8384 return math.random (0 , 1000 )
8485 end ,
8586 }
87+ for k , v in pairs (from_config ) do
88+ dynamic_variables [k ] = v
89+ end
8690 return dynamic_variables
8791end
8892
You can’t perform that action at this time.
0 commit comments