From 082ea10d63f06092357260b36833b78fc2e6bc81 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A5kon=20Harnes?= Date: Sat, 25 May 2024 18:32:35 +0200 Subject: [PATCH] feat: add ability to customize extension (#71) --- README.md | 1 + lua/img-clip/config.lua | 1 + lua/img-clip/paste.lua | 9 ++++++--- tests/config_spec.lua | 1 + vimdoc.md | 1 + 5 files changed, 10 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index f94029a..9c74d4b 100644 --- a/README.md +++ b/README.md @@ -87,6 +87,7 @@ The plugin is highly configurable. Please refer to the default configuration bel default = { -- file and directory options dir_path = "assets", ---@type string + extension = "png", ---@type string file_name = "%Y-%m-%d-%H-%M-%S", ---@type string use_absolute_path = false, ---@type boolean relative_to_current_file = false, ---@type boolean diff --git a/lua/img-clip/config.lua b/lua/img-clip/config.lua index 0b72b66..76ff588 100644 --- a/lua/img-clip/config.lua +++ b/lua/img-clip/config.lua @@ -12,6 +12,7 @@ local defaults = { default = { -- file and directory options dir_path = "assets", ---@type string + extension = "png", ---@type string file_name = "%Y-%m-%d-%H-%M-%S", ---@type string use_absolute_path = false, ---@type boolean relative_to_current_file = false, ---@type boolean diff --git a/lua/img-clip/paste.lua b/lua/img-clip/paste.lua index f0ad7d3..e1f38d3 100644 --- a/lua/img-clip/paste.lua +++ b/lua/img-clip/paste.lua @@ -58,7 +58,8 @@ M.paste_image_from_url = function(url) return true end - local file_path = fs.get_file_path("png") + local extension = config.get_opt("extension") + local file_path = fs.get_file_path(extension) if not file_path then util.error("Could not determine file path.") return false @@ -114,7 +115,8 @@ M.paste_image_from_path = function(src_path) return true end - local file_path = fs.get_file_path("png") + local extension = config.get_opt("extension") + local file_path = fs.get_file_path(extension) if not file_path then util.error("Could not determine file path.") return false @@ -152,7 +154,8 @@ M.paste_image_from_clipboard = function() end end - local file_path = fs.get_file_path("png") + local extension = config.get_opt("extension") + local file_path = fs.get_file_path(extension) if not file_path then util.error("Could not determine file path.") return false diff --git a/tests/config_spec.lua b/tests/config_spec.lua index e5c0376..2e9a65b 100644 --- a/tests/config_spec.lua +++ b/tests/config_spec.lua @@ -12,6 +12,7 @@ describe("config", function() it("should have default values for all configuration options", function() assert.equals("assets", config.get_opt("dir_path")) assert.equals("%Y-%m-%d-%H-%M-%S", config.get_opt("file_name")) + assert.equals("png", config.get_opt("extension")) assert.is_false(config.get_opt("url_encode_path")) assert.is_false(config.get_opt("use_absolute_path")) assert.is_false(config.get_opt("relative_to_current_file")) diff --git a/vimdoc.md b/vimdoc.md index 5a1135f..45a0676 100644 --- a/vimdoc.md +++ b/vimdoc.md @@ -87,6 +87,7 @@ The plugin is highly configurable. Please refer to the default configuration bel default = { -- file and directory options dir_path = "assets", ---@type string + extension = "png", ---@type string file_name = "%Y-%m-%d-%H-%M-%S", ---@type string use_absolute_path = false, ---@type boolean relative_to_current_file = false, ---@type boolean