An EditorJS Field with dependency injection of tools support for Django >4.*
Project description
Django EditorJS Field
Django >4.* (Not tested in old versions)
An EditorJS Field with dependency injection of tools support for Django >4.*
Features
- Dependency injection for tools
- Templatetag support
- All EditorJS configuration supported
- Without custom backend
- Customized editor in admin
- Debug support
Installation and Usage
Installation
Some day it will be django-editorjs-field...
Install package via pip
:
pip install django-editorjs-field-next
Add package to INSTALLED_APPS
:
INSTALLED_APPS = [
...
"django_editorjs_field"
]
Usage
Note!
If you will not provide configuration, you will have only default Paragraph Tool.
Example of field configuration:
from django_editorjs_field.tool import EditorJSTool as Tool
EditorJSField(
tools=[
Tool(name="Header", url="//cdn.jsdelivr.net/npm/@editorjs/header", template_name="tools/h.html"),
Tool(
name="Code",
url="https://cdn.jsdelivr.net/npm/@editorjs/code@2.8.0",
class_name="CodeTool",
template_name="tools/code.html"
)
]
)
Any kwargs that you add will pass to EditorJS configuration. For example, if you want autofocus
, placeholder
and i18n
, you just add to field arguments:
autofocus=False,
placeholder="EditorJSPlaceholder",
i18n={
"messages": {
"toolNames": {
"Heading": "Заголовок"
}
}
}
templatetag
Example of templatetag:
{% load editorjs %}
{% for article in articles_list %}
<div>
<h3>{{ article.title }}</h3>
{% render article %}
</div>
{% endfor %}
Tools
All tools (plugins) are independent objects. Tool constructor define as:
def __init__(self, name: str, url: str, template_name: str, class_name: str | None = None, **kwargs):
"""
An EditorJSTool constructor
...
Attributes
==========
name : str
Must be unique!
A name of a Tool. Used as a type in EditorJS.
url : str
A URL or Path to JS-file of Tool.
template_name : str
A Path to template for output rendering.
class_name : str | None
Name attribute is used by default.
A class name of Tool, which JS need to call constructor for.
version : str | None
Required plugin version.
"""
Override Paragraph Tool
In order to override Paragraph Tool you need to pass it as a tool into field. Example:
from django_editorjs_field.tool import EditorJSTool as Tool
EditorJSField(
tools=[
Tool(
name="paragraph",
url="//cdn.jsdelivr.net/npm/@editorjs/paragraph@2.0.2",
class_name="Paragraph",
template_name="tools/p.html"
)
Tool(name="Header", url="//cdn.jsdelivr.net/npm/@editorjs/header", template_name="tools/h.html"),
],
...
)
License
MIT
Authors
Evgeniy Gribanov
FAQ
About Debug support
If you run Django in DEBUG mode, your EditorJS inherit this mode too. It means that you will have usefull messages in your browser console about Editor Configuration and work.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file django_editorjs_field_next-0.1.2.tar.gz
.
File metadata
- Download URL: django_editorjs_field_next-0.1.2.tar.gz
- Upload date:
- Size: 8.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.3.1 CPython/3.11.1 Linux/5.15.0-1024-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6fcfd05beef13c66d589e3385ecdad1a206924c520d400f8dab7a4bd24d16806 |
|
MD5 | 43067b430369fab4ba23001522ed0e89 |
|
BLAKE2b-256 | b7419bc45e2b421164c0db9b7a41135fdd96be2de637d83e140fd6feb8075986 |
File details
Details for the file django_editorjs_field_next-0.1.2-py3-none-any.whl
.
File metadata
- Download URL: django_editorjs_field_next-0.1.2-py3-none-any.whl
- Upload date:
- Size: 10.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.3.1 CPython/3.11.1 Linux/5.15.0-1024-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ebff2145962d6e337f66c657021533da2aed486224bd1d5b25aee3c47a06f204 |
|
MD5 | 1400f13cd039ead550a7a6877309a24d |
|
BLAKE2b-256 | 580c656563bd6d5bc71d80619629cddf0f3ef704f0f998e9c5d1cd1411d64580 |