Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
glepnir committed Aug 4, 2024
0 parents commit e82ff18
Show file tree
Hide file tree
Showing 9 changed files with 266 additions and 0 deletions.
63 changes: 63 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
name: Ci

on: [push]

jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Stylua
uses: JohnnyMorganz/stylua-action@v3
with:
token: ${{ secrets.GITHUB_TOKEN }}
version: latest
args: --check .


docs:
runs-on: ubuntu-latest
name: pandoc to vimdoc
if: ${{ github.ref == 'refs/heads/main' }}
steps:
- uses: actions/checkout@v3
- name: panvimdoc
uses: kdheepak/panvimdoc@main
with:
vimdoc: nvim-plugin-template
treesitter: true
- uses: stefanzweifel/git-auto-commit-action@v4
with:
commit_message: 'chore(doc): auto generate docs'
commit_user_name: "github-actions[bot]"
commit_user_email: "github-actions[bot]@users.noreply.github.com"
commit_author: "github-actions[bot] <github-actions[bot]@users.noreply.github.com>"

test:
name: Run Test
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, macos-latest]
steps:
- uses: actions/checkout@v3
- uses: rhysd/action-setup-vim@v1
id: vim
with:
neovim: true
version: nightly

- name: luajit
uses: leafo/gh-actions-lua@v10
with:
luaVersion: "luajit-2.1.0-beta3"

- name: luarocks
uses: leafo/gh-actions-luarocks@v4

- name: run test
shell: bash
run: |
luarocks install luacheck
luarocks install vusted
vusted ./test
6 changes: 6 additions & 0 deletions .stylua.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
column_width = 100
line_endings = "Unix"
indent_type = "Spaces"
indent_width = 2
quote_style = "AutoPreferSingle"
call_parentheses = "Always"
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2023 nvimdev

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
38 changes: 38 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# nvim-plugin-template

Neovim plugin template; includes automatic documentation generation from README, integration tests with Busted, and linting with Stylua

## Usage

1. Click `use this template` button generate a repo on your github.
2. Clone your plugin repo. Open terminal then cd plugin directory.
3. Run `python3 rename.py your-plugin-name`. This will replace all `nvim-plugin-template` to your `plugin-name`.
Then it will prompt you input `y` or `n` to remove example codes in `init.lua` and
`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.

Now you have a clean plugin environment. Enjoy!

## Format

The CI uses `stylua` to format the code; customize the formatting by editing `.stylua.toml`.

## Test

Uses [busted](https://lunarmodules.github.io/busted/) for testing. Installs by using `luarocks --lua-version=5.1 install vusted` then runs `vusted ./test`
for your test cases. `vusted` is a wrapper of Busted especially for testing Neovim plugins.

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
[busted usage](https://lunarmodules.github.io/busted/)

## CI

- Auto generates doc from README.
- Runs the Busted/vusted integration tests
- Lints with `stylua`.


## More

To see this template in action, take a look at my other plugins.

## License MIT
67 changes: 67 additions & 0 deletions doc/nvim-plugin-template.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
*nvim-plugin-template.txt* For NVIM v0.8.0 Last change: 2024 June 08

==============================================================================
Table of Contents *nvim-plugin-template-table-of-contents*

1. nvim-plugin-template |nvim-plugin-template-nvim-plugin-template|
- Usage |nvim-plugin-template-nvim-plugin-template-usage|
- Format |nvim-plugin-template-nvim-plugin-template-format|
- Test |nvim-plugin-template-nvim-plugin-template-test|
- CI |nvim-plugin-template-nvim-plugin-template-ci|
- More |nvim-plugin-template-nvim-plugin-template-more|
- License MIT |nvim-plugin-template-nvim-plugin-template-license-mit|

==============================================================================
1. nvim-plugin-template *nvim-plugin-template-nvim-plugin-template*

Neovim plugin template; includes automatic documentation generation from
README, integration tests with Busted, and linting with Stylua


USAGE *nvim-plugin-template-nvim-plugin-template-usage*

1. Click `use this template` button generate a repo on your github.
2. Clone your plugin repo. Open terminal then cd plugin directory.
3. Run `python3 rename.py your-plugin-name`. This will replace all `nvim-plugin-template` to your `plugin-name`.
Then it will prompt you input `y` or `n` to remove example codes in `init.lua` and
`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.

