1 <?php
2
3 4 5 6 7 8 9 10
11
12 namespace Icybee;
13
14 use ICanBoogie\Debug;
15 use ICanBoogie\Operation;
16 use ICanBoogie\Route;
17
18 use Brickrouge\A;
19 use Brickrouge\Alert;
20 use Brickrouge\DropdownMenu;
21 use Brickrouge\Element;
22
23 class DocumentDecorator
24 {
25 protected $component;
26
27 public function __construct($component)
28 {
29 $this->component = $component;
30 $this->body = new Element('body');
31 }
32
33 public function __toString()
34 {
35 try
36 {
37 return $this->render();
38 }
39 catch (\Exception $e)
40 {
41 return Debug::format_alert($e);
42 }
43 }
44
45 public function render()
46 {
47 global $core;
48
49 $component = (string) $this->component;
50 $document = $core->document;
51 $title = \Brickrouge\escape('Icybee');
52 $favicon = Document::resolve_url(\Icybee\ASSETS . 'favicon.png');
53
54 $body = $this->body;
55 $body[Element::INNER_HTML] = $component . PHP_EOL . PHP_EOL . $document->js;
56
57 $api_base = '';
58
59 if (isset($core->site))
60 {
61 $api_base = $core->site->path;
62 }
63
64 return <<<EOT
65 <!DOCTYPE html>
66 <html lang="{$core->language}" data-api-base="{$api_base}">
67 <head>
68 <meta charset="utf-8" />
69 <title>$title</title>
70 <link rel="shortcut icon" type="image/png" href="{$favicon}" />
71 {$document->css}
72 </head>
73 {$body}
74 </html>
75 EOT;
76 }
77 }