From 38adfaad2590b3cf3dce8f3c5034d413c49d2fd0 Mon Sep 17 00:00:00 2001 From: Chris Grieser <73286100+chrisgrieser@users.noreply.github.com> Date: Fri, 2 Aug 2024 15:52:13 +0200 Subject: [PATCH] feat: expand templates and placeholders --- .github/ISSUE_TEMPLATE/bug_report.yml | 14 ++++--- .github/workflows/panvimdoc.yml | 8 +++- BOOTSTRAP.sh | 39 +++++++++----------- LICENSE | 2 +- README.md | 18 ++++----- doc/PLACEHOLDER_plugin_name_short.txt | 0 lua/PLACEHOLDER_plugin_name_short/config.lua | 20 ++++++++++ lua/PLACEHOLDER_plugin_name_short/init.lua | 8 ++++ lua/PLACEHOLDER_plugin_name_short/utils.lua | 15 ++++++++ 9 files changed, 85 insertions(+), 39 deletions(-) create mode 100644 doc/PLACEHOLDER_plugin_name_short.txt create mode 100644 lua/PLACEHOLDER_plugin_name_short/config.lua create mode 100644 lua/PLACEHOLDER_plugin_name_short/init.lua create mode 100644 lua/PLACEHOLDER_plugin_name_short/utils.lua diff --git a/.github/ISSUE_TEMPLATE/bug_report.yml b/.github/ISSUE_TEMPLATE/bug_report.yml index 527585c..b861d78 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.yml +++ b/.github/ISSUE_TEMPLATE/bug_report.yml @@ -22,7 +22,8 @@ body: id: screenshot attributes: label: Relevant Screenshot - description: If applicable, add screenshots or a screen recording to help explain your problem. + description: + If applicable, add screenshots or a screen recording to help explain your problem. - type: textarea id: reproduction-steps attributes: @@ -30,9 +31,9 @@ body: description: Steps to reproduce the problem placeholder: | For example: - 1. Go to '...' - 2. Click on '...' - 3. Scroll down to '...' + 1. Go to… + 2. Click on… + 3. Scroll down to… validations: { required: true } - type: textarea id: version-info @@ -44,12 +45,13 @@ body: id: repro-lua attributes: label: Minimal reproducible config - description: Minimal config to reproduce the issue. Save as `repro.lua` and run with `nvim -u repro.lua` + description: + Minimal config to reproduce the issue. Save as `repro.lua` and run with `nvim -u repro.lua` render: lua value: | local spec = { { - "%%plugin-repo%%", + "PLACEHOLDER_plugin_repo", opts = {}, -- insert config here }, } diff --git a/.github/workflows/panvimdoc.yml b/.github/workflows/panvimdoc.yml index bb98133..fa325dc 100644 --- a/.github/workflows/panvimdoc.yml +++ b/.github/workflows/panvimdoc.yml @@ -6,23 +6,27 @@ on: paths: - README.md # source file - .github/workflows/panvimdoc.yml # updates to this file itself - workflow_dispatch: + workflow_dispatch: # manually trigger permissions: contents: write +#─────────────────────────────────────────────────────────────────────────────── + jobs: docs: runs-on: ubuntu-latest name: README.md to vimdoc steps: - uses: actions/checkout@v4 + - uses: kdheepak/panvimdoc@main with: - vimdoc: pseudometa-plugin-template + vimdoc: PLACEHOLDER_plugin_name_short demojify: true treesitter: true description: " Auto-generated from README.md. Do not make PRs to this file." + - uses: stefanzweifel/git-auto-commit-action@v4 with: commit_message: "chore: auto-generate vimdocs" diff --git a/BOOTSTRAP.sh b/BOOTSTRAP.sh index 5d690bb..d846389 100644 --- a/BOOTSTRAP.sh +++ b/BOOTSTRAP.sh @@ -1,45 +1,42 @@ #!/usr/bin/env zsh set -e # abort when any command errors, prevents self-removing at the end + #─────────────────────────────────────────────────────────────────────────────── +# VALUES # plugin name is the same as the git repo name and can therefore be inferred repo=$(git remote -v | head -n1 | sed -e 's/\.git.*//' -e 's/.*:\(.*\) .*/\1/') name=$(echo "$repo" | cut -d/ -f2) name_short=$(echo "$name" | sed -e 's/.nvim$//' -e 's/^nvim-//') +year=$(date +"%Y") # desc can be inferred from github description (not using jq for portability) -desc=$(curl -sL "https://api.github.com/repos/$repo" | grep --max-count=1 "description" | cut -d'"' -f4) +desc=$(curl -sL "https://api.github.com/repos/$repo" | + grep --max-count=1 "description" | cut -d'"' -f4) -# current year for license -year=$(date +"%Y") #─────────────────────────────────────────────────────────────────────────────── +# PLACEHOLDERS -LC_ALL=C # prevent byte sequence error -bootstrap_file=$(basename "$0") - -# replace them all -# $1: placeholder name as {{mustache-template}} -# $2: the replacement +# INFO macOS' sed requires `sed -i ''`, remove the `''` when on Linux function replacePlaceholders() { - # INFO macOS' sed requires `sed -i ''`, remove the `''` when on Linux or using GNU-sed - find . -type f -not -path '*/\.git/*' -not -name ".DS_Store" -not -name "$bootstrap_file" -exec \ + LC_ALL=C # prevent byte sequence error + this_file=$(basename "$0") + find . -type f -not -path '*/\.git/*' -not -name ".DS_Store" -not -name "$this_file" -exec \ sed -i '' "s|$1|$2|g" {} \; } -replacePlaceholders "%%plugin-name%%" "$name" -replacePlaceholders "%%plugin-desc%%" "$desc" -replacePlaceholders "%%year%%" "$year" -replacePlaceholders "%%plugin-name-short%%" "$name_short" -replacePlaceholders "%%plugin-repo%%" "$repo" +replacePlaceholders "PLACEHOLDER_plugin_name" "$name" +replacePlaceholders "PLACEHOLDER_plugin_name_short" "$name_short" +replacePlaceholders "PLACEHOLDER_plugin_desc" "$desc" +replacePlaceholders "PLACEHOLDER_year" "$year" +replacePlaceholders "PLACEHOLDER_plugin_repo" "$repo" #─────────────────────────────────────────────────────────────────────────────── -# Files -mkdir -p "./lua/$name_short" +# FILES -# for panvimdoc -mkdir ./doc -touch "./doc/$name_short.txt" +mv "./lua/PLACEHOLDER_plugin_name_short" "./lua/$name_short" +mv "./doc/PLACEHOLDER_plugin_name_short.txt" "./doc/$name_short.txt" rm -- "$0" # make this script delete itself diff --git a/LICENSE b/LICENSE index 13250e6..b5e8963 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) {{year}} Christopher Grieser +Copyright (c) PLACEHOLDER_year Christopher Grieser Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/README.md b/README.md index 2bdc66d..f12dfa8 100644 --- a/README.md +++ b/README.md @@ -1,12 +1,12 @@ -# %%plugin-name%% +# PLACEHOLDER_plugin_name -%%plugin-desc%% +PLACEHOLDER_plugin_desc @@ -20,19 +20,19 @@ ## Features -- +- … ## Installation ```lua -- lazy.nvim { - "chrisgrieser/%%plugin-name%%", + "chrisgrieser/PLACEHOLDER_plugin_name", }, -- packer use { - "chrisgrieser/%%plugin-name%%", + "chrisgrieser/PLACEHOLDER_plugin_name", } ``` @@ -40,8 +40,8 @@ use { ```lua -- default settings -require("%%plugin-name-short%%").setup { - +require("PLACEHOLDER_plugin_name_short").setup { + enabled = true, } ``` diff --git a/doc/PLACEHOLDER_plugin_name_short.txt b/doc/PLACEHOLDER_plugin_name_short.txt new file mode 100644 index 0000000..e69de29 diff --git a/lua/PLACEHOLDER_plugin_name_short/config.lua b/lua/PLACEHOLDER_plugin_name_short/config.lua new file mode 100644 index 0000000..8a8f156 --- /dev/null +++ b/lua/PLACEHOLDER_plugin_name_short/config.lua @@ -0,0 +1,20 @@ +local M = {} +-------------------------------------------------------------------------------- + +---@class PLACEHOLDER_plugin_name_short.config +local defaultConfig = { + enabled = true, +} + +---@type PLACEHOLDER_plugin_name_short.config +M.config = defaultConfig + +-------------------------------------------------------------------------------- + +---@param userConfig? PLACEHOLDER_plugin_name_short.config +M.setup = function(userConfig) + M.config = vim.tbl_deep_extend("force", defaultConfig, userConfig or {}) +end + +-------------------------------------------------------------------------------- +return M diff --git a/lua/PLACEHOLDER_plugin_name_short/init.lua b/lua/PLACEHOLDER_plugin_name_short/init.lua new file mode 100644 index 0000000..0bd728f --- /dev/null +++ b/lua/PLACEHOLDER_plugin_name_short/init.lua @@ -0,0 +1,8 @@ +local M = {} +-------------------------------------------------------------------------------- + +---@param userConfig? PLACEHOLDER_plugin_name_short.config +M.setup = function(userConfig) require("PLACEHOLDER_plugin_name_short.config").setup(userConfig) end + +-------------------------------------------------------------------------------- +return M diff --git a/lua/PLACEHOLDER_plugin_name_short/utils.lua b/lua/PLACEHOLDER_plugin_name_short/utils.lua new file mode 100644 index 0000000..499a87a --- /dev/null +++ b/lua/PLACEHOLDER_plugin_name_short/utils.lua @@ -0,0 +1,15 @@ +local M = {} +-------------------------------------------------------------------------------- + +---@param body string +---@param level? "info"|"trace"|"debug"|"warn"|"error" +---@param title? string +function M.notify(body, level, title) + local pluginName = "PLACEHOLDER_plugin_name_short" + local notifyTitle = title and pluginName .. ": " .. title or pluginName + if not level then level = "info" end + vim.notify(vim.trim(body), vim.log.levels[level:upper()], { title = notifyTitle }) +end + +-------------------------------------------------------------------------------- +return M