Skip to content

Commit

Permalink
feat: add ability to customize extension
Browse files Browse the repository at this point in the history
  • Loading branch information
HakonHarnes committed May 25, 2024
1 parent c55f988 commit 53a6a9d
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 3 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions lua/img-clip/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 6 additions & 3 deletions lua/img-clip/paste.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions tests/config_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand Down
1 change: 1 addition & 0 deletions vimdoc.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 53a6a9d

Please sign in to comment.