Skip to content

Commit

Permalink
feat: expand templates and placeholders
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisgrieser committed Aug 2, 2024
1 parent e742f48 commit 38adfaa
Show file tree
Hide file tree
Showing 9 changed files with 85 additions and 39 deletions.
14 changes: 8 additions & 6 deletions .github/ISSUE_TEMPLATE/bug_report.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,18 @@ 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:
label: To Reproduce
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
Expand All @@ -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
},
}
Expand Down
8 changes: 6 additions & 2 deletions .github/workflows/panvimdoc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
39 changes: 18 additions & 21 deletions BOOTSTRAP.sh
Original file line number Diff line number Diff line change
@@ -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

Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -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
Expand Down
18 changes: 9 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<!-- LTeX: enabled=false -->
# %%plugin-name%%
# PLACEHOLDER_plugin_name
<!-- LTeX: enabled=true -->
<!-- TODO uncomment shields when available in dotfyle.com
<a href="https://dotfyle.com/plugins/chrisgrieser/%%plugin-name%%">
<img alt="badge" src="https://dotfyle.com/plugins/chrisgrieser/%%plugin-name%%/shield"/></a>
<a href="https://dotfyle.com/plugins/chrisgrieser/PLACEHOLDER_plugin_name">
<img alt="badge" src="https://dotfyle.com/plugins/chrisgrieser/PLACEHOLDER_plugin_name/shield"/></a>
-->

%%plugin-desc%%
PLACEHOLDER_plugin_desc

<!-- toc -->

Expand All @@ -20,28 +20,28 @@
<!-- tocstop -->

## Features
-
-

## Installation

```lua
-- lazy.nvim
{
"chrisgrieser/%%plugin-name%%",
"chrisgrieser/PLACEHOLDER_plugin_name",
},

-- packer
use {
"chrisgrieser/%%plugin-name%%",
"chrisgrieser/PLACEHOLDER_plugin_name",
}
```

## Configuration

```lua
-- default settings
require("%%plugin-name-short%%").setup {

require("PLACEHOLDER_plugin_name_short").setup {
enabled = true,
}
```

Expand Down
Empty file.
20 changes: 20 additions & 0 deletions lua/PLACEHOLDER_plugin_name_short/config.lua
Original file line number Diff line number Diff line change
@@ -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
8 changes: 8 additions & 0 deletions lua/PLACEHOLDER_plugin_name_short/init.lua
Original file line number Diff line number Diff line change
@@ -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
15 changes: 15 additions & 0 deletions lua/PLACEHOLDER_plugin_name_short/utils.lua
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 38adfaa

Please sign in to comment.