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

Make custom tags work in the LMS

parent c140fe87
No related merge requests found
...@@ -13,15 +13,21 @@ setup( ...@@ -13,15 +13,21 @@ setup(
# for a description of entry_points # for a description of entry_points
entry_points={ entry_points={
'xmodule.v1': [ 'xmodule.v1': [
"book = xmodule.translation_module:TranslateCustomTagDescriptor",
"chapter = xmodule.seq_module:SequenceDescriptor", "chapter = xmodule.seq_module:SequenceDescriptor",
"course = xmodule.seq_module:SequenceDescriptor", "course = xmodule.seq_module:SequenceDescriptor",
"customtag = xmodule.template_module:CustomTagDescriptor",
"discuss = xmodule.translation_module:TranslateCustomTagDescriptor",
"html = xmodule.html_module:HtmlDescriptor", "html = xmodule.html_module:HtmlDescriptor",
"image = xmodule.translation_module:TranslateCustomTagDescriptor",
"problem = xmodule.capa_module:CapaDescriptor",
"problemset = xmodule.seq_module:SequenceDescriptor",
"section = xmodule.translation_module:SemanticSectionDescriptor", "section = xmodule.translation_module:SemanticSectionDescriptor",
"sequential = xmodule.seq_module:SequenceDescriptor", "sequential = xmodule.seq_module:SequenceDescriptor",
"slides = xmodule.translation_module:TranslateCustomTagDescriptor",
"vertical = xmodule.vertical_module:VerticalDescriptor", "vertical = xmodule.vertical_module:VerticalDescriptor",
"problem = xmodule.capa_module:CapaDescriptor",
"problemset = xmodule.seq_module:SequenceDescriptor",
"video = xmodule.video_module:VideoDescriptor", "video = xmodule.video_module:VideoDescriptor",
"videodev = xmodule.translation_module:TranslateCustomTagDescriptor",
"videosequence = xmodule.seq_module:SequenceDescriptor", "videosequence = xmodule.seq_module:SequenceDescriptor",
] ]
} }
......
import json from xmodule.x_module import XModule
from xmodule.raw_module import RawDescriptor
from x_module import XModule, XModuleDescriptor
from lxml import etree from lxml import etree
class ModuleDescriptor(XModuleDescriptor): class CustomTagModule(XModule):
pass
class Module(XModule):
""" """
This module supports tags of the form This module supports tags of the form
<customtag option="val" option2="val2"> <customtag option="val" option2="val2">
...@@ -34,9 +29,13 @@ class Module(XModule): ...@@ -34,9 +29,13 @@ class Module(XModule):
def get_html(self): def get_html(self):
return self.html return self.html
def __init__(self, system, xml, item_id, instance_state=None, shared_state=None): def __init__(self, system, location, definition, instance_state=None, shared_state=None, **kwargs):
XModule.__init__(self, system, xml, item_id, instance_state, shared_state) XModule.__init__(self, system, location, definition, instance_state, shared_state, **kwargs)
xmltree = etree.fromstring(xml) xmltree = etree.fromstring(self.definition['data'])
filename = xmltree.find('impl').text filename = xmltree.find('impl').text
params = dict(xmltree.items()) params = dict(xmltree.items())
self.html = self.system.render_template(filename, params, namespace='custom_tags') self.html = self.system.render_template(filename, params, namespace='custom_tags')
class CustomTagDescriptor(RawDescriptor):
module_class = CustomTagModule
...@@ -65,3 +65,20 @@ class SemanticSectionDescriptor(XModuleDescriptor): ...@@ -65,3 +65,20 @@ class SemanticSectionDescriptor(XModuleDescriptor):
else: else:
xml_object.tag = 'sequence' xml_object.tag = 'sequence'
return system.process_xml(etree.tostring(xml_object)) return system.process_xml(etree.tostring(xml_object))
class TranslateCustomTagDescriptor(XModuleDescriptor):
@classmethod
def from_xml(cls, xml_data, system, org=None, course=None):
"""
Transforms the xml_data from <$custom_tag attr="" attr=""/> to
<customtag attr="" attr=""><impl>$custom_tag</impl></customtag>
"""
xml_object = etree.fromstring(xml_data)
tag = xml_object.tag
xml_object.tag = 'customtag'
impl = etree.SubElement(xml_object, 'impl')
impl.text = tag
return system.process_xml(etree.tostring(xml_object))
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