Add webpack assets directly to xmodule fragments, rather than injecting them in fragment contents
This commit is contained in:
@@ -1,9 +1,3 @@
|
||||
<%namespace name='static' file='static_content.html'/>
|
||||
|
||||
% if is_xmodule:
|
||||
<%static:webpack entry="${class_name}"/>
|
||||
% endif
|
||||
<!-- This is the xblock wrapper ${is_xmodule} -->
|
||||
<div class="${' '.join(classes) | n}" ${data_attributes}>
|
||||
% if js_init_parameters:
|
||||
<script type="json/xblock-args" class="xblock-json-init-args">
|
||||
|
||||
@@ -29,6 +29,8 @@ from xmodule.seq_module import SequenceModule
|
||||
from xmodule.vertical_block import VerticalBlock
|
||||
from xmodule.x_module import shim_xmodule_js, XModuleDescriptor, XModule, PREVIEW_VIEWS, STUDIO_VIEW
|
||||
|
||||
import webpack_loader.utils
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
@@ -134,8 +136,6 @@ def wrap_xblock(
|
||||
'display_name': block.display_name_with_default_escaped,
|
||||
'data_attributes': u' '.join(u'data-{}="{}"'.format(markupsafe.escape(key), markupsafe.escape(value))
|
||||
for key, value in data.iteritems()),
|
||||
'class_name': class_name,
|
||||
'is_xmodule': isinstance(block, (XModule, XModuleDescriptor)),
|
||||
}
|
||||
|
||||
if hasattr(frag, 'json_init_args') and frag.json_init_args is not None:
|
||||
@@ -144,6 +144,11 @@ def wrap_xblock(
|
||||
else:
|
||||
template_context['js_init_parameters'] = ""
|
||||
|
||||
if isinstance(block, (XModule, XModuleDescriptor)):
|
||||
# Add the webpackified asset tags
|
||||
for tag in webpack_loader.utils.get_as_tags(class_name):
|
||||
frag.add_resource(tag, mimetype='text/html', placement='head')
|
||||
|
||||
return wrap_fragment(frag, render_to_string('xblock_wrapper.html', template_context))
|
||||
|
||||
|
||||
@@ -202,7 +207,6 @@ def wrap_xblock_aside(
|
||||
'classes': css_classes,
|
||||
'data_attributes': u' '.join(u'data-{}="{}"'.format(markupsafe.escape(key), markupsafe.escape(value))
|
||||
for key, value in data.iteritems()),
|
||||
'is_xmodule': False,
|
||||
}
|
||||
|
||||
if hasattr(frag, 'json_init_args') and frag.json_init_args is not None:
|
||||
|
||||
Reference in New Issue
Block a user