def render_inlines(value): """ Renders inlines in a ``Post`` by passing them through inline templates. Template Syntax:: {{ post.body|render_inlines|markdown:"safe" }} Inline Syntax (singular):: <inline type="<app_name>.<model_name>" id="<id>" class="med_left" /> Inline Syntax (plural):: <inline type="<app_name>.<model_name>" ids="<id>, <id>, <id>" /> An inline template will be used to render the inline. Templates will be located in the following manner: ``inlines/<app_name>_<model_name>.html`` The template will be passed the following context: ``object`` An object for the corresponding passed id. or ``object_list`` A list of objects for the corresponding ids. It would be wise to anticipate both object_list and object unless you know for sure one or the other will only be present. """ return inlines(value)
def test_rendering_tags(self): fp_type_id = """<div data-inline-type="tests.image" data-inline-id="2">Content</div>""" fp_type_ids = """<p data-inline-type="tests.video" data-inline-ids="1,2,3">Content</p>""" fp_type_filter = """<div data-inline-type="tests.image" data-inline-filter="title__contains='Image'">Content</div>""" # These three should be simply ignored since they don't have all the right attributes fp_type = """<div data-inline-type="tests.video">Content</div>""" fp_id = """<li data-inline-id="2">Content</li>""" fp_ignore = """<span class="test">Content</span>""" fp_list = [fp_type_ids, fp_type_id, fp_type_filter, fp_type, fp_id, ] rendered_list = [] for fp in fp_list: rendered_list.append(parser.inlines(fp)) expected_result_list = [ """<video src="/tests/media/" alt="Video-1">Test</video><video src="/tests/media/" alt="Video-2">Test</video><video src="/tests/media/" alt="Video-3">Test</video>\n""", """<img src="/tests/media/" alt="Image-2" />\n""", """<img src="/tests/media/" alt="Image-1" /><img src="/tests/media/" alt="Image-2" /><img src="/tests/media/" alt="Image-3" />\n""", # These three remain the same as the originals """<div data-inline-type="tests.video">Content</div>""", """<li data-inline-id="2">Content</li>""", """<span class="test">Content</span>""", ] for expected, result in zip(expected_result_list, rendered_list): self.assertEqual(expected, result)
def extract_inlines(value): return inlines(value, True)