This change re-adds functionality for adding external plugin resources.
The resources, defined in the field, are passed to the widget, which
renders them into the data-external-plugin-resources attribute.
In ckeditor-init.js, this data attribute is read and the resources
are added to the CKEditor, using CKEditor.plugins.addExternal().
A LazyEncoder has been implemented based on Djangos DjangoJSONEncoder,
rather than json.JSONEncoder, as described [here](https://docs.djangoproject.com/en/dev/topics/serialization/#serialization-formats-json)
This allows us to use `ugettext_lazy` (and other laze functions) in
`settings.py` which adds the possibility to localize strings for use
in the `CKEDITOR_CONFIGS` settings etc.
**Example**
from django.utils.translation import ugettext_lazy as _
CKEDITOR_CONFIGS = {
'default': {
'stylesSet': [
{ 'name': _('Lead') , 'element': 'p', 'attributes': { 'class': 'lead' } },
...
]
...
}
This commit adds keyword arguments to fields.RichTextField that allow the
overriding of extraPlugins on a per-field basis, and that allow the declaration
of external plugin resources (using CKEDITOR.plugins.addExternal()).
This improves the implementation of CKEditor plugins in django apps,
because they can be hosted and deployed separately from the CKEditor sources.
As an example, here's how to define a custom RichTextField by just currying
the existing one's constructor with the new arguments:
from django.utils.functional import curry
extra_plugins = ['custom_plugin']
external_plugin_resources=[('custom_plugin', '/custom_plugin_base/', 'plugin.js')]
CustomRichTextField = curry(RichTextField, extra_plugins=extra_plugins, external_plugin_resources=external_plugin_resources)
The external_plugin_resources kwarg is a list of tuples that contain the same
information as the parameters to CKEDITOR.plugins.addExternal().
You may want to write "reverse('some_view')" for the second parameter.
If that fails due to circular imports, wrap the reverse call in a
SimpleLazyObject, like this:
from django.utils.functional import SimpleLazyObject
external_plugin_resources=[('custom_plugin', SimpleLazyObject(lambda: reverse('custom_plugin_view', kwargs=...) + 'some_relative_path/'), 'plugin.js')]
This setting allows custom CKEditor configuration settings to be passed
to the editor before being created. The design is based off of dwaiter's
django-ckeditor.