Now you have a clean plugin environment. Enjoy!


FORMAT *nvim-plugin-template-nvim-plugin-template-format*

The CI uses `stylua` to format the code; customize the formatting by editing
`.stylua.toml`.


TEST *nvim-plugin-template-nvim-plugin-template-test*

Uses busted <https://lunarmodules.github.io/busted/> for testing. Installs by
using `luarocks --lua-version=5.1 install vusted` then runs `vusted ./test` for
your test cases. `vusted` is a wrapper of Busted especially for testing Neovim
plugins.

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 busted usage
<https://lunarmodules.github.io/busted/>


CI *nvim-plugin-template-nvim-plugin-template-ci*

- Auto generates doc from README.
- Runs the Busted/vusted integration tests
- Lints with `stylua`.


MORE *nvim-plugin-template-nvim-plugin-template-more*

To see this template in action, take a look at my other plugins.


LICENSE MIT *nvim-plugin-template-nvim-plugin-template-license-mit*

Generated by panvimdoc <https://github.com/kdheepak/panvimdoc>

vim:tw=78:ts=8:noet:ft=help:norl:
7 changes: 7 additions & 0 deletions lua/nvim-plugin-template/init.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
local function example()
return true
end

return {
example = example,
}
Empty file added plugin/nvim-plugin-template.lua
Empty file.
56 changes: 56 additions & 0 deletions rename.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#!/usr/bin/python
# -*- coding: UTF-8 -*-

import os, sys
pdir = os.getcwd()

# ANSI color codes
class Colors:
RED = '\033[91m'
GREEN = '\033[92m'
YELLOW = '\033[93m'
BLUE = '\033[94m'
RESET = '\033[0m'

def print_colored(message, color):
print(color + message + Colors.RESET)

if len(sys.argv) != 2:
print_colored("plugin name is missing", Colors.RED)
sys.exit(1)

new_name = sys.argv[1]
for dir in os.listdir(pdir):
if dir == "lua":
os.rename(os.path.join("lua", "nvim-plugin-template"), os.path.join("lua",new_name))
print_colored("Renamed files under lua folder successed", Colors.GREEN)
if dir == "plugin":
os.rename(os.path.join("plugin", "nvim-plugin-template.lua"),
os.path.join("plugin",new_name + ".lua"))
print_colored("Renamed files under plugin folder successed", Colors.GREEN)
if dir == 'doc':
os.rename(os.path.join("doc", "nvim-plugin-template.txt"),
os.path.join("doc",new_name + ".txt"))
print_colored("Renamed files under doc folder successed", Colors.GREEN)
if dir == '.github':
with open(os.path.join(".github","workflows","ci.yml"), 'r+') as f:
d = f.read()
t = d.replace('nvim-plugin-template', new_name)
f.seek(0, 0)
f.write(t)
print_colored("Ci yaml has been updated", Colors.GREEN)

choice = input("Do you need plugin folder in your plugin (y|n): ")
if choice.lower() == 'n':
os.remove(os.path.join(os.getcwd(), 'plugin'))

choice = input("Do you want also remove example code in init.lua and test (y|n): ")
if choice.lower() == 'y':
with open(os.path.join(pdir, 'lua',new_name,'init.lua'), 'w') as f:
f.truncate()

with open(os.path.join(pdir, 'test','plugin_spec.lua'), 'w') as f:
f.truncate()

os.remove(os.path.join(os.getcwd(), 'rename.py'))
print_colored("All works done enjoy", Colors.YELLOW)
8 changes: 8 additions & 0 deletions test/plugin_spec.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
local example = require('nvim-plugin-template').example

describe('neovim plugin', function()
it('work as expect', function()
local result = example()
assert.is_true(result)
end)
end)

0 comments on commit e82ff18

Please sign in to comment.