Skip to content

Commit 16990e3

Browse files
committed
Update slide template using ejs instead of mustache to reduce similar package dependency
1 parent c73c32d commit 16990e3

5 files changed

Lines changed: 101 additions & 89 deletions

File tree

lib/config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ var indexpath = config.indexpath || './public/views/index.ejs';
3838
var hackmdpath = config.hackmdpath || './public/views/hackmd.ejs';
3939
var errorpath = config.errorpath || './public/views/error.ejs';
4040
var prettypath = config.prettypath || './public/views/pretty.ejs';
41-
var slidepath = config.slidepath || './public/views/slide.hbs';
41+
var slidepath = config.slidepath || './public/views/slide.ejs';
4242

4343
// session
4444
var sessionname = config.sessionname || 'connect.sid';

lib/response.js

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ var models = require("./models");
1818

1919
//slides
2020
var md = require('reveal.js/plugin/markdown/markdown');
21-
var Mustache = require('mustache');
2221

2322
//reveal.js
2423
var opts = {
@@ -244,7 +243,6 @@ function showPublishNote(req, res, next) {
244243
function renderPublish(data, res) {
245244
var template = config.prettypath;
246245
var options = {
247-
url: config.serverurl,
248246
cache: !config.debug,
249247
filename: template
250248
};
@@ -512,14 +510,27 @@ function showPublishSlide(req, res, next) {
512510
var render = function (res, title, markdown) {
513511
var slides = md.slidify(markdown, opts);
514512

515-
res.end(Mustache.to_html(opts.template, {
513+
var template = config.slidepath;
514+
var options = {
515+
cache: !config.debug,
516+
filename: template
517+
};
518+
var compiled = ejs.compile(fs.readFileSync(template, 'utf8'), options);
519+
var html = compiled({
516520
url: config.serverurl,
517521
title: title,
518522
theme: opts.theme,
519523
highlightTheme: opts.highlightTheme,
520524
slides: slides,
521525
options: JSON.stringify(opts.revealOptions, null, 2)
522-
}));
526+
});
527+
var buf = html;
528+
res.writeHead(200, {
529+
'Content-Type': 'text/html; charset=UTF-8',
530+
'Cache-Control': 'private',
531+
'Content-Length': buf.length
532+
});
533+
res.end(buf);
523534
};
524535

525536
module.exports = response;

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
"method-override": "^2.3.5",
3131
"moment": "^2.12.0",
3232
"morgan": "^1.7.0",
33-
"mustache": "2.2.1",
3433
"mysql": "^2.10.2",
3534
"node-uuid": "^1.4.7",
3635
"passport": "^0.3.2",

public/views/slide.ejs

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
<!doctype html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="utf-8">
5+
<meta name="apple-mobile-web-app-capable" content="yes">
6+
<meta name="apple-mobile-web-app-status-bar-style" content="black">
7+
<meta name="mobile-web-app-capable" content="yes">
8+
<title><%- title %></title>
9+
<link rel="icon" type="image/png" href="<%- url %>/favicon.png">
10+
<link rel="apple-touch-icon" href="<%- url %>/apple-touch-icon.png">
11+
12+
<link rel="stylesheet" href="<%- url %>/vendor/reveal.js/css/reveal.css">
13+
<link rel="stylesheet" href="<%- url %>/vendor/reveal.js/<%- theme %>" id="theme">
14+
<!-- For syntax highlighting -->
15+
<link rel="stylesheet" href="<%- url %>/vendor/reveal.js/lib/css/<%- highlightTheme %>.css">
16+
<link rel="stylesheet" href="<%- url %>/css/site.css">
17+
<link rel="stylesheet" href="<%- url %>/css/slide.css">
18+
19+
<!-- If the query includes 'print-pdf', use the PDF print sheet -->
20+
<script>
21+
document.write( '<link rel="stylesheet" href="<%- url %>/vendor/reveal.js/css/print/' + ( window.location.search.match( /print-pdf/gi ) ? 'pdf' : 'paper' ) + '.css" type="text/css" media="print">' );
22+
</script>
23+
<script src="<%- url %>/vendor/jquery/dist/jquery.min.js"></script>
24+
<script src="<%- url %>/vendor/velocity/velocity.min.js"></script>
25+
</head>
26+
<body>
27+
28+
<div class="reveal">
29+
<div class="slides"><%- slides %></div>
30+
</div>
31+
32+
<script src="<%- url %>/vendor/reveal.js/lib/js/head.min.js"></script>
33+
<script src="<%- url %>/vendor/reveal.js/js/reveal.js"></script>
34+
<script src="<%- url %>/vendor/string.min.js"></script>
35+
<script src="<%- url %>/vendor/xss/dist/xss.min.js"></script>
36+
<script src="<%- url %>/js/render.js"></script>
37+
38+
<script>
39+
if (typeof mixpanel !== 'undefined') mixpanel.track("enter slide");
40+
41+
var body = $(".slides").html();
42+
$(".slides").html(S(body).unescapeHTML().s);
43+
44+
function extend() {
45+
var target = {};
46+
for (var i = 0; i < arguments.length; i++) {
47+
var source = arguments[i];
48+
for (var key in source) {
49+
if (source.hasOwnProperty(key)) {
50+
target[key] = source[key];
51+
}
52+
}
53+
}
54+
return target;
55+
}
56+
57+
// Optional libraries used to extend on reveal.js
58+
var deps = [
59+
{ src: '<%- url %>/vendor/reveal.js/lib/js/classList.js', condition: function() { return !document.body.classList; } },
60+
{ src: '<%- url %>/vendor/reveal.js/plugin/markdown/marked.js', condition: function() { return !!document.querySelector('[data-markdown]'); } },
61+
{ src: '<%- url %>/js/reveal-markdown.js', condition: function() { return !!document.querySelector('[data-markdown]'); } },
62+
{ src: '<%- url %>/vendor/reveal.js/plugin/highlight/highlight.js', async: true, callback: function() { hljs.initHighlightingOnLoad(); } },
63+
{ src: '<%- url %>/vendor/reveal.js/plugin/notes/notes.js', async: true, condition: function() { return !!document.body.classList; } },
64+
{ src: '<%- url %>/vendor/reveal.js/plugin/math/math.js', async: true }
65+
];
66+
67+
// default options to init reveal.js
68+
var defaultOptions = {
69+
controls: true,
70+
progress: true,
71+
history: true,
72+
center: true,
73+
transition: 'slide',
74+
dependencies: deps
75+
};
76+
77+
// options from URL query string
78+
var queryOptions = Reveal.getQueryHash() || {};
79+
80+
var options = <%- options %>;
81+
options = extend(defaultOptions, options, queryOptions);
82+
Reveal.initialize(options);
83+
</script>
84+
</body>
85+
</html>

public/views/slide.hbs

Lines changed: 0 additions & 83 deletions
This file was deleted.

0 commit comments

Comments
 (0)