Skip to content

Commit

Permalink
Fix many typos in documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
jrief committed Apr 30, 2024
1 parent 5a7f70e commit dd7df86
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 33 deletions.
14 changes: 8 additions & 6 deletions docs/source/index.rst
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
=====================================
Documentation of ``<django-formset>``
=====================================
===============================
Documentation of django-formset
===============================

**Building beautiful Forms in Django with a contemporary User eXperience has never been easier.**
**This missing widgets and form manipulation library for Django**

``<django-formset>`` is a web component to let the browser pre-validate one or more standard
Django ``Form``-s.
``<django-formset>`` is a web component to let the browser pre-validate and manipulate one or more
Django ``Form``-s. This facilitates developers to build beautiful forms with a contemporary user
experience. This library ships with a set of widgets, which integrate seamlessly with their
Django's counterparts.


.. toctree::
Expand Down
54 changes: 27 additions & 27 deletions docs/source/richtext-extensions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ Richtext Extensions

Having a Richtext editor which can set simple property values such as **bold** or *italic* on
editable text elements is not a big deal, even the most basic implementation can do that. The
difficulty arises, when you want to set more than one property on a certain element. Take for
difficulty arises when you want to set more than one property on a certain element. Take for
instance the hyperlink, the most basic implementation requires two fields: the URL and the text to
display. But some implementors might want to set more properties, such as the rel_, the target_
display. But some implementers might want to set more properties, such as the rel_, the target_
attribute or they want to use links to download files or to link onto phone numbers or email
addresses.

Expand All @@ -21,7 +21,7 @@ page to link to from a list of available pages.
.. _rel: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/a#rel
.. _target: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/a#target

As we can see, there are many use cases where the implementor might want to extend the Richtext
As we can see, there are many use cases where the implementer might want to extend the Richtext
editor with a custom dialog form adopted to his exact needs. Since **django-formset** provides a way
to declare :ref:`dialog-forms`, we can use this to adopt our hyperlink editor to accept any
arbitrary attribute value.
Expand Down Expand Up @@ -83,12 +83,12 @@ arbitrary attribute value.

Here we define a custom dialog form for the hyperlink editor. This dialog form has four fields,
of which ``url`` and ``page`` are mapped as parameters to the anchor element in HTML. The other two
fields are used to set the text of the link and to toggle between an internal and an exernal link.
fields are used to set the text of the link and to toggle between an internal and an external link.


.. rubric:: The ``text`` field

This field is the text to display inside the achor element of the link. Since the selected text in
This field is the text to display inside the anchor element of the link. Since the selected text in
the editor is used as the link text, we have added the ``'richtext-selection': True`` attribute to
the input field. This attribute is used by the editor to set the selected text as the initial value
of the field and vice versa.
Expand All @@ -97,7 +97,7 @@ of the field and vice versa.
.. rubric:: The ``link_type`` field

This choice field is used to select the type of the link, which can either be an external link
specified by an URL, or an internal link specified by the primary key of an objects of type
specified by an URL, or an internal link specified by the primary key of an object of type
``PageModel``. The value of this field is not stored in the Richtext editor's document state,
therefore we use a functional snippets to map the document state's value to the dialog form's field:

Expand All @@ -120,8 +120,8 @@ functional snippet:
'richtext-map-to': '{href: elements.link_type.value == "external" ? elements.url.value : ""}'
This functional snippet has access to all ``elements`` of the dialog form. Therefore we can check
for the value of the field named ``link_type`` and return the value of the field named ``url``
mapping it to the attribute ``href``.
for the value of the field named ``link_type`` and return the value of the field named ``url`` and
map it to the attribute ``href``.

To map the value of the editor's document state back to the dialog, we use the attribute
``'richtext-map-from': 'href'``. This takes the values from the editor's document state and applies
Expand All @@ -145,8 +145,8 @@ The ``page`` field is a ModelChoiceField to select the internal page. It shall b
'richtext-map-to': '{page_id: elements.link_type.value == "internal" ? elements.page.value : ""}'
This functional snippet has access to all ``elements`` of the dialog form. Therefore we can check
for the value of the field named ``link_type`` and return the value of the field named ``page``
mapping it to the attribute ``page_id``.
for the value of the field named ``link_type`` and return the value of the field named ``page`` and
map it to the attribute ``page_id``.

