Skip to content

Commit a72ab52

Browse files
authoredFeb 5, 2025··
Initial commit
0 parents  commit a72ab52

File tree

12 files changed

+264
-0
lines changed

12 files changed

+264
-0
lines changed
 

‎.busted

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
return {
2+
_all = {
3+
coverage = false,
4+
lpath = 'lua/?.lua;lua/?/init.lua',
5+
lua = 'nlua',
6+
},
7+
default = {
8+
verbose = true,
9+
},
10+
tests = {
11+
verbose = true,
12+
},
13+
}

‎.github/workflows/ci.yml

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
name: Ci
2+
3+
on: [push]
4+
5+
jobs:
6+
lint:
7+
runs-on: ubuntu-latest
8+
steps:
9+
- uses: actions/checkout@v3
10+
- name: Stylua
11+
uses: JohnnyMorganz/stylua-action@v3
12+
with:
13+
token: ${{ secrets.GITHUB_TOKEN }}
14+
version: latest
15+
args: --check .
16+
17+
docs:
18+
runs-on: ubuntu-latest
19+
name: pandoc to vimdoc
20+
if: ${{ github.ref == 'refs/heads/main' }}
21+
steps:
22+
- uses: actions/checkout@v3
23+
- name: panvimdoc
24+
uses: kdheepak/panvimdoc@main
25+
with:
26+
vimdoc: nvim-plugin-template.nvim
27+
treesitter: true
28+
- uses: stefanzweifel/git-auto-commit-action@v4
29+
with:
30+
commit_message: "chore(doc): auto generate docs"
31+
commit_user_name: "github-actions[bot]"
32+
commit_user_email: "github-actions[bot]@users.noreply.github.com"
33+
commit_author: "github-actions[bot] <github-actions[bot]@users.noreply.github.com>"

‎.github/workflows/test.yml

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: Run tests
2+
on:
3+
pull_request: ~
4+
push:
5+
branches:
6+
- main
7+
8+
jobs:
9+
build:
10+
name: Run tests
11+
runs-on: ubuntu-latest
12+
strategy:
13+
matrix:
14+
neovim_version: ['nightly', 'stable']
15+
16+
steps:
17+
- uses: actions/checkout@v4
18+
- name: Download stylua
19+
shell: bash
20+
run: |
21+
wget "https://github.com/JohnnyMorganz/StyLua/releases/download/v0.18.0/stylua-linux.zip" -P /home/runner/.local/bin
22+
unzip /home/runner/.local/bin/stylua-linux.zip -d /home/runner/.local/bin
23+
chmod +x /home/runner/.local/bin/stylua
24+
- name: Run tests
25+
uses: nvim-neorocks/nvim-busted-action@v1
26+
with:
27+
nvim_version: ${{ matrix.neovim_version }}

‎.stylua.toml

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
column_width = 100
2+
line_endings = "Unix"
3+
indent_type = "Spaces"
4+
indent_width = 2
5+
quote_style = "AutoPreferSingle"
6+
call_parentheses = "Always"

‎LICENSE

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2023 nvimdev
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

