Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add "djhtml" formatter (indenter) and command #2

Merged
merged 1 commit into from
Jun 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 30 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,14 @@ django templates (htmldjango) extension for [coc.nvim](https://github.com/neocli

## Features

- Format by [Unibeautify](https://unibeautify.com/) (Beautifiers: JS-Beautify + Pretty Diff)
- Format (One of them can be selected in the `htmldjango.formatting.provider` settings)
- by [Unibeautify](https://unibeautify.com/) (Beautifiers: JS-Beautify + Pretty Diff) [Node tool]
- by [DjHTML](https://github.com/rtts/djhtml) ("Django/Jinja" template indenter) [Python tool]
- Hover | [DEMO](https://github.com/yaegassy/coc-htmldjango/pull/1)
- Snippets completion
- To use it, you need to install [coc-snippets](https://github.com/neoclide/coc-snippets).
- And set `snippets.loadFromExtensions` to true in "coc-settings.json"
- Built-in installer (DjHTML)

It is possible to use `coc-htmldjango` with filetype other than `htmldjango`.

Expand Down Expand Up @@ -41,6 +44,10 @@ Plug 'yaegassy/coc-htmldjango', {'do': 'yarn install --frozen-lockfile'}
## Configuration options for coc-htmldjango

- `htmldjango.enable`: Enable coc-htmldjango extension, default: `true`
- `htmldjango.builtin.pythonPath`: Python 3.x path (Absolute path) to be used for built-in install, default: `""`
- `htmldjango.formatting.provider`: Provider for formatting. Possible options include 'djhtml' and 'unibeautify', default: `"unibeautify"`
- `htmldjango.djhtml.commandPath`: The custom path to the djhtml (Absolute path), default: `""`
- `htmldjango.djhtml.tabWidth`: Set tabwidth (--tabwidth), default: `4`
- `htmldjango.unibeautify.brace_style`: Brace style, valid option `"collapse", "collapse-preserve-inline", "expand", "end-expand", "none"`, default: `"collapse"`
- `htmldjango.unibeautify.end_with_newline`: End output with newline, default: `true`
- `htmldjango.unibeautify.force_indentation`: if indentation should be forcefully applied to markup even if it disruptively adds unintended whitespace to the documents rendered output, default: `true`
Expand All @@ -60,7 +67,17 @@ Plug 'yaegassy/coc-htmldjango', {'do': 'yarn install --frozen-lockfile'}

## Commands

- `htmldjango.Format`
- `htmldjango.unibeautify.format`
- `htmldjango.djhtml.format`
- `htmldjango.djhtml.install`

## Bult-in install (DjHTML)

coc-htmldjango allows you to create an extension-only "venv" and install "djhtml".

```vim
:CocComannd htmldjango.djhtml.install
```

## Configuration file for Unibeautify (.unibeautifyrc.{yml,yaml,json})

Expand All @@ -74,21 +91,26 @@ If there is no configuration file, the default value of `coc-htmldjango` will be

- Files containing `"{% comment %}"` will failed to format

## Related coc.nvim extension
## Inspiration (Unibeautify or DjHTML)

- [yaegassy/coc-curlylint](https://github.com/yaegassy/coc-curlylint)
Unfortunately, there is no full formatter tool dedicated to "django templates".

## Inspiration
There is no django-specific plugin for prettier either, If you want to use prettier, you need to add lots of "prettier-ignore" comments.

Unfortunately, there is no dedicated formatter tool for "django templates".
"Visual Studio Code" user community seems to be using `Unibeautify` as a formatter for django templates in many cases.

There is no django-specific plugin for prettier either, If you want to use prettier, you need to add lots of "prettier-ignore" comments.
---

There seems to be a Python tool called `DjHTML` that is currently under active development.

It seems to be an "indenter", not a full formatter.

"Visual Studio Code" user community seems to be using `Unibeautify` as a formatter for django templates in many cases, so I created `coc-htmldjango`.
I think it's a good tool, so I added a feature to make it available from `coc-htmldjango`.

## Thanks

- [Unibeautify/unibeautify](https://github.com/Unibeautify/unibeautify)
- [rtts/djhtml](https://github.com/rtts/djhtml)
- [vscode-django/vscode-django](https://github.com/vscode-django/vscode-django)
- [neoclide/coc-snippets](https://github.com/neoclide/coc-snippets)
- [neoclide/coc-html](https://github.com/neoclide/coc-html)
Expand Down
45 changes: 42 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"name": "coc-htmldjango",
"version": "0.2.0",
"djhtmlVersion": "1.4.6",
"description": "django templates (htmldjango) extension for coc.nvim. Provides formatter, snippets completion and more...",
"author": "yaegassy <yosstools@gmail.com>",
"license": "MIT",
Expand Down Expand Up @@ -36,6 +37,9 @@
"semi": true
},
"devDependencies": {
"@types/rimraf": "^3.0.0",
"@types/which": "^2.0.0",
"@types/tmp": "^0.2.0",
"@types/js-yaml": "^4.0.0",
"@types/node": "^14.6.3",
"@typescript-eslint/eslint-plugin": "^4.8.2",
Expand All @@ -49,7 +53,9 @@
"prettier": "^2.2.0",
"rimraf": "^3.0.2",
"ts-node": "^9.1.1",
"typescript": "^4.1.2"
"typescript": "^4.1.2",
"which": "^2.0.2",
"tmp": "^0.1.0"
},
"activationEvents": [
"onLanguage:htmldjango"
Expand All @@ -73,6 +79,31 @@
],
"description": "Set the template language to be used for the hover"
},
"htmldjango.builtin.pythonPath": {
"type": "string",
"default": "",
"description": "Python 3.x path (Absolute path) to be used for built-in install"
},
"htmldjango.formatting.provider": {
"type": "string",
"default": "unibeautify",
"description": "Provider for formatting. Possible options include 'djhtml' and 'unibeautify'",
"enum": [
"unibeautify",
"djhtml",
"none"
]
},
"htmldjango.djhtml.commandPath": {
"type": "string",
"default": "",
"description": "The custom path to the djhtml (Absolute path)."
},
"htmldjango.djhtml.tabWidth": {
"type": "number",
"default": 4,
"description": "Set tabwidth (--tabwidth)"
},
"htmldjango.unibeautify.brace_style": {
"type": "string",
"default": "collapse",
Expand Down Expand Up @@ -250,8 +281,16 @@
},
"commands": [
{
"command": "htmldjango.Format",
"title": "Format"
"command": "htmldjango.unibeautify.format",
"title": "Unibeautify format"
},
{
"command": "htmldjango.djhtml.format",
"title": "DjHTML format"
},
{
"command": "htmldjango.djhtml.install",
"title": "Install djhtml"
}
],
"snippets": [
Expand Down
5 changes: 0 additions & 5 deletions src/beautifiers.ts

This file was deleted.

12 changes: 12 additions & 0 deletions src/constant.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/**
* System-wide constants.
*
* May be read from package.json
*/

// @ts-ignore
import { djhtmlVersion } from '../package.json';

export const SUPPORT_LANGUAGES = ['htmldjango'];

export const DJHTML_VERSION = djhtmlVersion;
Loading