To map the value of the editor's document state back to the dialog, we use the attribute
``'richtext-map-from': 'page_id'``. This takes the values from the editor's document state and
Expand Down Expand Up @@ -251,12 +251,6 @@ refer to the Tiptap documentation on marks_ and nodes_.
.. _nodes: https://www.tiptap.dev/api/nodes


.. rubric:: The ``icon`` attribute

This is the path to the icon which is displayed in the editor toolbar. The icon must be a SVG
file.


.. rubric:: The ``prefix`` attribute

This attribute is another unique identifier. It is used to set a name for the dialog form.
Expand All @@ -267,7 +261,7 @@ Behind the scenes

The most tricky part of the implementation is the mapping of the form fields to the editor's
document state and vice versa. Dialog forms therefore need a way to bidirectionally exchange their
values with the editor. This is done by adding the extra attributes ``richtext-map-to`` and
data with the Richtext editor. This is done by adding the extra attributes ``richtext-map-to`` and
``richtext-map-from`` to the form field widgets.


Expand All @@ -278,15 +272,17 @@ state. It is applied whenever the user clicks on the "Apply" button of the dialo
attribute can take three types of values:

* ``True``, which means that the field's value is mapped to the editor's document state using the
field's name as the key. This then is also applied in the other direction, ``richtext-map-from``
is not required in this case.
field's name as the key. If set, it also is applied in the other direction, ``richtext-map-from``
therefore is not required anymore.
* A key value. This is used to map the field's value to the editor's document state using the given
key to map it onto another key.
* A functional snippet. This is used to map the field's value to the editor's document state using a
JavaScript snippet. This snippet has access to all elements of the dialog form and can return a
value to be mapped onto the editor's document state. Accessing the values of the elements can only
be achieved using ``elements.…`` inside the snippet. This is the most flexible way, because it
can take the values of other fields into account, transform them or perform extra logic.
* A functional expression. This is used to map the field's value to the editor's document state
using a JavaScript lambda function. This snippet has access to all elements of the dialog form and
can return a value to be mapped onto the editor's document state. Accessing the values of the
elements can only be achieved using ``elements.…`` inside the snippet. This is the most flexible
way, because it can take the values of other fields into account, transform them or perform extra
logic.

Example: ``{src: JSON.parse(elements.image.dataset.fileupload).download_url}`` maps the download
URL of an uploaded image of an input element named ``image`` to the attribute ``src`` of the
editor's document state implementing the mark extension ``<img src="…" />``.
Expand All @@ -299,10 +295,11 @@ the editor. This attribute can take two types of values:

* A key value. This is used to map the editor's document state using the a key and map it to the
field of the dialog form with the given name.
* A functional snippet. This is used to map the editor's document state using using a JavaScript
snippet. This snippet has access to all attributes of the editor's document state and must return
a value to be mapped onto the given field of the dialog form. Accessing the values of the
* A functional expression. This is used to map the editor's document state using a JavaScript
lambda function. This snippet has access to all attributes of the editor's document state and must
return a value to be mapped onto the given field of the dialog form. Accessing the values of the
attributes can only be achieved using ``attributes.…`` inside the snippet.

Example: ``{dataset: {fileupload: JSON.stringify(attributes.dataset)}}`` maps the value of the
attribute ``dataset`` of the editor's document state to the ``dataset`` attribute of the
associated input field in the form dialog.
Expand All @@ -327,3 +324,6 @@ For our custom hyperlink extension, the template could look like this:
{% load page_url from hyperlink %}
<a href="{% if attrs.page_id %}{% page_url attrs.page_id %}{% else %}{{ attrs.href }}{% endif %}">{{ text }}</a>
This template then is used by the richtext renderer and loaded whenever an element of type
``custom_hyperlink`` is encountered.

0 comments on commit dd7df86

Please sign in to comment.