mirror of
https://github.com/wagtail/wagtail.git
synced 2024-12-01 11:41:20 +01:00
Support defining media (js/css) in HalloPlugin objects
This commit is contained in:
parent
092cc8affc
commit
49193243f4
@ -97,5 +97,9 @@ def polite_pages_only(parent_page, pages, request):
|
||||
@hooks.register('register_rich_text_features')
|
||||
def register_blockquote_feature(features):
|
||||
features.register_editor_plugin(
|
||||
'hallo', 'blockquote', HalloPlugin(name='halloblockquote')
|
||||
'hallo', 'blockquote', HalloPlugin(
|
||||
name='halloblockquote',
|
||||
js=[static('testapp/js/hallo-blockquote.js')],
|
||||
css={'all': [static('testapp/css/hallo-blockquote.css')]},
|
||||
)
|
||||
)
|
||||
|
@ -28,10 +28,10 @@ class HalloRichTextArea(WidgetWithScript, widgets.Textarea):
|
||||
else:
|
||||
# construct a list of plugin objects, by querying the feature registry
|
||||
# and keeping the non-null responses from get_editor_plugin
|
||||
self.plugins = filter(None, [
|
||||
self.plugins = list(filter(None, [
|
||||
features.get_editor_plugin('hallo', feature_name)
|
||||
for feature_name in self.features
|
||||
])
|
||||
]))
|
||||
|
||||
super(HalloRichTextArea, self).__init__(*args, **kwargs)
|
||||
|
||||
@ -66,7 +66,7 @@ class HalloRichTextArea(WidgetWithScript, widgets.Textarea):
|
||||
|
||||
@property
|
||||
def media(self):
|
||||
return Media(js=[
|
||||
media = Media(js=[
|
||||
static('wagtailadmin/js/vendor/hallo.js'),
|
||||
static('wagtailadmin/js/hallo-bootstrap.js'),
|
||||
static('wagtailadmin/js/hallo-plugins/hallo-wagtaillink.js'),
|
||||
@ -74,16 +74,28 @@ class HalloRichTextArea(WidgetWithScript, widgets.Textarea):
|
||||
static('wagtailadmin/js/hallo-plugins/hallo-requireparagraphs.js'),
|
||||
])
|
||||
|
||||
if self.plugins is not None:
|
||||
for plugin in self.plugins:
|
||||
media += plugin.media
|
||||
|
||||
return media
|
||||
|
||||
|
||||
class HalloPlugin(object):
|
||||
def __init__(self, **kwargs):
|
||||
self.name = kwargs.pop('name', None)
|
||||
self.options = kwargs.pop('options', {})
|
||||
self.name = kwargs.get('name', None)
|
||||
self.options = kwargs.get('options', {})
|
||||
self.js = kwargs.get('js', None)
|
||||
self.css = kwargs.get('css', None)
|
||||
|
||||
def construct_plugins_list(self, plugins):
|
||||
if self.name is not None:
|
||||
plugins[self.name] = self.options
|
||||
|
||||
@property
|
||||
def media(self):
|
||||
return Media(js=self.js, css=self.css)
|
||||
|
||||
|
||||
DEFAULT_RICH_TEXT_EDITORS = {
|
||||
'default': {
|
||||
|
@ -291,6 +291,10 @@ class TestHalloJsWithFeaturesKwarg(BaseRichTextEditHandlerTestCase, WagtailTestU
|
||||
self.assertNotContains(response, '"halloheadings":')
|
||||
self.assertNotContains(response, '"hallowagtailimage":')
|
||||
|
||||
# check that media (js/css) from the features is being imported
|
||||
self.assertContains(response, 'testapp/js/hallo-blockquote.js')
|
||||
self.assertContains(response, 'testapp/css/hallo-blockquote.css')
|
||||
|
||||
def test_features_list_on_rich_text_block(self):
|
||||
block = RichTextBlock(features=['blockquote', 'embed', 'made-up-feature'])
|
||||
|
||||
@ -302,6 +306,11 @@ class TestHalloJsWithFeaturesKwarg(BaseRichTextEditHandlerTestCase, WagtailTestU
|
||||
self.assertNotIn('"halloheadings":', form_html)
|
||||
self.assertNotIn('"hallowagtailimage":', form_html)
|
||||
|
||||
# check that media (js/css) from the features is being imported
|
||||
media_html = str(block.media)
|
||||
self.assertIn('testapp/js/hallo-blockquote.js', media_html)
|
||||
self.assertIn('testapp/css/hallo-blockquote.css', media_html)
|
||||
|
||||
|
||||
@override_settings(WAGTAILADMIN_RICH_TEXT_EDITORS={
|
||||
'default': {
|
||||
|
Loading…
Reference in New Issue
Block a user