-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(hooks): add hook system for post-file creation actions
- Implement hooks functionality in `lua/scratch/api.lua` - Add `hooks` field to the configuration in `lua/scratch/config.lua` - Update README.md with an example of using hooks
- Loading branch information
1 parent
f93937f
commit 41c2659
Showing
4 changed files
with
47 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
local M = {} | ||
|
||
---@class Scratch.Hook | ||
---@field callback fun(param: table?) | ||
---@field name? string | ||
---@field trigger_point? string | ||
|
||
M.trigger_points = { | ||
AFTER = "AFTER", | ||
} | ||
|
||
---@param hooks Scratch.Hook[] | ||
---@param target_trigger_point? string | ||
---@return Scratch.Hook[] | ||
M.get_hooks = function(hooks, target_trigger_point) | ||
local matching_hooks = {} | ||
for _, hook in ipairs(hooks) do | ||
local matches = false | ||
local trigger_point = hook.trigger_point or M.trigger_points.AFTER | ||
|
||
if trigger_point == target_trigger_point then | ||
matches = true | ||
end | ||
|
||
if matches then | ||
table.insert(matching_hooks, hook) | ||
end | ||
end | ||
return matching_hooks | ||
end | ||
|
||
return M |