‎README.md

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# nvim-plugin-template
2+
3+
Neovim plugin template; includes automatic documentation generation from README, integration tests with Busted, and linting with Stylua
4+
5+
## Usage
6+
7+
1. Click `use this template` button generate a repo on your github.
8+
2. Clone your plugin repo. Open terminal then cd plugin directory.
9+
3. Run `python3 rename.py your-plugin-name`. This will replace all `nvim-plugin-template` to your `plugin-name`.
10+
Then it will prompt you input `y` or `n` to remove example codes in `init.lua` and
11+
`test/plugin_spec.lua`. If you are familiar this repo just input `y`. If you are looking at this template for the first time I suggest you inspect the contents. After this step `rename.py` will also auto-remove.
12+
13+
Now you have a clean plugin environment. Enjoy!
14+
15+
## Format
16+
17+
The CI uses `stylua` to format the code; customize the formatting by editing `.stylua.toml`.
18+
19+
## Test
20+
21+
See [Running tests locally](https://github.com/nvim-neorocks/nvim-busted-action?tab=readme-ov-file#running-tests-locally)
22+
23+
## CI
24+
25+
- Auto generates doc from README.
26+
- Runs the [nvim-busted-action](https://github.com/nvim-neorocks/nvim-busted-action) for test.
27+
- Lints with `stylua`.
28+
29+
## More
30+
31+
To see this template in action, take a look at my other plugins.
32+
33+
## License MIT

‎doc/.gitkeep

Whitespace-only changes.

‎doc/nvim-plugin-template.nvim.txt

+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
*nvim-plugin-template.nvim.txt* For NVIM v0.8.0 Last change: 2025 February 05
2+
3+
==============================================================================
4+
Table of Contents *nvim-plugin-template.nvim-table-of-contents*
5+
6+
1. nvim-plugin-template |nvim-plugin-template.nvim-nvim-plugin-template|
7+
- Usage |nvim-plugin-template.nvim-nvim-plugin-template-usage|
8+
- Format |nvim-plugin-template.nvim-nvim-plugin-template-format|
9+
- Test |nvim-plugin-template.nvim-nvim-plugin-template-test|
10+
- CI |nvim-plugin-template.nvim-nvim-plugin-template-ci|
11+
- More |nvim-plugin-template.nvim-nvim-plugin-template-more|
12+
- License MIT |nvim-plugin-template.nvim-nvim-plugin-template-license-mit|
13+
14+
==============================================================================
15+
1. nvim-plugin-template *nvim-plugin-template.nvim-nvim-plugin-template*
16+
17+
Neovim plugin template; includes automatic documentation generation from
18+
README, integration tests with Busted, and linting with Stylua
19+
20+
21+
USAGE *nvim-plugin-template.nvim-nvim-plugin-template-usage*
22+
23+
1. Click `use this template` button generate a repo on your github.
24+
2. Clone your plugin repo. Open terminal then cd plugin directory.
25+
3. Run `python3 rename.py your-plugin-name`. This will replace all `nvim-plugin-template` to your `plugin-name`.
26+
Then it will prompt you input `y` or `n` to remove example codes in `init.lua` and
27+
`test/plugin_spec.lua`. If you are familiar this repo just input `y`. If you are looking at this template for the first time I suggest you inspect the contents. After this step `rename.py` will also auto-remove.
28+
29+
Now you have a clean plugin environment. Enjoy!
30+
31+
32+
FORMAT *nvim-plugin-template.nvim-nvim-plugin-template-format*
33+
34+
The CI uses `stylua` to format the code; customize the formatting by editing
35+
`.stylua.toml`.
36+
37+
38+
TEST *nvim-plugin-template.nvim-nvim-plugin-template-test*
39+
40+
See Running tests locally
41+
<https://github.com/nvim-neorocks/nvim-busted-action?tab=readme-ov-file#running-tests-locally>
42+
43+
44+
CI *nvim-plugin-template.nvim-nvim-plugin-template-ci*
45+
46+
- Auto generates doc from README.
47+
- Runs the nvim-busted-action <https://github.com/nvim-neorocks/nvim-busted-action> for test.
48+
- Lints with `stylua`.
49+
50+
51+
MORE *nvim-plugin-template.nvim-nvim-plugin-template-more*
52+
53+
To see this template in action, take a look at my other plugins.
54+
55+
56+
LICENSE MIT *nvim-plugin-template.nvim-nvim-plugin-template-license-mit*
57+
58+
Generated by panvimdoc <https://github.com/kdheepak/panvimdoc>
59+
60+
vim:tw=78:ts=8:noet:ft=help:norl:

‎lua/nvim-plugin-template/init.lua

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
local function example()
2+
return true
3+
end
4+
5+
return {
6+
example = example,
7+
}

‎plugin/nvim-plugin-template.lua

Whitespace-only changes.

‎rename.py

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
#!/usr/bin/python
2+
# -*- coding: UTF-8 -*-
3+
4+
import os, sys, shutil
5+
pdir = os.getcwd()
6+
7+
# ANSI color codes
8+
class Colors:
9+
RED = '\033[91m'
10+
GREEN = '\033[92m'
11+
YELLOW = '\033[93m'
12+
BLUE = '\033[94m'
13+
RESET = '\033[0m'
14+
15+
def print_colored(message, color):
16+
print(color + message + Colors.RESET)
17+
18+
if len(sys.argv) != 2:
19+
print_colored("plugin name is missing", Colors.RED)
20+
sys.exit(1)
21+
22+
new_name = sys.argv[1]
23+
for dir in os.listdir(pdir):
24+
if dir == "lua":
25+
os.rename(os.path.join("lua", "nvim-plugin-template"), os.path.join("lua",new_name))
26+
print_colored("Renamed files under lua folder successed", Colors.GREEN)
27+
if dir == "plugin":
28+
os.rename(os.path.join("plugin", "nvim-plugin-template.lua"),
29+
os.path.join("plugin",new_name + ".lua"))
30+
print_colored("Renamed files under plugin folder successed", Colors.GREEN)
31+
if dir == 'doc':
32+
os.rename(os.path.join("doc", "nvim-plugin-template.txt"),
33+
os.path.join("doc",new_name + ".txt"))
34+
print_colored("Renamed files under doc folder successed", Colors.GREEN)
35+
if dir == '.github':
36+
with open(os.path.join(".github","workflows","ci.yml"), 'r+') as f:
37+
d = f.read()
38+
t = d.replace('nvim-plugin-template', new_name)
39+
f.seek(0, 0)
40+
f.write(t)
41+
print_colored("Ci yaml has been updated", Colors.GREEN)
42+
43+
choice = input("Do you need plugin folder in your plugin (y|n): ")
44+
if choice.lower() == 'n':
45+
shutil.rmtree(os.path.join(os.getcwd(), 'plugin'))
46+
47+
choice = input("Do you want also remove example code in init.lua and test (y|n): ")
48+
if choice.lower() == 'y':
49+
with open(os.path.join(pdir, 'lua',new_name,'init.lua'), 'w') as f:
50+
f.truncate()
51+
52+
with open(os.path.join(pdir, 'test','plugin_spec.lua'), 'w') as f:
53+
f.truncate()
54+
55+
os.remove(os.path.join(os.getcwd(), 'rename.py'))
56+
print_colored("All works done enjoy", Colors.YELLOW)

‎test/plugin_spec.lua

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
local example = require('nvim-plugin-template').example
2+
3+
describe('neovim plugin', function()
4+
it('work as expect', function()
5+
local result = example()
6+
assert.is_true(result)
7+
end)
8+
end)

0 commit comments

Comments
 (0)
Please sign in to comment.