0
0
mirror of https://github.com/wagtail/wagtail.git synced 2024-12-01 11:41:20 +01:00

Define identifier attribute on LinkHandler / EmbedHandler

This commit is contained in:
Matt Westcott 2018-04-27 02:02:10 +01:00
parent 986abd10ea
commit c5c16f7b35
9 changed files with 16 additions and 8 deletions

View File

@ -68,16 +68,16 @@ class FeatureRegistry:
except KeyError:
return None
def register_link_type(self, link_type, handler):
self.link_types[link_type] = handler
def register_link_type(self, handler):
self.link_types[handler.identifier] = handler
def get_link_types(self):
if not self.has_scanned_for_features:
self._scan_for_features()
return self.link_types
def register_embed_type(self, embed_type, handler):
self.embed_types[embed_type] = handler
def register_embed_type(self, handler):
self.embed_types[handler.identifier] = handler
def get_embed_types(self):
if not self.has_scanned_for_features:

View File

@ -5,6 +5,8 @@ from wagtail.core.rich_text import LinkHandler
class PageLinkHandler(LinkHandler):
identifier = 'page'
@staticmethod
def get_model():
return Page

View File

@ -40,7 +40,7 @@ def register_core_features(features):
features.default_features.append('hr')
features.default_features.append('link')
features.register_link_type('page', PageLinkHandler)
features.register_link_type(PageLinkHandler)
features.default_features.append('bold')

View File

@ -8,6 +8,8 @@ from wagtail.documents.models import get_document_model
# Front-end conversion
class DocumentLinkHandler(LinkHandler):
identifier = 'document'
@staticmethod
def get_model():
return get_document_model()

View File

@ -68,7 +68,7 @@ def editor_js():
@hooks.register('register_rich_text_features')
def register_document_feature(features):
features.register_link_type('document', DocumentLinkHandler)
features.register_link_type(DocumentLinkHandler)
features.register_editor_plugin(
'hallo', 'document-link',

View File

@ -7,6 +7,8 @@ from wagtail.embeds.models import Embed
# Front-end conversion
class MediaEmbedHandler(EmbedHandler):
identifier = 'media'
@staticmethod
def get_model():
return Embed

View File

@ -34,7 +34,7 @@ def editor_js():
@hooks.register('register_rich_text_features')
def register_embed_feature(features):
# define a handler for converting <embed embedtype="media"> tags into frontend HTML
features.register_embed_type('media', MediaEmbedHandler)
features.register_embed_type(MediaEmbedHandler)
# define a hallo.js plugin to use when the 'embed' feature is active
features.register_editor_plugin(

View File

@ -8,6 +8,8 @@ from wagtail.images.formats import get_image_format
# Front-end conversion
class ImageEmbedHandler(EmbedHandler):
identifier = 'image'
@staticmethod
def get_model():
return get_image_model()

View File

@ -61,7 +61,7 @@ def editor_js():
@hooks.register('register_rich_text_features')
def register_image_feature(features):
# define a handler for converting <embed embedtype="image"> tags into frontend HTML
features.register_embed_type('image', ImageEmbedHandler)
features.register_embed_type(ImageEmbedHandler)
# define a hallo.js plugin to use when the 'image' feature is active
features.register_editor_plugin(