Commit e6f64429 by Robert Raposa

Merge pull request #11437 from edx/robrap/markup

Move markup helpers to djangolib
parents 158c4e58 29fe2c7b
...@@ -12,7 +12,7 @@ from contentstore.views.helpers import xblock_studio_url, xblock_type_display_na ...@@ -12,7 +12,7 @@ from contentstore.views.helpers import xblock_studio_url, xblock_type_display_na
from openedx.core.djangolib.js_utils import ( from openedx.core.djangolib.js_utils import (
dump_js_escaped_json, js_escaped_string dump_js_escaped_json, js_escaped_string
) )
from util.markup import HTML, ugettext as _ from openedx.core.djangolib.markup import HTML, ugettext as _
%> %>
<%block name="title">${xblock.display_name_with_default_escaped} ${xblock_type_display_name(xblock) | h}</%block> <%block name="title">${xblock.display_name_with_default_escaped} ${xblock_type_display_name(xblock) | h}</%block>
<%block name="bodyclass">is-signedin course container view-container</%block> <%block name="bodyclass">is-signedin course container view-container</%block>
......
<%! from util.markup import ugettext as _ %> <%! from openedx.core.djangolib.markup import ugettext as _ %>
<%page expression_filter="h"/> <%page expression_filter="h"/>
% for course_msg in course_enrollment_messages: % for course_msg in course_enrollment_messages:
<div class="wrapper-msg urgency-high"> <div class="wrapper-msg urgency-high">
......
...@@ -16,12 +16,12 @@ def ugettext(text): ...@@ -16,12 +16,12 @@ def ugettext(text):
Use like this in Mako:: Use like this in Mako::
<% from util.markup import ugettext as _ %> <% from openedx.core.djangolib.markup import ugettext as _ %>
<p>${_("Hello, world!")}</p> <p>${_("Hello, world!")}</p>
Or with formatting:: Or with formatting::
<% from util.markup import HTML, ugettext as _ %> <% from openedx.core.djangolib.markup import HTML, ugettext as _ %>
${_("Write & send {start}email{end}").format( ${_("Write & send {start}email{end}").format(
start=HTML("<a href='mailto:ned@edx.org'>"), start=HTML("<a href='mailto:ned@edx.org'>"),
end=HTML("</a>"), end=HTML("</a>"),
...@@ -41,7 +41,7 @@ def HTML(html): # pylint: disable=invalid-name ...@@ -41,7 +41,7 @@ def HTML(html): # pylint: disable=invalid-name
Use this when formatting HTML into other strings:: Use this when formatting HTML into other strings::
<% from util.markup import HTML, ugettext as _ %> <% from openedx.core.djangolib.markup import HTML, ugettext as _ %>
${_("Write & send {start}email{end}").format( ${_("Write & send {start}email{end}").format(
start=HTML("<a href='mailto:ned@edx.org'>"), start=HTML("<a href='mailto:ned@edx.org'>"),
end=HTML("</a>"), end=HTML("</a>"),
......
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
""" """
Tests for util.markup Tests for openedx.core.djangolib.markup
""" """
import unittest import unittest
import ddt import ddt
from mako.template import Template
from edxmako.template import Template from openedx.core.djangolib.markup import escape, HTML, ugettext as _, ungettext
from util.markup import escape, HTML, ugettext as _, ungettext
@ddt.ddt @ddt.ddt
...@@ -54,12 +54,12 @@ class FormatHtmlTest(unittest.TestCase): ...@@ -54,12 +54,12 @@ class FormatHtmlTest(unittest.TestCase):
# The default_filters used here have to match the ones in edxmako. # The default_filters used here have to match the ones in edxmako.
template = Template( template = Template(
""" """
<%! from util.markup import HTML, ugettext as _ %> <%! from openedx.core.djangolib.markup import HTML, ugettext as _ %>
${_(u"A & {BC}").format(BC=HTML("B & C"))} ${_(u"A & {BC}").format(BC=HTML("B & C"))}
""", """,
default_filters=['decode.utf8', 'h'], default_filters=['decode.utf8', 'h'],
) )
out = template.render({}) out = template.render()
self.assertEqual(out.strip(), u"A &amp; B & C") self.assertEqual(out.strip(), u"A &amp; B & C")
def test_ungettext(self): def test_ungettext(self):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment