Skip to content

Commit e82ff18

Browse files
authored
Initial commit
0 parents  commit e82ff18

File tree

9 files changed

+266
-0
lines changed

9 files changed

+266
-0
lines changed

.github/workflows/ci.yml

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
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+
18+
docs:
19+
runs-on: ubuntu-latest
20+
name: pandoc to vimdoc
21+
if: ${{ github.ref == 'refs/heads/main' }}
22+
steps:
23+
- uses: actions/checkout@v3
24+
- name: panvimdoc
25+
uses: kdheepak/panvimdoc@main
26+
with:
27+
vimdoc: nvim-plugin-template
28+
treesitter: true
29+
- uses: stefanzweifel/git-auto-commit-action@v4
30+
with:
31+
commit_message: 'chore(doc): auto generate docs'
32+
commit_user_name: "github-actions[bot]"
33+
commit_user_email: "github-actions[bot]@users.noreply.github.com"
34+
commit_author: "github-actions[bot] <github-actions[bot]@users.noreply.github.com>"
35+
36+
test:
37+
name: Run Test
38+
runs-on: ${{ matrix.os }}
39+
strategy:
40+
matrix:
41+
os: [ubuntu-latest, macos-latest]
42+
steps:
43+
- uses: actions/checkout@v3
44+
- uses: rhysd/action-setup-vim@v1
45+
id: vim
46+
with:
47+
neovim: true
48+
version: nightly
49+
50+
- name: luajit
51+
uses: leafo/gh-actions-lua@v10
52+
with:
53+
luaVersion: "luajit-2.1.0-beta3"
54+
55+
- name: luarocks
56+
uses: leafo/gh-actions-luarocks@v4
57+
58+
- name: run test
59+
shell: bash
60+
run: |
61+
luarocks install luacheck
62+
luarocks install vusted
63+
vusted ./test

.stylua.toml

Lines changed: 6 additions & 0 deletions
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

Lines changed: 21 additions & 0 deletions
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

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
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+
Uses [busted](https://lunarmodules.github.io/busted/) for testing. Installs by using `luarocks --lua-version=5.1 install vusted` then runs `vusted ./test`
22+
for your test cases. `vusted` is a wrapper of Busted especially for testing Neovim plugins.
23+
24+
Create test cases in the `test` folder. Busted expects files in this directory to be named `foo_spec.lua`, with `_spec` as a suffix before the `.lua` file extension. For more usage details please check
25+
[busted usage](https://lunarmodules.github.io/busted/)
26+
27+
## CI
28+
29+
- Auto generates doc from README.
30+
- Runs the Busted/vusted integration tests
31+
- Lints with `stylua`.
32+
33+
34+
## More
35+
36+
To see this template in action, take a look at my other plugins.
37+
38+
## License MIT

doc/nvim-plugin-template.txt

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
*nvim-plugin-template.txt* For NVIM v0.8.0 Last change: 2024 June 08
2+
3+
==============================================================================
4+
Table of Contents *nvim-plugin-template-table-of-contents*
5+
6+
1. nvim-plugin-template |nvim-plugin-template-nvim-plugin-template|
7+
- Usage |nvim-plugin-template-nvim-plugin-template-usage|
8+
- Format |nvim-plugin-template-nvim-plugin-template-format|
9+
- Test |nvim-plugin-template-nvim-plugin-template-test|
10+
- CI |nvim-plugin-template-nvim-plugin-template-ci|
11+
- More |nvim-plugin-template-nvim-plugin-template-more|
12+
- License MIT |nvim-plugin-template-nvim-plugin-template-license-mit|
13+
14+
==============================================================================
15+
1. nvim-plugin-template *nvim-plugin-template-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-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-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-plugin-template-test*
39+
40+
Uses busted <https://lunarmodules.github.io/busted/> for testing. Installs by
41+
using `luarocks --lua-version=5.1 install vusted` then runs `vusted ./test` for
42+
your test cases. `vusted` is a wrapper of Busted especially for testing Neovim
43+
plugins.
44+
45+
Create test cases in the `test` folder. Busted expects files in this directory
46+
to be named `foo_spec.lua`, with `_spec` as a suffix before the `.lua` file
47+
extension. For more usage details please check busted usage
48+
<https://lunarmodules.github.io/busted/>
49+
50+
51+
CI *nvim-plugin-template-nvim-plugin-template-ci*
52+
53+
- Auto generates doc from README.
54+
- Runs the Busted/vusted integration tests
55+
- Lints with `stylua`.
56+
57+
58+
MORE *nvim-plugin-template-nvim-plugin-template-more*
59+
60+
To see this template in action, take a look at my other plugins.
61+
62+
63+
LICENSE MIT *nvim-plugin-template-nvim-plugin-template-license-mit*
64+
65+
Generated by panvimdoc <https://github.com/kdheepak/panvimdoc>
66+
67+
vim:tw=78:ts=8:noet:ft=help:norl:

lua/nvim-plugin-template/init.lua

Lines changed: 7 additions & 0 deletions
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

Lines changed: 56 additions & 0 deletions
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
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+
os.remove(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

Lines changed: 8 additions & 0 deletions
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)