Skip to content

Commit eba07d4

Browse files
committed
#92 - Create debug output for slideshow engine
1 parent d83f95d commit eba07d4

File tree

2 files changed

+59
-10
lines changed

2 files changed

+59
-10
lines changed

src/Engine/Convert/NativeSlideshow.php

Lines changed: 35 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use FileConverter\Engine\EngineBase;
1313
use FileConverter\Engine\Helper\Archive;
1414
use GuzzleHttp\json_decode;
15+
use QuipXml\OneLiner\OneLiner;
1516

1617
class NativeSlideshow extends EngineBase {
1718
/**
@@ -48,12 +49,7 @@ public function convertFile($source, $destination) {
4849

4950
// Apply the slideshow mode.
5051
foreach ($slideshow['items'] as $i => &$slide) {
51-
if (!isset($slide['notes'])) {
52-
if ($slideshow['mode'] === 'schedule') {
53-
unset($slideshow['items'][$i]);
54-
}
55-
}
56-
else {
52+
if (isset($slide['notes'])) {
5753
// Extract settings from the slide notes.
5854
$keys = array(
5955
'@(?<k>SLIDESHOW\.[^:]+):(?<v>[^\n]+)(?:\n|$)@s',
@@ -73,6 +69,10 @@ public function convertFile($source, $destination) {
7369
}
7470
unset($slide['notes']);
7571
}
72+
if ($slideshow['mode'] === 'schedule'
73+
&& (!isset($slide['begin']) || empty($slide['begin']))) {
74+
unset($slideshow['items'][$i]);
75+
}
7676
}
7777
unset($slide);
7878
$slideshow['items'] = array_values($slideshow['items']);
@@ -110,15 +110,40 @@ public function convertFile($source, $destination) {
110110
$this->isTempWritable($to);
111111
copy(__DIR__ . '/Resources/Slideshow/slideshow.css', $to);
112112

113+
// Build the strtr replacements.
114+
$tr = array(
115+
'{{ slideshow.title|escape }}' => htmlspecialchars($slideshow['title']),
116+
'{{ slideshow|json_encode() }}' => json_encode($slideshow),
117+
'{{ debug }}' => '',
118+
);
119+
120+
// Build a debug page.
121+
$debug = '';
122+
foreach ($slideshow['items'] as $slide) {
123+
$row = '';
124+
$img = OneLiner::wrap('img', '', TRUE, array(
125+
'src' => "img/slide{$slide[number]}.jpg",
126+
'style' => 'width:95%;border:1px solid #000',
127+
));
128+
$row .= OneLiner::wrap('<div class="col-sm-3">', $img);
129+
$details = '';
130+
$details .= OneLiner::wrap('strong', 'BEGIN:' . $slide['begin']);
131+
$details .= '<br />' . json_encode($slide);
132+
$row .= OneLiner::wrap('<div class="col-sm-9">', $details);
133+
$debug .= OneLiner::wrap('<div class="row">', $row);
134+
}
135+
$tr['{{ debug }}'] = $debug;
136+
$to = "$tmp/debug.htm";
137+
$content = file_get_contents(__DIR__ . '/Resources/Slideshow/debug.htm');
138+
$content = strtr($content, $tr);
139+
file_put_contents($to, $content);
140+
113141
// The index file involves template variables.
114142
// Provide a raw
115143
$to = "$tmp/index.htm";
116144
$this->isTempWritable($to);
117145
$content = file_get_contents(__DIR__ . '/Resources/Slideshow/index.htm');
118-
$content = strtr($content, array(
119-
'{{ slideshow.title|escape }}' => htmlspecialchars($slideshow['title']),
120-
'{{ slideshow|json_encode() }}' => json_encode($slideshow),
121-
));
146+
$content = strtr($content, $tr);
122147
file_put_contents($to, $content);
123148

124149
// Save the slideshow.
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="utf-8">
5+
<meta http-equiv="X-UA-Compatible" content="IE=edge">
6+
<meta name="viewport" content="width=device-width, initial-scale=1">
7+
<!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
8+
<title>{{ slideshow.title|escape }}</title>
9+
10+
<!-- Bootstrap CDN: http://getbootstrap.com/getting-started/ -->
11+
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
12+
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css" integrity="sha384-rHyoN1iRsVXV4nD0JutlnGaslCJuC7uwjduW9SVrLvRYooPp2bWYgmgJQIXwl/Sp" crossorigin="anonymous">
13+
14+
<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
15+
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
16+
<!--[if lt IE 9]>
17+
<script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
18+
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
19+
<![endif]-->
20+
</head>
21+
<body>
22+
{{ debug }}
23+
</body>
24+
</html>

0 commit comments

Comments
 (0)