com web/pres2: Graph support: pres2reveal reveal_template.p hp

[email protected] (Rasmus Lerdorf)
Newsgroups php.pres
Message-ID <[email protected]>
Commit:    e023e25592f1f705da11dcdad4438d88c4e87e35
Author:    Rasmus Lerdorf <[email protected]>         Fri, 6 Feb 2015 06:45:33 -0500
Parents:   a1315c0bd8d51d55bf832e1823afda55f5d77825
Branches:  master

Link:       http://git.php.net/?p=web/pres2.git;a=commitdiff;h=e023e25592f1f705da11dcdad4438d88c4e87e35

Log:
Graph support

Changed paths:
  M  pres2reveal
  M  reveal_template.php


Diff:
diff --git a/pres2reveal b/pres2reveal
index 5174993..b562a66 100755
--- a/pres2reveal
+++ b/pres2reveal
@@ -55,6 +55,8 @@ foreach($slide as $sld) {
 			case 'link':
 			case 'image':
 			case 'blurb':
+			case 'notes':
+			case 'literal':
 			case 'example':
 				$fnc ="render_$k";
 				if(is_array(e)) {
@@ -105,14 +107,22 @@ EOB;
 
 function render_blurb($e) {
 	$size = (int)$e['fontsize'];
-	$class = '';
+	$class = $style = '';
 	if($size >= 20) $tag = 'h1';
 	else if($size >= 8) $tag = 'h2';
 	else if($size >= 6) { $tag = 'h3'; $class = " class=\"p\""; }
 	else if($size >= 4) { $tag = 'h4'; $class = " class=\"p\""; }
-	else { $tag = 'p'; $class = " class=\"p\""; }
+	else {
+		$tag = 'p';
+		$class = " class=\"p\"";
+		if(!empty($e['fontsize'])) $style .= "font-size:".$e['fontsize'].';';
+	}
+
+	if(!empty($e['align'])) $style .= 'text-align:'.$e['align'].';';
+	if(!empty($style)) $style = " style=\"$style\"";
+
 	$text = markup_text((string)$e);
-	return "\t\t<$tag{$class}>$text</$tag>\n";
+	return "\t\t<$tag{$class}{$style}>$text</$tag>\n";
 }
 
 function render_link($link) {
@@ -125,43 +135,80 @@ function render_link($link) {
 }
 
 function render_list($e) {
-	$ret = "\t\t<ul>\n";
+	$ret = '';
+	if(!empty($e['title'])) {
+		$style = $align = '';
+		if(!empty($e['fontsize'])) $style .= "font-size: ".$e['fontsize'].';';
+		if(!empty($e['align'])) $align .= 'align="'.$e['align'].'"';
+		if(!empty($style)) $style = " style=\"$style\"";
+		if(!empty($align)) $align = " align=\"$align\"";
+		$ret .= "\t\t<div $align style=\"$style\">".markup_text($e['title'])."</div>\n";
+	}
+	$ret .= "\t\t<ul>\n";
 	foreach($e->item as $v) {
 		$text = markup_text((string)$v);
 		$ret .= "\t\t\t<li>$text</li>\n";	
 	}
 	foreach($e->bullet as $v) {
+		$style = '';
 		$text = markup_text((string)$v);
-		$ret .= "\t\t\t<li>$text</li>\n";	
+		if(!empty($v['fontsize'])) $style .= "font-size: ".$v['fontsize'].';';
+		if(!empty($v['lineheight'])) $style .= "line-height: ".$v['lineheight'].';';
+		if(!empty($style)) $style = " style=\"$style\"";
+		$ret .= "\t\t\t<li$style>$text</li>\n";
 	}
 	$ret .= "\t\t</ul>\n";
 	return $ret;
 }
 
 function render_example($e) {
-	$ret = '';
-	$code = (string)$e;
+	$ret = $style = '';
+	if(!empty($e['title'])) $ret .= '<p class="example">'.markup_text($e['title'])."</p>\n";
+	if(!empty($e['fontsize'])) $style = ' style="font-size:'.$e['fontsize'].';"';
+	$code = trim((string)$e);
+	$orig_code = $code;
 	if(substr($code,0,5)=="<?php") {
 		$code = trim(substr($code,5));
 	}
 	$code = htmlspecialchars($code);
 	$class = ''; 
 	if(!empty($e['type'])) $class = ' class="'.$e['type'].'"';
-	if(empty($e['hide'])) $ret .= "\t\t<pre><code$class>$code</code></pre>\n";
+	if(empty($e['hide'])) $ret .= "\t\t<pre><code$class data-trim$style>$code</code></pre>\n";
 	if(!empty($e['result'])) {
-		$ret .= "\t\t<pre><code>";
+		$ret .= "\t\t<pre class=\"output\"$style>";
 		ob_start();
-		eval("?>$code");
+		eval("?>$orig_code");
 		$ret .= ob_get_clean();
-		$ret .= "\t\t</code></pre>";
+		$ret .= "\t\t</pre>";
 	}
 	return $ret;
 }
 
+function render_notes($e) {
+	$notes = markup_text(nl2br((string)$e));
+	$ret = "<aside class=\"notes\">$notes</aside>\n";
+	return $ret;
+}
+
+function render_literal($e) {
+	return (string)$e;
+}
+
 function format_tt($arg) {
   return("<tt>".str_replace(' ', '&nbsp;', $arg[1])."</tt>");
 }
 
+/* {{{ string markup_text($str)
+	*word*		Bold
+	_word_		underline
+	%word%		monospaced word (ie. %function()%)
+	~word~		italics
+	|rrggbb|word| Colour a word
+	^N^		   Superscript
+	@N@		   Subscript
+	**word**	  Blink
+	#id#		  Entity
+*/
 function markup_text($str) {
     global $pres;
 
diff --git a/reveal_template.php b/reveal_template.php
index 123ffad..a5c052b 100644
--- a/reveal_template.php
+++ b/reveal_template.php
@@ -30,6 +30,7 @@
                 display: block;
                 overflow-x: auto;
                 padding: 0.5em;
+                line-height: 125%;
                 background: #fff;
                 color: black;
                 -webkit-text-size-adjust: none;
@@ -46,6 +47,22 @@
             display: block;
             margin: 0 0 1em 3em;
         }
+		/* Example titles */
+		p.example {
+			text-align: left;
+			margin: 0 0 -0.5em 1em;
+			font-weight: bold;
+		}
+		/* Example output style */
+		pre.output {
+            display: block;
+            overflow-x: auto;
+            padding: 0.5em;
+            background: #ddd;
+            color: black;
+			line-height: 200%;
+            -webkit-text-size-adjust: none;
+		}
         </style>
 
 		 <!-- Printing and PDF exports -->
@@ -57,6 +74,12 @@
 			document.getElementsByTagName( 'head' )[0].appendChild( link );
 		</script>
 
+        <!-- Needed for charts to work. Fall back to network if no local copy -->
+        <script type='text/javascript' src='/jquery.min.js'></script> 
+        <script>window.jQuery || document.write('<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js">\x3C/script>')</script>
+        <script src="/highcharts.js"></script>
+        <script>window.Highcharts || document.write('<script src="http://code.highcharts.com/highcharts.js">\x3C/script>')</script>
+
 		<!--[if lt IE 9]>
 		<script src="/reveal.js/lib/js/html5shiv.js"></script>
 		<![endif]-->
@@ -77,6 +100,9 @@
 					<p><?=$speaker?><br>
 					<small><a href="http://twitter.com/<?=$twitter?>"><?=$twitter?></a></small>
 					</p>
+					<aside class="notes">
+						<?=nl2br(trim($notes))?>
+					</aside>
 				</section>
 				<?=$slides?>
 			</div>
@@ -100,14 +126,25 @@
 				// Optional reveal.js plugins
 				dependencies: [
 					{ src: '/reveal.js/lib/js/classList.js', condition: function() { return !document.body.classList; } },
-					{ src: '/reveal.js/plugin/markdown/marked.js', condition: function() { return !!document.querySelector( '[data-markdown]' ); } },
-					{ src: '/reveal.js/plugin/markdown/markdown.js', condition: function() { return !!document.querySelector( '[data-markdown]' ); } },
 					{ src: '/highlight.min.js', async: true, condition: function() { return !!document.querySelector( 'pre code' ); }, callback: function() { hljs.initHighlightingOnLoad(); } },
 					{ src: '/reveal.js/plugin/zoom-js/zoom.js', async: true },
 					{ src: '/reveal.js/plugin/notes/notes.js', async: true }
 				]
 			});
-
+			/* This draws the graph on the slide on a slidechanged event */
+			Reveal.addEventListener('slidechanged', function(event) {
+				var callback = "render_"+event.currentSlide.id;
+				if(typeof(window[callback])=="function") {
+					window[callback]();
+				}
+			} );
+			/* This draws the graph if we got here directly without coming from another slide */
+			Reveal.addEventListener('ready', function(event) {
+				var callback = "render_"+event.currentSlide.id;
+				if(typeof(window[callback])=="function") {
+					window[callback]();
+				}
+			} );
 		</script>
 
 	</body>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.