Skip to content

Commit

Permalink
The initial commit of the project.
Browse files Browse the repository at this point in the history
This commit adds all the files that have been
developed so far for the project BetterJinja.
  • Loading branch information
UltraInstinct05 committed Aug 12, 2020
0 parents commit 3830083
Show file tree
Hide file tree
Showing 31 changed files with 1,179 additions and 0 deletions.
Empty file added .gitignore
Empty file.
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Changelog
All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [1.0.0] - 2020-08-12
### Added
- Indentation for Jinja2 code blocks.
- Snippets for commonly used Jinja2 blocks.
- The main syntax file along with syntax test for the scopes.
- Auto completions for builtin tags, filters, tests and functions.
- Abiility to use <kbd>ctrl + /</kbd> for Jinja2 line comments & <kbd>ctrl + shift + /</kbd> for block comments.
9 changes: 9 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
The MIT License (MIT)

Copyright 2020 &copy; Ashwin Shenoy

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.
76 changes: 76 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
# BetterJinja

![LICENSE](https://img.shields.io/badge/LICENSE-MIT-green?style=for-the-badge) ![LICENSE](https://img.shields.io/badge/ST-Build%203092+-orange?style=for-the-badge&logo=sublime-text) ![Tag](https://img.shields.io/github/v/tag/Sublime-Instincts/BetterJinja?style=for-the-badge&logo=github&sort=semver)

A Sublime Text package that offers enhanced syntax highlighting, snippets, completions and much more for [Jinja2](https://jinja.palletsprojects.com/en/2.11.x/) templates. Read more for the full documentation.

## Features

- Indentation for code blocks.
- Snippets for common code blocks.
- Enhanced syntax highlighting for Jinja2 templates.
- Autocompletions for built in tags, filters, functions, tests & loop variables.

## Installation

#### Package Control
The best way is to install it via [Package Control](https://packagecontrol.io/). Once you have Package Control setup in Sublime Text, open the command palette and search for `Package Control: Install Package`. Search for `BetterJinja` and install it. Package Control will take care for of automatically updating the package for you if there are new releases.

You can also use `Package Control: Add Repository`. Copy the github url (without the `.git` at the end) and enter it into the input panel that pops up at the bottom when you select `Package Control: Add Repository`. Now use `Package Control: Install Package` and search for `BetterJinja` and install it.

## Documentation

### Key bindings

- The key bindings are configured so that pressing <kbd>shift + {</kbd> **twice** will automatically add spaces on both sides for the inner brace expression block & place the cursor in the center, like so `{{ | }}`.
- |||ly pressing <kbd>shift + %</kbd> within `{}` will add spaces on both sides of the inner `%` like so `{% | %}`
- You can use <kbd>ctrl + /</kbd> for inserting Jinja2 style line comments (`## This is a line comment`)
- Similarly, use <kbd>ctrl + shift + /</kbd> for block style comments (`{# This is a block comment #}`)

### Auto completions
In order to get the auto completions, go to `Preferences: Settings` from the command palette and paste the following in the `Preferences.sublime-settings -- User` (the right hand window)

```json
"auto_complete_selector": "text.jinja, meta.tag - punctuation.definition.tag.begin, source - comment - string.quoted.double.block - string.quoted.single.block - string.unquoted.heredoc",
"auto_complete_triggers":
[
{"characters": "<", "selector": "text.html"},
{"selector": "text.jinja, text.html.basic"},
]
```

If you already have these in your user settings, then just copy the Twig related portions into them.

### Snippets

| **Tab Trigger** | **Jinja2 Code Block** |
|-------------------|-------------------------------------------|
| ```jwith``` | ```{% with %}{% endwith %}``` |
| ```jraw``` | ```{% raw %}{% endraw %}``` |
| ```jmacro``` | ```{% macro %}{% endmacro %}``` |
| ```jifelse``` | ```{% if %}{% else %}{% endif %}``` |
| ```jif``` | ```{% if %}{% endif %}``` |
| ```jfor``` | ```{% for %}{% endfor %}``` |
| ```jfilter``` | ```{% filter %}{% endfilter %}``` |
| ```jextends``` | ```{% extends %}``` |
| ```jexp``` | ```{% %}``` |
| ```jcall``` | ```{% call %}{% endcall %}``` |
| ```jblock``` | ```{% block %}{% endblock %}``` |
| ```jautoescape``` | ```{% autoescape %}{% endautoescape %}``` |

## Issues & Feature requests.

There is always scope for improvements so please do report any bug(s) that you encounter or request for feature(s) that this package should support.

Please follow the issue & feature request templates that have been setup while reporting any bug(s) or requesting for feature(s) (So as to stay as organised as possible).

## License
The MIT License (MIT)

Copyright 2020 &copy; Ashwin Shenoy

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.
3 changes: 3 additions & 0 deletions messages.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"install": "messages/install.txt"
}
47 changes: 47 additions & 0 deletions messages/install.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
____ _ _ _ _ _
| _ \ | | | | | (_) (_)
| |_) | ___| |_| |_ ___ _ __ | |_ _ __ _ __ _
| _ < / _ \ __| __/ _ \ '__| | | | '_ \| |/ _` |
| |_) | __/ |_| || __/ | | |__| | | | | | | (_| |
|____/ \___|\__|\__\___|_| \____/|_|_| |_| |\__,_|
_/ |
|__/
======================================================================

BetterJinja is an enhanced syntax highlighting package for Jinja2
templates for Sublime Text. It also provides snippets, completions,
automatic indentation for Jinja2 code blocks and more !

Quick start
-----------

If you are seeing this messages, that means you have already installed
BetterJinja, which means any of your jinja files will already be
receiving syntax highlighting.

The following file extensions are supported :-
- .j2
- .jinja
- .jinja2
- .htm.j2
- .htm.jinja
- .htm.jinja2
- .html.j2
- .html.jinja
- .html.jinja2

Having Problems ?
-----------------

If you encounter any problems with BetterJinja, or you think that it
can be improved to make your work easier, please log an issue with the
issue tracker:

https://github.com/Sublime-Instincts/BetterJinja/issues

Get in Touch
------------

BetterJinja is developed & maintained by Ashwin Shenoy. If you have
any feedback regarding BetterJinja, just send a mail on
[email protected] .
55 changes: 55 additions & 0 deletions resources/completions/BetterJinja (Filters).sublime-completions
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
{
"scope": "text.jinja text.html.basic & (meta.placeholder.jinja | meta.statement.jinja)",
"completions": [
{ "trigger": "abs\tJinja2 Filter", "contents": "abs()", },
{ "trigger": "attr\tJinja2 Filter", "contents": "attr()", },
{ "trigger": "batch\tJinja2 Filter", "contents": "batch()", },
{ "trigger": "capitalize\tJinja2 Filter", "contents": "capitalize()", },
{ "trigger": "center\tJinja2 Filter", "contents": "center()", },
{ "trigger": "default\tJinja2 Filter", "contents": "default()", },
{ "trigger": "dictsort\tJinja2 Filter", "contents": "dictsort()", },
{ "trigger": "escape\tJinja2 Filter", "contents": "escape()", },
{ "trigger": "filesizeformat\tJinja2 Filter", "contents": "filesizeformat()", },
{ "trigger": "first\tJinja2 Filter", "contents": "first()", },
{ "trigger": "float\tJinja2 Filter", "contents": "float()", },
{ "trigger": "forceescape\tJinja2 Filter", "contents": "forceescape()", },
{ "trigger": "format\tJinja2 Filter", "contents": "format()", },
{ "trigger": "groupby\tJinja2 Filter", "contents": "groupby()", },
{ "trigger": "indent\tJinja2 Filter", "contents": "indent()", },
{ "trigger": "int\tJinja2 Filter", "contents": "int()", },
{ "trigger": "join\tJinja2 Filter", "contents": "join()", },
{ "trigger": "last\tJinja2 Filter", "contents": "last()", },
{ "trigger": "length\tJinja2 Filter", "contents": "length()", },
{ "trigger": "list\tJinja2 Filter", "contents": "list()", },
{ "trigger": "lower\tJinja2 Filter", "contents": "lower()", },
{ "trigger": "max\tJinja2 Filter", "contents": "max()", },
{ "trigger": "min\tJinja2 Filter", "contents": "min()", },
{ "trigger": "map\tJinja2 Filter", "contents": "map()", },
{ "trigger": "pprint\tJinja2 Filter", "contents": "pprint()", },
{ "trigger": "random\tJinja2 Filter", "contents": "random()", },
{ "trigger": "reject\tJinja2 Filter", "contents": "reject()", },
{ "trigger": "rejectattr\tJinja2 Filter", "contents": "rejectattr()", },
{ "trigger": "replace\tJinja2 Filter", "contents": "replace()", },
{ "trigger": "reverse\tJinja2 Filter", "contents": "reverse()", },
{ "trigger": "round\tJinja2 Filter", "contents": "round()", },
{ "trigger": "safe\tJinja2 Filter", "contents": "safe()", },
{ "trigger": "select\tJinja2 Filter", "contents": "select()", },
{ "trigger": "selectattr\tJinja2 Filter", "contents": "selectattr()", },
{ "trigger": "slice\tJinja2 Filter", "contents": "slice()", },
{ "trigger": "sort\tJinja2 Filter", "contents": "sort()", },
{ "trigger": "string\tJinja2 Filter", "contents": "string()", },
{ "trigger": "striptags\tJinja2 Filter", "contents": "striptags()", },
{ "trigger": "sum\tJinja2 Filter", "contents": "sum()", },
{ "trigger": "title\tJinja2 Filter", "contents": "title()", },
{ "trigger": "tojson\tJinja2 Filter", "contents": "tojson()", },
{ "trigger": "trim\tJinja2 Filter", "contents": "trim()", },
{ "trigger": "truncate\tJinja2 Filter", "contents": "truncate()", },
{ "trigger": "unique\tJinja2 Filter", "contents": "unique()", },
{ "trigger": "upper\tJinja2 Filter", "contents": "upper()", },
{ "trigger": "urlencode\tJinja2 Filter", "contents": "urlencode()", },
{ "trigger": "urlize\tJinja2 Filter", "contents": "urlize()", },
{ "trigger": "wordcount\tJinja2 Filter", "contents": "wordcount()", },
{ "trigger": "wordwrap\tJinja2 Filter", "contents": "wordwrap()", },
{ "trigger": "xmlattr\tJinja2 Filter", "contents": "xmlattr()", },
],
}
11 changes: 11 additions & 0 deletions resources/completions/BetterJinja (Functions).sublime-completions
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"scope": "text.jinja text.html.basic & (meta.placeholder.jinja | meta.statement.jinja)",
"completions": [
{ "trigger": "range\tJinja2 Function", "contents": "range()", },
{ "trigger": "lipsum\tJinja2 Function", "contents": "lipsum()", },
{ "trigger": "dict\tJinja2 Function", "contents": "dict()", },
{ "trigger": "cycler\tJinja2 Function", "contents": "cycler()", },
{ "trigger": "joiner\tJinja2 Function", "contents": "joiner()", },
{ "trigger": "namespace\tJinja2 Function", "contents": "namespace()", },
],
}
18 changes: 18 additions & 0 deletions resources/completions/BetterJinja (Loops).sublime-completions
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"scope": "text.jinja text.html.basic & (meta.placeholder.jinja | meta.statement.jinja)",
"completions": [
{ "trigger": "loop.index\tJinja2 Loop Variable", "contents": "loop.index", },
{ "trigger": "loop.index0\tJinja2 Loop Variable", "contents": "loop.index0", },
{ "trigger": "loop.revindex\tJinja2 Loop Variable", "contents": "loop.revindex", },
{ "trigger": "loop.revindex0\tJinja2 Loop Variable", "contents": "loop.revindex0", },
{ "trigger": "loop.first\tJinja2 Loop Variable", "contents": "loop.first", },
{ "trigger": "loop.last\tJinja2 Loop Variable", "contents": "loop.last", },
{ "trigger": "loop.length\tJinja2 Loop Variable", "contents": "loop.length", },
{ "trigger": "loop.cycle\tJinja2 Loop Variable", "contents": "loop.cycle", },
{ "trigger": "loop.depth\tJinja2 Loop Variable", "contents": "loop.depth", },
{ "trigger": "loop.depth0\tJinja2 Loop Variable", "contents": "loop.depth0", },
{ "trigger": "loop.previtem\tJinja2 Loop Variable", "contents": "loop.previtem", },
{ "trigger": "loop.nextitem\tJinja2 Loop Variable", "contents": "loop.nextitem", },
{ "trigger": "loop.changed\tJinja2 Loop Variable", "contents": "loop.changed()", },
],
}
35 changes: 35 additions & 0 deletions resources/completions/BetterJinja (Tags).sublime-completions
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"scope": "text.jinja text.html.basic & (meta.placeholder.jinja | meta.statement.jinja)",
"completions": [
// Completions for blocks
{ "trigger": "for\tJinja2 Block", "contents": "for", },
{ "trigger": "if\tJinja2 Block", "contents": "if", },
{ "trigger": "raw\tJinja2 Block", "contents": "raw", },
{ "trigger": "block\tJinja2 Block", "contents": "block", },
{ "trigger": "extends\tJinja2 Block", "contents": "extends", },
{ "trigger": "macro\tJinja2 Block", "contents": "macro", },
{ "trigger": "call\tJinja2 Block", "contents": "call", },
{ "trigger": "filter\tJinja2 Block", "contents": "filter", },
{ "trigger": "set\tJinja2 Block", "contents": "set", },
{ "trigger": "include\tJinja2 Block", "contents": "include", },
{ "trigger": "pluralize\tJinja2 Block", "contents": "pluralize", },
{ "trigger": "trans\tJinja2 Block", "contents": "trans", },
{ "trigger": "do\tJinja2 Block", "contents": "do", },
{ "trigger": "debug\tJinja2 Block", "contents": "debug", },
{ "trigger": "with\tJinja2 Block", "contents": "with", },
{ "trigger": "autoescape\tJinja2 Block", "contents": "autoescape", },

// Completions for endblocks
{ "trigger": "endautoescape\tJinja2 Block", "contents": "endautoescape", },
{ "trigger": "endwith\tJinja2 Block", "contents": "endwith", },
{ "trigger": "endtrans\tJinja2 Block", "contents": "endtrans", },
{ "trigger": "endset\tJinja2 Block", "contents": "endset", },
{ "trigger": "endfilter\tJinja2 Block", "contents": "endfilter", },
{ "trigger": "endcall\tJinja2 Block", "contents": "endcall", },
{ "trigger": "endmacro\tJinja2 Block", "contents": "endmacro", },
{ "trigger": "endblock\tJinja2 endblock", "contents": "endblock", },
{ "trigger": "endraw\tJinja2 Block", "contents": "endraw", },
{ "trigger": "endif\tJinja2 Block", "contents": "endif", },
{ "trigger": "endfor\tJinja2 EndBlock", "contents": "endfor", },
],
}
33 changes: 33 additions & 0 deletions resources/completions/BetterJinja (Tests).sublime-completions
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"scope": "text.jinja text.html.basic & (meta.placeholder.jinja | meta.statement.jinja)",
"completions": [
{ "trigger": "boolean\tJinja2 Test", "contents": "boolean()", },
{ "trigger": "callable\tJinja2 Test", "contents": "callable()", },
{ "trigger": "defined\tJinja2 Test", "contents": "defined()", },
{ "trigger": "divisibleby\tJinja2 Test", "contents": "divisibleby()", },
{ "trigger": "eq\tJinja2 Test", "contents": "eq()", },
{ "trigger": "escaped\tJinja2 Test", "contents": "escaped()", },
{ "trigger": "even\tJinja2 Test", "contents": "even()", },
{ "trigger": "false\tJinja2 Test", "contents": "false()", },
{ "trigger": "float\tJinja2 Test", "contents": "float()", },
{ "trigger": "ge\tJinja2 Test", "contents": "ge()", },
{ "trigger": "gt\tJinja2 Test", "contents": "gt()", },
{ "trigger": "in\tJinja2 Test", "contents": "in()", },
{ "trigger": "integer\tJinja2 Test", "contents": "integer()", },
{ "trigger": "iterable\tJinja2 Test", "contents": "iterable()", },
{ "trigger": "le\tJinja2 Test", "contents": "le()", },
{ "trigger": "lower\tJinja2 Test", "contents": "lower()", },
{ "trigger": "lt\tJinja2 Test", "contents": "lt()", },
{ "trigger": "mapping\tJinja2 Test", "contents": "mapping()", },
{ "trigger": "ne\tJinja2 Test", "contents": "ne()", },
{ "trigger": "none\tJinja2 Test", "contents": "none()", },
{ "trigger": "number\tJinja2 Test", "contents": "number()", },
{ "trigger": "odd\tJinja2 Test", "contents": "odd()", },
{ "trigger": "sameas\tJinja2 Test", "contents": "sameas()", },
{ "trigger": "sequence\tJinja2 Test", "contents": "sequence()", },
{ "trigger": "string\tJinja2 Test", "contents": "string()", },
{ "trigger": "true\tJinja2 Test", "contents": "true()", },
{ "trigger": "undefined\tJinja2 Test", "contents": "undefined()", },
{ "trigger": "upper\tJinja2 Test", "contents": "upper()", },
],
}
28 changes: 28 additions & 0 deletions resources/keymaps/Default.sublime-keymap
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
[
{
"keys": ["%"],
"command": "insert_snippet",
"args": {
"contents": "% ${0} %"
},
"context": [
{ "key": "selector", "operator": "equal", "operand": "text.jinja" },
{ "key": "setting.auto_match_enabled", "operator": "equal", "operand": true },
{ "key": "preceding_text", "operator": "regex_contains", "operand": "{$", "match_all": true },
{ "key": "following_text", "operator": "regex_contains", "operand": "}$", "match_all": true },
],
},
{
"keys": ["{"],
"command": "insert_snippet",
"args": {
"contents": "{ ${0} }"
},
"context": [
{ "key": "selector", "operator": "equal", "operand": "text.jinja" },
{ "key": "setting.auto_match_enabled", "operator": "equal", "operand": true },
{ "key": "preceding_text", "operator": "regex_contains", "operand": "{$", "match_all": true },
{ "key": "following_text", "operator": "regex_contains", "operand": "}$", "match_all": true },
],
}
]
Loading

0 comments on commit 3830083

Please sign in to comment.