Update Drupal snippets
This commit is contained in:
parent
95f49f9b47
commit
c6de886ae7
|
@ -25,6 +25,60 @@ local M = {
|
|||
{ i(1), i(0) }
|
||||
),
|
||||
|
||||
drupalclass = fmta(
|
||||
[[
|
||||
<<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace <>;
|
||||
|
||||
final class <> {
|
||||
|
||||
<>
|
||||
|
||||
}]],
|
||||
{
|
||||
f(function()
|
||||
local filepath = vim.fn.expand "%:h"
|
||||
local filepath_parts = vim.fn.split(filepath, "/")
|
||||
|
||||
if not vim.tbl_contains(filepath_parts, "src") then
|
||||
return ""
|
||||
end
|
||||
|
||||
local namespace_parts = { "Drupal" }
|
||||
|
||||
local is_test_file = vim.tbl_contains(filepath_parts, "tests")
|
||||
if is_test_file then
|
||||
table.insert(namespace_parts, "Tests")
|
||||
end
|
||||
|
||||
-- Find and add the module name.
|
||||
for k, v in ipairs(filepath_parts) do
|
||||
if v == "src" then
|
||||
if is_test_file then
|
||||
table.insert(namespace_parts, filepath_parts[k - 2])
|
||||
else
|
||||
table.insert(namespace_parts, filepath_parts[k - 1])
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- Add the rest of the namespace.
|
||||
local namespace = vim.split(filepath, "src/")
|
||||
local final_part = (namespace[2] or ""):gsub("/", "\\")
|
||||
table.insert(namespace_parts, final_part)
|
||||
|
||||
return table.concat(namespace_parts, "\\")
|
||||
end),
|
||||
f(function()
|
||||
return vim.fn.expand "%:t:r"
|
||||
end),
|
||||
i(0),
|
||||
}
|
||||
),
|
||||
|
||||
func = fmta("function <>(<>)<> {\n <>\n}<>", { i(1), i(2), i(3), i(4), i(0) }),
|
||||
|
||||
met = fmta(
|
||||
|
|
39
lua/opdavies/snippets/ft/yaml.lua
Normal file
39
lua/opdavies/snippets/ft/yaml.lua
Normal file
|
@ -0,0 +1,39 @@
|
|||
local fmta = require("luasnip.extras.fmt").fmta
|
||||
local ls = require "luasnip"
|
||||
local rep = require("luasnip.extras").rep
|
||||
|
||||
local c = ls.choice_node
|
||||
local i = ls.insert_node
|
||||
local t = ls.text_node
|
||||
|
||||
local M = {
|
||||
drupal_info = fmta(
|
||||
[[
|
||||
name: <module_name>
|
||||
description: <description>
|
||||
core_version_requirement: ^10 || ^11
|
||||
type: <type>
|
||||
package: <package>
|
||||
]],
|
||||
{ module_name = i(1), description = i(2), type = c(3, { t "module", t "theme" }), package = i(0) }
|
||||
),
|
||||
|
||||
drupal_route = fmta(
|
||||
[[
|
||||
<module>.<route>:
|
||||
path: /<path>
|
||||
defaults:
|
||||
_controller: Drupal\<module_same>\Controller\<class>
|
||||
# _form:
|
||||
# _title:
|
||||
# _title_callback:
|
||||
methods: [GET]
|
||||
requirements:
|
||||
_permission: access content
|
||||
# _access: TRUE<finish>
|
||||
]],
|
||||
{ module = i(1), route = i(2), path = i(3), module_same = rep(1), class = i(4), finish = i(0) }
|
||||
),
|
||||
}
|
||||
|
||||
return M
|
Reference in a new issue