niksos/modules/tui/neovim/runtime/lua/templates/c.lua

41 lines
1.1 KiB
Lua
Raw Normal View History

local utils = require("new-file-template.utils")
local function h_template(relative_path, filename)
local file_name_split = vim.split(filename, "%.")
local guard_content = file_name_split[1].upper(file_name_split[1]) .. [[_H_]]
.. string.format('%s', os.time()) .. [[_]]
return [[
#ifndef ]] .. guard_content .. [[
#define ]] .. guard_content .. [[
|cursor|
#endif // ]] .. guard_content .. [[
]]
end
local function c_template(relative_path, filename)
local file_name_split = vim.split(filename, "%.")
return [[#include "]].. file_name_split[1] ..[[.h"
|cursor|]]
end
--- @param opts table
--- A table containing the following fields:
--- - `full_path` (string): The full path of the new file, e.g., "lua/new-file-template/templates/init.lua".
--- - `relative_path` (string): The relative path of the new file, e.g., "lua/new-file-template/templates/init.lua".
--- - `filename` (string): The filename of the new file, e.g., "init.lua".
return function(opts)
local template = {
{ pattern = ".*h", content = h_template },
{ pattern = ".*c", content = c_template },
}
return utils.find_entry(template, opts)
end