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 "Hover" feature #1

Merged
merged 1 commit into from
Apr 27, 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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ django templates (htmldjango) extension for [coc.nvim](https://github.com/neocli
## Features

- Format by [Unibeautify](https://unibeautify.com/) (Beautifiers: JS-Beautify + Pretty Diff)
- Hover
- 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"
Expand Down
11 changes: 11 additions & 0 deletions data/hover/django/add.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# add

Adds the argument to the value.

---

```htmldjango
{{ value|add:"2" }}

{{ first|add:second }}
```
11 changes: 11 additions & 0 deletions data/hover/django/addslashes.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# addslashes

Adds slashes before quotes. Useful for escaping strings in CSV, for example.

---

```htmldjango
{{ value|addslashes }}
```

If value is "I'm using Django", the output will be "I\'m using Django".
11 changes: 11 additions & 0 deletions data/hover/django/autoescape.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# autoescape

Controls the current auto-escaping behavior. This tag takes either on or off as an argument and that determines whether auto-escaping is in effect inside the block. The block is closed with an endautoescape ending tag.

---

```htmldjango
{% autoescape on %}
{{ body }}
{% endautoescape %}
```
16 changes: 16 additions & 0 deletions data/hover/django/block.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# block

Outputs a whole load of debugging information, including the current context and imported modules.

---

```htmldjango
{% block title %}My amazing blog{% endblock %}

{% block content %}
{% for entry in blog_entries %}
<h2>{{ entry.title }}</h2>
<p>{{ entry.body }}</p>
{% endfor %}
{% endblock %}
```
11 changes: 11 additions & 0 deletions data/hover/django/capfirst.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# capfirst

Capitalizes the first character of the value. If the first character is not a letter, this filter has no effect.

---

```htmldjango
{{ value|capfirst }}
```

If value is "django", the output will be "Django".
11 changes: 11 additions & 0 deletions data/hover/django/center.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# center

Centers the value in a field of a given width.

---

```htmldjango
"{{ value|center:"15" }}"
```

If value is `"Django"`, the output will be `" Django "`.
12 changes: 12 additions & 0 deletions data/hover/django/comment.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# comment

Ignores everything between `{% comment %}` and `{% endcomment %}`. An optional note may be inserted in the first tag. For example, this is useful when commenting out code for documenting why the code was disabled.

---

```htmldjango
<p>Rendered text with {{ pub_date|date:"c" }}</p>
{% comment "Optional note" %}
<p>Commented out text with {{ create_date|date:"c" }}</p>
{% endcomment %}
```
7 changes: 7 additions & 0 deletions data/hover/django/csrf_token.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# csrf_token

---

```htmldjango
<form method="post">{% csrf_token %}
```
11 changes: 11 additions & 0 deletions data/hover/django/cut.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# cut

Removes all values of arg from the given string.

---

```htmldjango
{{ value|cut:" " }}
```

If value is `"String with spaces"`, the output will be `"Stringwithspaces"`.
15 changes: 15 additions & 0 deletions data/hover/django/cycle.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# cycle

Produces one of its arguments each time this tag is encountered. The first argument is produced on the first encounter, the second argument on the second encounter, and so forth. Once all arguments are exhausted, the tag cycles to the first argument and produces it again.

This tag is particularly useful in a loop:

---

```htmldjango
{% for o in some_list %}
<tr class="{% cycle 'row1' 'row2' %}">
...
</tr>
{% endfor %}
```
17 changes: 17 additions & 0 deletions data/hover/django/date.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# date

Formats a date according to the given format.

Uses a similar format as PHP’s date() function (https://php.net/date) with some differences.

---

```htmldjango
{{ value|date:"D d M Y" }}

{{ value|date:"SHORT_DATE_FORMAT" }}

{{ value|date }}

{{ value|date:"D d M Y" }} {{ value|time:"H:i" }}
```
5 changes: 5 additions & 0 deletions data/hover/django/debug.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# debug

Outputs a whole load of debugging information, including the current context and imported modules.

---
11 changes: 11 additions & 0 deletions data/hover/django/default.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# default

If value evaluates to `False`, uses the given default. Otherwise, uses the value.

---

```htmldjango
{{ value|default:"nothing" }}
```

If `value` is `""` (the empty string), the output will be `nothing`.
13 changes: 13 additions & 0 deletions data/hover/django/default_if_none.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# default_if_none

If (and only if) value is `None`, uses the given default. Otherwise, uses the value.

Note that if an empty string is given, the default value will not be used. Use the `default` filter if you want to fallback for empty strings.

---

```htmldjango
{{ value|default_if_none:"nothing" }}
```

If `value` is `None`, the output will be `nothing`.
9 changes: 9 additions & 0 deletions data/hover/django/dictsort.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# dictsort

Takes a list of dictionaries and returns that list sorted by the key given in the argument.

---

```htmldjango
{{ value|dictsort:"name" }}
```
3 changes: 3 additions & 0 deletions data/hover/django/dictsortreversed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# dictsortreversed

Takes a list of dictionaries and returns that list sorted in reverse order by the key given in the argument. This works exactly the same as the above filter, but the returned value will be in reverse order.
11 changes: 11 additions & 0 deletions data/hover/django/divisibleby.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# divisibleby

Returns `True` if the value is divisible by the argument.

---

```htmldjango
{{ value|divisibleby:"3" }}
```

If `value` is `21`, the output would be `True`.
30 changes: 30 additions & 0 deletions data/hover/django/empty.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# empty

The `for` tag can take an optional `{% empty %}` clause whose text is displayed if the given array is empty or could not be found:

---

```htmldjango
<ul>
{% for athlete in athlete_list %}
<li>{{ athlete.name }}</li>
{% empty %}
<li>Sorry, no athletes in this list.</li>
{% endfor %}
</ul>
```

---

```htmldjango
<ul>
{% if athlete_list %}
{% for athlete in athlete_list %}
<li>{{ athlete.name }}</li>
{% endfor %}
{% else %}
<li>Sorry, no athletes in this list.</li>
{% endif %}
</ul>
```

11 changes: 11 additions & 0 deletions data/hover/django/escape.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# escape

Escapes a string’s HTML. Specifically.

---

```htmldjango
{% autoescape off %}
{{ title|escape }}
{% endautoescape %}
```
9 changes: 9 additions & 0 deletions data/hover/django/escapejs.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# escapejs

Escapes characters for use in JavaScript strings. This does not make the string safe for use in HTML or JavaScript template literals, but does protect you from syntax errors when using templates to generate JavaScript/JSON.

---

```htmldjango
{{ value|escapejs }}
```
20 changes: 20 additions & 0 deletions data/hover/django/extends.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# extends

Signals that this template extends a parent template.

This tag can be used in two ways:

- `{% extends "base.html" %}` (with quotes) uses the literal value
`"base.html"` as the name of the parent template to extend.
- `{% extends variable %}` uses the value of `variable`. If the variable
evaluates to a string, Django will use that string as the name of the
parent template. If the variable evaluates to a `Template` object, Django
will use that object as the parent template.

---

```htmldjango
{% extends "./base2.html" %}
{% extends "../base1.html" %}
{% extends "./my/base3.html" %}
```
11 changes: 11 additions & 0 deletions data/hover/django/filesizeformat.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# filesizeformat

Formats the value like a "human-readable" file size (i.e. `'13 KB'`, `'4.1 MB'`, `'102 bytes'`, etc.).

---

```htmldjango
{{ value|filesizeformat }}
```

If `value` is 123456789, the output would be `117.7 MB`.
13 changes: 13 additions & 0 deletions data/hover/django/filter.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# filter

Filters the contents of the block through one or more filters. Multiple filters can be specified with pipes and filters can have arguments, just as in variable syntax.

Note that the block includes all the text between the `filter` and `endfilter` tags.

---

```htmldjango
{% filter force_escape|lower %}
This text will be HTML-escaped, and will appear in all lowercase.
{% endfilter %}
```
11 changes: 11 additions & 0 deletions data/hover/django/first.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# first

Returns the first item in a list.

---

```htmldjango
{{ value|first }}
```

If `value` is the list `['a', 'b', 'c']`, the output will be `'a'`.
11 changes: 11 additions & 0 deletions data/hover/django/firstof.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# firstof

Outputs the first argument variable that is not "false" (i.e. exists, is not empty, is not a false boolean value, and is not a zero numeric value). Outputs nothing if all the passed variables are "false".

---

```htmldjango
{% firstof var1 var2 var3 %}

{% firstof var1 var2 var3 as value %}
```
3 changes: 3 additions & 0 deletions data/hover/django/floatformat.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# floatformat

When used without an argument, rounds a floating-point number to one decimal place – but only if there’s a decimal part to be displayed.
21 changes: 21 additions & 0 deletions data/hover/django/for.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# for

Loops over each item in an array, making the item available in a context variable. For example, to display a list of athletes provided in athlete_list:

---

```htmldjango
<ul>
{% for athlete in athlete_list %}
<li>{{ athlete.name }}</li>
{% endfor %}
</ul>

{% for x, y in points %}
There is a point at {{ x }},{{ y }}
{% endfor %}

{% for key, value in data.items %}
{{ key }}: {{ value }}
{% endfor %}
```
13 changes: 13 additions & 0 deletions data/hover/django/force_escape.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# force_escape

Applies HTML escaping to a string (see the `escape` filter for details). This filter is applied immediately and returns a new, escaped string. This is useful in the rare cases where you need multiple escaping or want to apply other filters to the escaped results. Normally, you want to use the `escape` filter.

For example, if you want to catch the `<p>` HTML elements created by the `linebreaks` filter:

---

```htmldjango
{% autoescape off %}
{{ body|linebreaks|force_escape }}
{% endautoescape %}
```
11 changes: 11 additions & 0 deletions data/hover/django/get_digit.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# get_digit

Given a whole number, returns the requested digit, where 1 is the right-most digit, 2 is the second-right-most digit, etc. Returns the original value for invalid input (if input or argument is not an integer, or if argument is less than 1). Otherwise, output is always an integer.

---

```htmldjango
{{ value|get_digit:"2" }}
```

If value is `123456789`, the output will be `8`.
12 changes: 12 additions & 0 deletions data/hover/django/get_media_prefix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# get_media_prefix

Similar to the `get_static_prefix`, get_media_prefix populates a template variable with the media prefix `MEDIA_URL`, e.g.:

---

```htmldjango
{% load static %}
<body data-media-url="{% get_media_prefix %}">
```

By storing the value in a data attribute, we ensure it's escaped appropriately if we want to use it in a JavaScript context.
Loading