Ejemplo n.º 1
0
 def test_missing_editor_plugin_returns_none(self):
     features = FeatureRegistry()
     self.assertIsNone(
         features.get_editor_plugin('made_up_editor', 'blockquote')
     )
     self.assertIsNone(
         features.get_editor_plugin('hallo', 'made_up_feature')
     )
Ejemplo n.º 2
0
 def test_missing_editor_plugin_returns_none(self):
     features = FeatureRegistry()
     self.assertIsNone(
         features.get_editor_plugin('made_up_editor', 'blockquote')
     )
     self.assertIsNone(
         features.get_editor_plugin('hallo', 'made_up_feature')
     )
Ejemplo n.º 3
0
    def test_legacy_register_embed_type(self):
        def embed_expand_db_attributes(attrs):
            return '<div>embedded content: %s</div>' % attrs['content']

        features = FeatureRegistry()
        features.register_embed_type('mock_embed', embed_expand_db_attributes)

        handler = features.get_embed_types()['mock_embed']
        self.assertEqual(handler.expand_db_attributes({'content': 'foo'}),
                         '<div>embedded content: foo</div>')
Ejemplo n.º 4
0
    def test_legacy_register_embed_type(self):
        def embed_expand_db_attributes(attrs):
            return '<div>embedded content: %s</div>' % attrs['content']

        features = FeatureRegistry()
        features.register_embed_type('mock_embed', embed_expand_db_attributes)

        handler = features.get_embed_types()['mock_embed']
        self.assertEqual(
            handler.expand_db_attributes({'content': 'foo'}),
            '<div>embedded content: foo</div>'
        )
Ejemplo n.º 5
0
    def test_legacy_register_link_type(self):
        User = get_user_model()
        User.objects.create(username='******', email='*****@*****.**')

        def user_expand_db_attributes(attrs):
            user = User.objects.get(username=attrs['username'])
            return '<a href="mailto:%s">' % user.email

        features = FeatureRegistry()
        features.register_link_type('user', user_expand_db_attributes)

        handler = features.get_link_types()['user']
        self.assertEqual(handler.expand_db_attributes({'username': '******'}),
                         '<a href="mailto:[email protected]">')
Ejemplo n.º 6
0
    def test_legacy_register_link_type(self):
        User = get_user_model()
        User.objects.create(username='******', email='*****@*****.**')

        def user_expand_db_attributes(attrs):
            user = User.objects.get(username=attrs['username'])
            return '<a href="mailto:%s">' % user.email

        features = FeatureRegistry()
        features.register_link_type('user', user_expand_db_attributes)

        handler = features.get_link_types()['user']
        self.assertEqual(
            handler.expand_db_attributes({'username': '******'}),
            '<a href="mailto:[email protected]">'
        )
Ejemplo n.º 7
0
 def test_register_rich_text_features_hook(self):
     # testapp/wagtail_hooks.py defines a 'blockquote' rich text feature with a hallo.js
     # plugin, via the register_rich_text_features hook; test that we can retrieve it here
     features = FeatureRegistry()
     quotation = features.get_editor_plugin('hallo', 'quotation')
     self.assertEqual(quotation.name, 'halloquotation')
Ejemplo n.º 8
0
 def test_register_rich_text_features_hook(self):
     # testapp/wagtail_hooks.py defines a 'blockquote' rich text feature with a hallo.js
     # plugin, via the register_rich_text_features hook; test that we can retrieve it here
     features = FeatureRegistry()
     quotation = features.get_editor_plugin('hallo', 'quotation')
     self.assertEqual(quotation.name, 'halloquotation')
Ejemplo n.º 9
0
 def test_missing_editor_plugin_returns_none(self):
     features = FeatureRegistry()
     self.assertIsNone(
         features.get_editor_plugin("made_up_editor", "blockquote"))
     self.assertIsNone(
         features.get_editor_plugin("draftail", "made_up_feature"))
Ejemplo n.º 10
0
 def test_register_rich_text_features_hook(self):
     # testapp/wagtail_hooks.py defines a 'blockquote' rich text feature with a Draftail
     # plugin, via the register_rich_text_features hook; test that we can retrieve it here
     features = FeatureRegistry()
     quotation = features.get_editor_plugin("draftail", "quotation")
     self.assertEqual(quotation.js, ["testapp/js/draftail-quotation.js"])
Ejemplo n.º 11
0
from django.utils.safestring import mark_safe

from wagtail.core.rich_text.feature_registry import FeatureRegistry
from wagtail.core.rich_text.rewriters import EmbedRewriter, LinkRewriter, MultiRuleRewriter

features = FeatureRegistry()

# Rewriter function to be built up on first call to expand_db_html, using the utility classes
# from wagtail.core.rich_text.rewriters along with the embed handlers / link handlers registered
# with the feature registry

FRONTEND_REWRITER = None


def expand_db_html(html):
    """
    Expand database-representation HTML into proper HTML usable on front-end templates
    """
    global FRONTEND_REWRITER

    if FRONTEND_REWRITER is None:
        embed_rules = features.get_embed_types()
        link_rules = features.get_link_types()
        FRONTEND_REWRITER = MultiRuleRewriter(
            [LinkRewriter(link_rules),
             EmbedRewriter(embed_rules)])

    return FRONTEND_REWRITER(html)


class RichText: