From 43e406068af8f2ae3d77301926bb5d31f392c961 Mon Sep 17 00:00:00 2001
From: Simon Rettberg
Date: Tue, 15 Oct 2013 19:24:01 +0200
Subject: Initial commit
---
inc/render.inc.php | 124 +++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 124 insertions(+)
create mode 100644 inc/render.inc.php
(limited to 'inc/render.inc.php')
diff --git a/inc/render.inc.php b/inc/render.inc.php
new file mode 100644
index 00000000..cf2b20b7
--- /dev/null
+++ b/inc/render.inc.php
@@ -0,0 +1,124 @@
+
+
+
+ ', RENDER_DEFAULT_TITLE, self::$title, '
+
+
+
+ ',
+ self::$header
+ ,
+ '
+
+ ',
+ self::$body
+ ,
+ '
+
+ '
+ ;
+ }
+
+ /**
+ * Set the page title (title-tag)
+ */
+ public static function setTitle($title)
+ {
+ self::$title = ' - ' . $title;
+ }
+
+ /**
+ * Add raw html data to the header-section of the generated page
+ */
+ public static function addHeader($html)
+ {
+ self::$header .= $html . "\n";
+ }
+
+ /**
+ * Add the given template to the output, using the given params for placeholders in the template
+ */
+ public static function parse($template, $params)
+ {
+ self::$body .= self::$mustache->render(self::getTemplate($template), $params);
+ }
+
+ /**
+ * Open the given html tag, optionally adding the passed assoc array of params
+ */
+ public static function openTag($tag, $params = false)
+ {
+ array_push(self::$tags, $tag);
+ if (!is_array($params)) {
+ self::$body .= '<' . $tag . '>';
+ } else {
+ self::$body .= '<' . $tag;
+ foreach ($params as $key => $val) {
+ self::$body .= ' ' . $key . '="' . htmlspecialchars($val) . '"';
+ }
+ self::$body .= '>';
+ }
+ }
+
+ /**
+ * Close the given tag. Will check if it maches the tag last opened
+ */
+ public static function closeTag($tag)
+ {
+ if (empty(self::$tags)) Util::traceError('Tried to close tag ' . $tag . ' when no open tags exist.');
+ $last = array_pop(self::$tags);
+ if ($last !== $tag) Util::traceError('Tried to close tag ' . $tag . ' when last opened tag was ' . $last);
+ self::$body .= '' . $tag . '>';
+ }
+
+ /**
+ * Private helper: Load the given template and return it
+ */
+ private static function getTemplate($template)
+ {
+ if (isset(self::$templateCache[$template])) {
+ return self::$templateCache[$template];
+ }
+ // Load from disk
+ $data = @file_get_contents('templates/' . $template . '.html');
+ if ($data === false) $data = 'Non-existent template ' . $template . ' requested!';
+ self::$templateCache[$template] =& $data;
+ return $data;
+ }
+}
+
--
cgit v1.2.3-55-g7522