Skip to content
Snippets Groups Projects
Commit bf62c4b7 authored by Calen Pennington's avatar Calen Pennington
Browse files

Extract a pure-XBlock version of MakoModuleDescriptor

parent b50876fc
No related merge requests found
from .x_module import XModuleDescriptor, DescriptorSystem
"""
Code to handle mako templating for XModules and XBlocks.
"""
from xblock.fragment import Fragment
from .x_module import XModuleDescriptor, DescriptorSystem, shim_xmodule_js
class MakoDescriptorSystem(DescriptorSystem):
......@@ -8,20 +13,19 @@ class MakoDescriptorSystem(DescriptorSystem):
self.render_template = render_template
class MakoModuleDescriptor(XModuleDescriptor):
class MakoTemplateBlockBase(object):
"""
Module descriptor intended as a mixin that uses a mako template
XBlock intended as a mixin that uses a mako template
to specify the module html.
Expects the descriptor to have the `mako_template` attribute set
with the name of the template to render, and it will pass
the descriptor as the `module` parameter to that template
MakoModuleDescriptor.__init__ takes the same arguments as xmodule.x_module:XModuleDescriptor.__init__
"""
# pylint: disable=no-member
def __init__(self, *args, **kwargs):
super(MakoModuleDescriptor, self).__init__(*args, **kwargs)
super(MakoTemplateBlockBase, self).__init__(*args, **kwargs)
if getattr(self.runtime, 'render_template', None) is None:
raise TypeError(
'{runtime} must have a render_template function'
......@@ -39,6 +43,21 @@ class MakoModuleDescriptor(XModuleDescriptor):
'editable_metadata_fields': self.editable_metadata_fields
}
def studio_view(self, context): # pylint: disable=unused-argument
"""
View used in Studio.
"""
# pylint: disable=no-member
fragment = Fragment(
self.system.render_template(self.mako_template, self.get_context())
)
shim_xmodule_js(self, fragment)
return fragment
class MakoModuleDescriptor(MakoTemplateBlockBase, XModuleDescriptor): # pylint: disable=abstract-method
"""
Mixin to use for XModule descriptors.
"""
def get_html(self):
return self.system.render_template(
self.mako_template, self.get_context())
return self.studio_view(None).content
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment