File tree 4 files changed +26
-1
lines changed
4 files changed +26
-1
lines changed Original file line number Diff line number Diff line change 76
76
},
77
77
-- Jump to request line on run
78
78
jump_to_request = false ,
79
- env_file = ' .env'
79
+ env_file = ' .env' ,
80
+ custom_dynamic_variables = {},
80
81
})
81
82
end
82
83
}
@@ -113,6 +114,8 @@ To run `rest.nvim` you should map the following commands:
113
114
- ` highlight ` allows to enable and configure the highlighting of the selected request when send,
114
115
- ` jump_to_request ` moves the cursor to the selected request line when send,
115
116
- ` 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: {})
116
119
117
120
## Usage
118
121
Original file line number Diff line number Diff line change @@ -162,6 +162,23 @@ The following dynamic variables are currenty supported:
162
162
To use dynamic variables, the following syntax is used: `{{DYNAMIC_VARIABLE}}`,
163
163
e.g. `{{$uuid}}`
164
164
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
+
165
182
166
183
===============================================================================
167
184
KNOWN ISSUES *rest-nvim-issues*
Original file line number Diff line number Diff line change @@ -14,6 +14,7 @@ local config = {
14
14
},
15
15
jump_to_request = false ,
16
16
env_file = " .env" ,
17
+ custom_dynamic_variables = {},
17
18
}
18
19
19
20
--- Get a configuration value
Original file line number Diff line number Diff line change @@ -76,13 +76,17 @@ M.read_env_file = function()
76
76
end
77
77
78
78
M .read_dynamic_variables = function ()
79
+ local from_config = config .get (" custom_dynamic_variables" ) or {}
79
80
local dynamic_variables = {
80
81
[" $uuid" ] = M .uuid ,
81
82
[" $timestamp" ] = os.time ,
82
83
[" $randomInt" ] = function ()
83
84
return math.random (0 , 1000 )
84
85
end ,
85
86
}
87
+ for k , v in pairs (from_config ) do
88
+ dynamic_variables [k ] = v
89
+ end
86
90
return dynamic_variables
87
91
end
88
92
You can’t perform that action at this time.
0 commit comments