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

Support djangocms-static-ace to load ace code editor from static files #156

Merged
merged 6 commits into from
Sep 1, 2022
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
4 changes: 4 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
Changelog
=========

unreleased
==========

* Added support for djangocms-static-ace to serve the ace code editor locally

2.0.0 (2020-09-02)
==================
Expand Down
10 changes: 9 additions & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,13 @@ For a manual install:

* run ``python manage.py migrate``

The Code plugin uses the ace code editor which is loaded from a CDN by default.
If you want the ace code editor to be served from static files, please use
``djangocms-bootstrap4[static-ace]`` instead of ``djangocms-bootstrap4`` in your
requirements or with pip. Make the static files fore the ace code editor available
to your project by adding ``djangocms_static_ace`` to your project's
``INSTALLED_APPS``.


Configuration
-------------
Expand Down Expand Up @@ -110,7 +117,8 @@ It provides the following **standard** Bootstrap 4 components:
* `Tabs <https://getbootstrap.com/docs/4.0/components/navs/#tabs>`_
* `Utilities (Spacing) <https://getbootstrap.com/docs/4.0/utilities/>`_

django CMS Bootstrap 4 **does not** add the styles or javascript files to your frontend, these need to be added at your discretion.
django CMS Bootstrap 4 **does not** add the styles or javascript files to your
frontend, these need to be added at your discretion.


Settings
Expand Down
8 changes: 8 additions & 0 deletions djangocms_bootstrap4/contrib/bootstrap4_content/forms.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
from django.conf import settings as django_settings
from django.forms.models import ModelForm
from django.forms.widgets import Textarea


class Bootstrap4CodeForm(ModelForm):
class Media:
js = (
"admin/vendor/ace/ace.js"
if "djangocms_static_ace" in django_settings.INSTALLED_APPS
else "https://cdnjs.cloudflare.com/ajax/libs/ace/1.9.6/ace.js",
)

class Meta:
# When used inside djangocms-text-ckeditor
# this causes the label field to be prefilled with the selected text.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
{% extends "admin/change_form.html" %}

{% block object-tools %}
{{ block.super }}

<script src="https://cdnjs.cloudflare.com/ajax/libs/ace/1.2.9/ace.js"></script>
<script>
{{ block.super }}<script>
django.jQuery(function () {
// ace editor cannot be attached directly to a textarea
var textarea = django.jQuery('textarea').css('display', 'none');
Expand All @@ -18,7 +15,19 @@

// init editor with settings
var editor = ace.edit(div[0]);
editor.setTheme('ace/theme/github');
var darkMode;

if (window.parent.CMS.API.Helpers.getColorScheme) {
darkMode = window.parent.CMS.API.Helpers.getColorScheme() === 'dark';
} else {
// django CMS pre-3.11.1
darkMode = window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches;
}
if (darkMode) {
editor.setTheme('ace/theme/tomorrow_night');
} else {
editor.setTheme('ace/theme/github');
}
editor.getSession().setValue(textarea.val());
editor.getSession().setMode('ace/mode/html');
editor.setOptions({
Expand Down
8 changes: 8 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@
]


EXTRA_REQUIREMENTS = {
"static-ace": [
"djangocms-static-ace",
]
}


CLASSIFIERS = [
'Development Status :: 5 - Production/Stable',
'Environment :: Web Environment',
Expand Down Expand Up @@ -56,6 +63,7 @@
include_package_data=True,
zip_safe=False,
install_requires=REQUIREMENTS,
extras_require=EXTRA_REQUIREMENTS,
classifiers=CLASSIFIERS,
test_suite='tests.settings.run',
)
6 changes: 6 additions & 0 deletions tests/test_migrations.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,18 @@

from django.core.management import call_command
from django.test import TestCase, override_settings
from cms import __version__
from distutils.version import LooseVersion


class MigrationTestCase(TestCase):

@override_settings(MIGRATION_MODULES={})
def test_for_missing_migrations(self):
if LooseVersion("3.9") <= LooseVersion(__version__) < LooseVersion("3.10"):
# django-cms 3.9 creates migrations to BigAutoField hence skip this test
return

output = StringIO()
options = {
'interactive': False,
Expand Down