Ejemplo n.º 1
0
 def test_should_not_remove_paragraphs_that_contain_whitespace_but_are_not_empty_with_inline_style_or_attribubtes(
         self):
     self.assertEqual(
         '<p style="text-align: center;"><small data-id="foo">X</small></p>',
         cleanup_html(
             '<p style="text-align: center;"><small data-id="foo">X</small></p>'
         ))
Ejemplo n.º 2
0
 def test_should_remove_empty_paragraphs(self):
     self.assertEqual(
         '<h1>Foo</h1><p>Lorem Ipsum</p>',
         cleanup_html(
             '<p> &nbsp; </p><h1>Foo</h1><p> \n </p><p>Lorem Ipsum</p>' + \
             '<p></p><p>&nbsp;\n</p>'
         )
     )
Ejemplo n.º 3
0
 def test_should_remove_empty_paragraphs_with_inline_style_or_attributes(
         self):
     self.assertEqual(
         '<h1>Foo</h1><p data-id="foo">Lorem Ipsum</p>',
         cleanup_html(
             '<p style="text-align: center;"> &nbsp; </p><h1>Foo</h1><p data-id="bar"> \n </p><p data-id="foo">Lorem Ipsum</p>' + \
             '<p></p><p>&nbsp;\n</p>'
         )
     )
Ejemplo n.º 4
0
def cms_content(context, content, headline_transpose=0, image_shape=None):
    """
    Renders cms content.
    """
    if content is None:
        return ''

    # run through content pipeline
    cms = get_cms()
    request = context.get('request')
    content = cms.on_render_content_pipeline(request, content, context)

    # make sure that headline transpose is an integer we can work with
    try:
        headline_transpose = int(headline_transpose)
    except ValueError:
        headline_transpose = 0

    preview = value_or_default('cms_preview', context, False)

    # lazy-loaded images (not in preview mode)
    if not preview and 'cubane.media' in settings.INSTALLED_APPS:
        from cubane.media.templatetags.media_tags import render_image
        images = context.get('images', {})
        images = load_images_for_content(content, images)
        noscript = value_or_default('noscript', context, False)
        content = rewrite_images(content, images, render_image, noscript,
                                 image_shape)

    # page links
    if not preview:
        page_links = context.get('page_links', {})
        page_links = get_page_links_from_content(content, preview)
        content = rewrite_page_links(content, page_links)

    # transpose headlines
    if headline_transpose > 0:
        content = transpose_html_headlines(content, headline_transpose)

    # cleanup markup
    content = cleanup_html(content)

    # frontend editing
    return mark_safe(content)
Ejemplo n.º 5
0
    def render(self, context):
        """
        Render slot content.
        """
        slotname = value_or_literal(self.slotname, context)
        headline_transpose = value_or_literal(self.headline_transpose, context)
        image_shape = value_or_literal(self.image_shape, context)
        page = value_or_none('page', context)
        child_page = value_or_none('child_page', context)
        preview = value_or_default('cms_preview', context, False)
        noscript = value_or_default('noscript', context, False)
        images = context.get('images', {})
        is_enquiry_template = value_or_default('is_enquiry_template', context,
                                               False)

        # make sure that this slot actually exists
        if slotname not in settings.CMS_SLOTNAMES:
            return template_error(
                "Slot '%s' does not exist (referenced via %s)" %
                (slotname, self.slotname))

        # switch page to child_page if present
        if child_page:
            page = child_page

        # extract correct content from page based on the slotname provided
        if page:
            content = page.get_slot_content(slotname)
        else:
            content = ''

        # make sure that headline transpose is an integer we can work with
        try:
            headline_transpose = int(headline_transpose)
        except ValueError:
            headline_transpose = 0

        # run through content pipeline
        cms = get_cms()
        request = context.get('request')
        content = cms.on_render_content_pipeline(request, content, context)

        # rewrite image url to use responsive lazy-load mechanism for images,
        # (we are not doing this in preview mode).
        if not preview and not is_enquiry_template and 'cubane.media' in settings.INSTALLED_APPS:
            from cubane.media.templatetags.media_tags import render_image
            content = rewrite_images(content, images, render_image, noscript,
                                     image_shape)

        # page links
        if not preview:
            page_links = context.get('page_links', {})
            content = rewrite_page_links(content, page_links)

        # transpose headlines
        content = transpose_html_headlines(content, headline_transpose)

        # cleanup markup
        content = cleanup_html(content)

        # mark content as safe
        content = mark_safe(content)

        # wrap content into a seperate slot container if we are configured
        # to do so...
        if settings.CMS_RENDER_SLOT_CONTAINER:
            content = '<div class="cms-slot-container">' + content + '</div>'

        # frontend editing?
        if settings.CUBANE_FRONTEND_EDITING:
            ref = get_edit_reference(request, page, ['slot_%s' % slotname])
            if ref:
                content = '<div edit="%s">%s</div>' % (ref, content)

        # in preview mode, we wrap the content into a container, so that we
        # can identify the content in the backend and provide live-editing
        # preview capabilities...
        if preview:
            return '<div class="cms-slot" data-slotname="%s" data-headline-transpose="%d">%s</div>' % (
                slotname, headline_transpose, content)
        else:
            return content
Ejemplo n.º 6
0
 def test_should_remove_leading_whitespace_for_paragraph_start(self):
     self.assertEqual(
         '<p>foo</p><p>bar</p><p>test</p>',
         cleanup_html('<p>  &nbsp;foo</p><p> bar</p><p>&nbsp;test</p>'))
Ejemplo n.º 7
0
 def test_should_not_remove_paragraphs_that_contain_whitespace_but_are_not_empty(
         self):
     self.assertEqual('<p><small>X</small></p>',
                      cleanup_html('<p><small>X</small></p>'))
Ejemplo n.º 8
0
 def test_should_strip_white_space(self):
     self.assertEqual('foo', cleanup_html('  foo  \n\n  '))
Ejemplo n.º 9
0
 def test_should_return_empty_string_for_none(self):
     self.assertEqual('', cleanup_html(None))