ILIAS  trunk Revision v11.0_alpha-2645-g16283d3b3f8
Renderer.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 
28 
34 {
38  public function render(Component\Component $component, RendererInterface $default_renderer): string
39  {
40 
41  if ($component instanceof I\Legacy\Content) {
42  return $this->renderContent($component, $default_renderer);
43  }
44  if ($component instanceof I\Legacy\Segment) {
45  return $this->renderSegment($component, $default_renderer);
46  }
47 
48  $this->cannotHandleComponent($component);
49 
50  }
51 
52  protected function renderContent(Content $component, RendererInterface $default_renderer): string
53  {
54  $component = $this->registerSignals($component);
55  $this->bindJavaScript($component);
56 
57  // Wrap LatexContent in a div with a css class that enables the rendering inside
58  if ($component instanceof Component\Legacy\LatexContent) {
59  $tpl = $this->getTemplate("tpl.latex_content.html", true, true);
60  $tpl->setVariable('CONTENT', $component->getContent());
61  return $tpl->get();
62  }
63 
64  return $component->getContent();
65  }
66 
67  protected function registerSignals(Content $component): Component\JavaScriptBindable
68  {
69  $custom_signals = $component->getAllCustomSignals();
70 
71  return $component->withAdditionalOnLoadCode(function ($id) use ($custom_signals): string {
72  $code = "";
73  foreach ($custom_signals as $custom_signal) {
74  $signal_id = $custom_signal['signal'];
75  $signal_code = $custom_signal['js_code'];
76  $code .= "$(document).on('$signal_id', function(event, signalData) { $signal_code });";
77  }
78  return $code;
79  });
80  }
81 
82 
86  public function registerResources(ResourceRegistry $registry): void
87  {
88  parent::registerResources($registry);
89  $registry->register('assets/js/mathjax_config.js');
90  $registry->register('node_modules/mathjax/es5/tex-chtml-full.js');
91  }
92 
93  protected function renderSegment(Segment $component, RendererInterface $default_renderer): string
94  {
95  return $component->getSegmentContent();
96  }
97 }
Registry for resources required by rendered output like Javascript or CSS.
render(Component\Component $component, RendererInterface $default_renderer)
Definition: Renderer.php:38
renderSegment(Segment $component, RendererInterface $default_renderer)
Definition: Renderer.php:93
getAllCustomSignals()
Get a list of all registered signals and their custom JavaScript code.
Definition: Content.php:94
renderContent(Content $component, RendererInterface $default_renderer)
Definition: Renderer.php:52
getTemplate(string $name, bool $purge_unfilled_vars, bool $purge_unused_blocks)
Get template of component this renderer is made for.
registerResources(ResourceRegistry $registry)
Register additional resources which are needed for the LatexContent component.
Definition: Renderer.php:86
cannotHandleComponent(Component $component)
This method MUST be called by derived component renderers, if.
register(string $name)
Add a dependency.
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
bindJavaScript(JavaScriptBindable $component)
Bind the component to JavaScript.