Skip to main content

An EditorJS Field with dependency injection of tools support for Django >4.*

Project description

Django EditorJS Field

Code style: black

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.
    """

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django_editorjs_field_next-0.1.0.tar.gz (8.7 kB view details)

Uploaded Source

Built Distribution

django_editorjs_field_next-0.1.0-py3-none-any.whl (10.2 kB view details)

Uploaded Python 3

File details

Details for the file django_editorjs_field_next-0.1.0.tar.gz.

File metadata

  • Download URL: django_editorjs_field_next-0.1.0.tar.gz
  • Upload date:
  • Size: 8.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.2.2 CPython/3.11.0 Linux/5.10.0-19-amd64

File hashes

Hashes for django_editorjs_field_next-0.1.0.tar.gz
Algorithm Hash digest
SHA256 d7ba99fe67f699fbdd9322a9cda33f4a7b5eddf81c0ec136b3bcc8e29f041fda
MD5 d2a16a0d58990eaa7631ad76d1b1ceff
BLAKE2b-256 7cbb33310cab873577d62cf2a5b1d17e507ed22e914b510f9f5638871106cc1a

See more details on using hashes here.

File details

Details for the file django_editorjs_field_next-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for django_editorjs_field_next-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ce675a53bd6f7e54532be091c006adf34701d75ae237ae1063e7dff4af28b3fb
MD5 087933042ff842740f4edf6a5ceef30f
BLAKE2b-256 eea7795d8215227387b0fe172790f39c8562f8fe3236554a2aa0f00ccc8dca44

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page