def export(self, context, exercise): g = context.generator() exercise_id = context.unique_id() context.resource('lcg-exercises.css') has_real_answers = self._has_real_answers(exercise) allow_interactivity = context.allow_interactivity() if not has_real_answers: methods = (self._export_tasks,) elif not allow_interactivity: methods = (self._export_tasks, self._export_answers) else: context.resource('prototype.js') context.resource('lcg.js') context.resource('lcg-exercises.js') context.resource('effects.js') context.resource('media.js') methods = (self._export_instructions, self._export_tasks, self._export_results) parts = [method(context, exercise, exercise_id) for method in methods] content = [x for x in parts if x is not None] if allow_interactivity and has_real_answers: script = self._export_script(context, exercise, exercise_id) if script: content = (g.form(content, id=exercise_id), g.script(script)) return g.div(content, cls='exercise ' + lcg.camel_case_to_lower(exercise.__class__.__name__))
def export(self, context, exercise): g = context.generator() exercise_id = context.unique_id() context.resource('lcg-exercises.css') has_real_answers = self._has_real_answers(exercise) allow_interactivity = context.allow_interactivity() if not has_real_answers: methods = (self._export_tasks,) elif not allow_interactivity: methods = (self._export_tasks, self._export_answers) else: context.resource('prototype.js') context.resource('lcg.js') context.resource('lcg-exercises.js') context.resource('effects.js') context.resource('media.js') context.connect_shared_player() methods = (self._export_instructions, self._export_tasks, self._export_results) parts = [method(context, exercise, exercise_id) for method in methods] content = [x for x in parts if x is not None] if allow_interactivity and has_real_answers: script = self._export_script(context, exercise, exercise_id) if script: content = (g.form(content, id=exercise_id), g.script(script)) return g.div(content, cls='exercise ' + lcg.camel_case_to_lower(exercise.__class__.__name__))
def _css_class_name(self, context): """Return the name of the CSS class assigned to the widget root DOM element. The name is by default created by converting the camel-case Python class name to hyphen separated words and adding '-widget' to the end (for example 'foldable-tree-widget' for the 'FoldableTree' Python class). Derived classes may override this method to use a specific CSS class name. """ return lcg.camel_case_to_lower(self.__class__.__name__) + '-widget'
def export(self, context): context.resource('prototype.js') context.resource('gettext.js') context.resource('lcg.js') context.resource('lcg-widgets.css') g = context.generator() name = self.__class__.__name__ element_id = context.unique_id() return g.concat(self._wrap_exported_widget(context, self._export_widget(context), id=element_id, aria_label=self._label, cls=lcg.camel_case_to_lower(name) + '-widget'), g.script(g.js_call('new lcg.%s' % name, element_id, *self._javascript_widget_arguments(context))))
def _task_style_cls(self, exercise): return 'task %s-task' % lcg.camel_case_to_lower(exercise.__class__.__name__)