1 <?php
2
3 4 5 6 7 8 9 10
11
12 namespace Icybee\Modules\Editor;
13
14 use Brickrouge\A;
15
16 17 18
19 class TabbableEditorRenderer
20 {
21 protected $editor;
22
23 public function __construct(TabbableEditor $editor)
24 {
25 $this->editor = $editor;
26 }
27
28 public function __invoke($content)
29 {
30 $panes = $content;
31
32 $nav = $this->render_nav($panes);
33 $content = $this->render_content($panes);
34
35 return <<<EOT
36 <div class="tabbable">
37
38 $nav
39 $content
40
41 </div>
42 EOT;
43 }
44
45 protected function render_nav(array $panes)
46 {
47 $html = '';
48
49 foreach ($panes as $i => $pane)
50 {
51 $html .= '<li';
52
53 if (!$i)
54 {
55 $html .= ' class="active"';
56 }
57
58 $html .= '>';
59
60 $html .= $this->render_tabbable_tab($pane, $panes);
61
62 $html .= '</li>';
63 }
64
65 return '<ul class="nav nav-tabs">' . $html . '</ul>';
66 }
67
68 protected function render_tabbable_tab(array $pane, array $panes)
69 {
70 return new A($pane['title'], '#', array('data-toggle' => 'tab'));
71 }
72
73 protected function render_content(array $panes)
74 {
75 $html = '';
76
77 foreach ($panes as $i => $pane)
78 {
79 $editor_id = $pane['editor_id'];
80
81 $html .= '<div class="tab-pane editor-' . \ICanBoogie\normalize($editor_id);
82
83 if (!$i)
84 {
85 $html .= ' active';
86 }
87
88 $html .= '">';
89
90 $html .= $this->render_pane($pane);
91
92 $html .= '</div>';
93 }
94
95 return '<div class="tab-content combo">' . $html . '</div>';
96 }
97
98 protected function render_pane(array $pane)
99 {
100 global $core;
101
102 $editor_id = $pane['editor_id'];
103 $serialized_content = $pane['serialized_content'];
104 $editor = $core->editors[$editor_id];
105
106 return $editor->render($editor->unserialize($serialized_content));
107 }
108 }