Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

fixed the presentation, now multiple presentation are possible. Will …

…start writing the blog
  • Loading branch information...
commit 69ee90e1b711b5dc64a97b2e41d88c254f8c69a1 1 parent b1556f7
@jettro authored
View
78 PresentationController.js
@@ -0,0 +1,78 @@
+var presentations = [];
+
+function PresentationController() {
+}
+
+PresentationController.prototype.addPresentation = function(presentation) {
+ presentations.push(presentation);
+};
+
+PresentationController.prototype.allPresentations = function(req, res) {
+ res.render('index', {locals: {presentations:presentations}});
+};
+
+/**
+ * Renders the description page of the presentation.
+ *
+ * @param req Request object
+ * @param res Response object
+ */
+PresentationController.prototype.index = function(req, res) {
+ var presentation = obtainPresentation(req.params.urlIdentifier);
+ console.log("This is the url identifier %s", presentation.urlIdentifier);
+ res.render(presentation.urlIdentifier + '/index', {locals: {presentation: presentation}});
+};
+
+PresentationController.prototype.slide = function(req, res) {
+ var id = req.params.id;
+ var presentation = obtainPresentation(req.params.urlIdentifier);
+ var slide = presentation.slides[id - 1];
+ res.render(presentation.urlIdentifier + '/slide/' + slide.identifier,
+ {locals: {
+ numSlide:req.params.id,
+ totalSlide:presentation.slides.length,
+ titleSlide:slide.title,
+ urlIdentifier:presentation.urlIdentifier
+ }});
+};
+
+/**
+ *
+ * @param req
+ * @param res
+ */
+PresentationController.prototype.command = function(req, res) {
+ var id = req.params.id;
+ var urlIdentifier = req.params.urlIdentifier;
+ var command = req.body.command;
+ var presentation = obtainPresentation(urlIdentifier);
+ var numSlides = presentation.slides.length;
+
+ if (command == 'next' || command == 'n' || command == '') {
+ if (id < numSlides) id++;
+ } else if (command == 'previous' || command == 'p' || command == 'prev') {
+ if (id > 1) id--;
+ } else if (command == 'home') {
+ res.redirect('/');
+ return;
+ } else if (!isNaN(command)) {
+ var commandNum = parseInt(command);
+ if (commandNum > 0 && commandNum <= numSlides) id = commandNum;
+ }
+
+ res.redirect('/presentation/' + urlIdentifier + '/slide/' + id);
+};
+
+/* Helper functions */
+function obtainPresentation(urlIdentifier) {
+ var len = presentations.length;
+ for (var i = 0; i < len; i++) {
+ var presentation = presentations[i];
+ if (urlIdentifier == presentation.urlIdentifier) {
+ return presentation;
+ }
+ }
+ throw "Could not find the url: " + urlIdentifier;
+}
+
+module.exports = PresentationController;
View
45 app.js
@@ -1,16 +1,27 @@
var pub = __dirname + '/public';
var Slide = require('./slide');
var Presentation = require('./presentation');
+var PresentationController = require('./PresentationController');
var express = require('express')
, app = express.createServer();
-var presentations = [];
+var presentationController = new PresentationController();
+
var createPresentationNodejs = [];
-createPresentationNodejs.push("intro","Creating a presentation with Node.js");
-createPresentationNodejs.push("goal","Goal");
-presentations.push(new Presentation("Creating a presentation with Node.js","create-presentation-nodejs",createPresentationNodejs,
- "With this presentation I want to show a way to create a presentation without the usual tools. We are going to create our own tool during the presentation."));
+createPresentationNodejs.push(new Slide("intro","Creating a presentation with Node.js"));
+createPresentationNodejs.push(new Slide("goal","Goal"));
+createPresentationNodejs.push(new Slide("requirements","Requirements"));
+createPresentationNodejs.push(new Slide("technology","technology"));
+createPresentationNodejs.push(new Slide("urlhandling","Configure url handling"));
+createPresentationNodejs.push(new Slide("handlerequests","Handle requests"));
+createPresentationNodejs.push(new Slide("viewcontent","View content"));
+createPresentationNodejs.push(new Slide("thefuture","The Future"));
+createPresentationNodejs.push(new Slide("questions","Questions"));
+
+presentationController.addPresentation(new Presentation("Creating a presentation with Node.js","create-presentation-nodejs",createPresentationNodejs,
+ "For my work I had to prepare a short presentation of around 10 minutes. I decided to create a tool to create presentation with and present about " +
+ "it. This is the result, a short presentation showing some of the ideas."));
app.configure(function() {
app.set('view engine', 'jade');
@@ -21,24 +32,10 @@ app.configure(function() {
app.use(express.bodyParser());
});
-app.get('/', function(req, res) {
- res.render('index', {locals: {presentations:presentations}});
-});
-//app.get('/slide/:id', presentation.index);
-//app.post('/slide/:id', slide.command);
+app.get('/', presentationController.allPresentations);
+app.get('/presentation/:urlIdentifier', presentationController.index);
+app.get('/presentation/:urlIdentifier/slide/:id', presentationController.slide);
+app.post('/presentation/:urlIdentifier/slide/:id', presentationController.command);
app.listen(8018);
-console.log('Express server started on port %s', app.address().port);
-
-//function Slide() {
-
-// slides.push("Creating a presentation with Node.js",
-// "Goal",
-// "Requirements",
-// "Technology",
-// "Configure url handling",
-// "Handle requests",
-// "View content",
-// "The Future",
-// "Questions");
-//}
+console.log('Express server started on port %s', app.address().port);
View
45 presentation.js
@@ -19,56 +19,11 @@ function Presentation(title, urlIdentifier, slides, description) {
this.description = description;
}
-/**
- * Starts the presentation by rendering the first slide.
- *
- * @param req Request object
- * @param res Response object
- */
-Presentation.prototype.start = function(req,res) {
- renderSlide(req,res,1);
-};
-
-/**
- * Renders the description page of the presentation.
- *
- * @param req Request object
- * @param res Response object
- */
-Presentation.prototype.renderDescription = function(req,res) {
- res.render('description', {locals: {description:this.description}});
-};
-/**
- *
- * @param req
- * @param res
- */
-Presentation.prototype.command = function(req,res) {
- var id = req.params.id;
- var command = req.body.command;
- if (command == 'next' || command == 'n' || command == '') {
- if (id < slides.length) id++;
- } else if (command == 'previous' || command == 'p' || command == 'prev') {
- if (id > 1) id--;
- } else if (!isNaN(command)) {
- var commandNum = parseInt(command);
- if(commandNum > 0 && commandNum <= slides.length) id = commandNum;
- }
-
- console.log("Command: %s", command);
- res.redirect(this.urlIdentifier + '/slide/' + this.slides[id].identifier);
-};
Presentation.prototype.allSlides = function() {
console.log("Num slides: %s",slides.length);
return slides;
};
-
-function renderSlide(req,res,numSlide) {
- res.render('slide/num'+numSlide, {locals: {numSlide:req.params.id,totalSlide:slides.length,titleSlide:slides[numSlide-1]}});
-}
-
-
module.exports = Presentation;
View
0  public/images/logo.jpg → public/images/create-presentation-nodejs/logo.jpg
File renamed without changes
View
0  public/images/nature.jpg → public/images/create-presentation-nodejs/nature.jpg
File renamed without changes
View
0  public/images/question.jpg → ...ic/images/create-presentation-nodejs/question.jpg
File renamed without changes
View
13 public/style/main.css
@@ -2,6 +2,7 @@ html, body {
height: 100%;
padding: 0;
margin: 0;
+ /*font-size: 24pt;*/
}
blockquote {
@@ -51,6 +52,18 @@ img.shadow {
div.description {
font-size: smaller;
}
+
+div.overview .description {
+ border: 1px solid #00008b;
+ padding-left: 100px;
+ padding-right: 100px;
+ font-size: 14pt;
+}
+
+.left {
+ text-indent: 20px;
+ text-align: left;
+}
/* Positioning the different components */
#fullscreen {
min-height: 100%;
View
10 views/create-presentation-nodejs/index.jade
@@ -0,0 +1,10 @@
+#title #{presentation.title}
+
+ .overview
+ .description #{presentation.description}
+
+.left available slides
+ul
+ - each slide,index in presentation.slides
+ li
+ a(href='/presentation/' + presentation.urlIdentifier + '/slide/' + index + 1) #{slide.title}
View
17 views/create-presentation-nodejs/slide/handlerequests.jade
@@ -0,0 +1,17 @@
+pre(class="brush: js")
+ | var slides = [];
+ | function Slide() {
+ | slides.push("Creating a presentation ...",
+ | "Goal","Requirements","Technology");
+ | }
+ | Slide.prototype.index = function(req,res) {
+ | renderSlide(req,res,req.params.id);
+ | };
+ | function renderSlide(req,res,numSlide) {
+ | res.render('slide/num'+numSlide, {locals: {
+ | numSlide:req.params.id,
+ | totalSlide:slides.length,
+ | titleSlide:slides[numSlide-1]}});
+ | }
+script(type="text/JavaScript")
+ | SyntaxHighlighter.all()
View
4 views/create-presentation-nodejs/slide/intro.jade
@@ -1,4 +1,4 @@
-img(src='/images/logo.jpg')
+img(src='/images/create-presentation-nodejs/logo.jpg')
div.heading author
div.heading Jettro Coenradie
-img(src='/images/nature.jpg', class="shadow")
+img(src='/images/create-presentation-nodejs/nature.jpg', class="shadow")
View
1  views/create-presentation-nodejs/slide/questions.jade
@@ -0,0 +1 @@
+img(src='/images/' + urlIdentifier + '/question.jpg', class="shadow")
View
5 views/create-presentation-nodejs/slide/requirements.jade
@@ -0,0 +1,5 @@
+ul
+ li Use templates to layout slides
+ li Use stylesheets to style slides
+ li use command line interface to navigate between slides
+ li Use different components on slides
View
9 views/create-presentation-nodejs/slide/technology.jade
@@ -0,0 +1,9 @@
+ul
+ li
+ a(href="http://nodejs.org/") Node.js
+ li
+ a(href="http://expressjs.com/") Express.js
+ li
+ a(href="http://jade-lang.com/") Jade
+ li
+ a(href="http://alexgorbatchev.com/SyntaxHighlighter/") Syntax Highlighter
View
3  views/create-presentation-nodejs/slide/thefuture.jade
@@ -0,0 +1,3 @@
+ul
+ li replace Keynote and Powerpoint
+ li Nothing, this was just fun to do
View
9 views/create-presentation-nodejs/slide/urlhandling.jade
@@ -0,0 +1,9 @@
+pre(class="brush: js")
+ | app.get('/', function(req, res) {
+ | res.render('index',
+ | {locals: {slides:slide.allSlides()}});
+ | });
+ | app.get('/slide/:id', slide.index);
+ | app.post('/slide/:id', slide.command);
+script(type="text/JavaScript")
+ | SyntaxHighlighter.all()
View
7 views/create-presentation-nodejs/slide/viewcontent.jade
@@ -0,0 +1,7 @@
+pre(class="brush: plain")
+ | img(src='/images/logo.jpg')
+ | div.heading author
+ | div.heading Jettro Coenradie
+ | img(src='/images/nature.jpg', class="shadow")
+script(type="text/JavaScript")
+ | SyntaxHighlighter.all()
View
4 views/index.jade
@@ -1,6 +1,6 @@
div#title available presentations
ul
- - each presentation,index in presentations
+ - each presentation in presentations
li
- a(href=presentation.urlIdentifier + '/slide/' + (index + 1)) #{presentation.title}
+ a(href='/presentation/' + presentation.urlIdentifier) #{presentation.title}
div.description #{presentation.description}
View
2  views/layout.jade
@@ -20,5 +20,5 @@ html(lang="en")
div#counter
slide #{numSlide} from #{totalSlide}
div#commandline
- form(action="/slide/"+numSlide,method="POST")
+ form(action="/presentation/"+urlIdentifier+"/slide/"+numSlide,method="POST")
input(type="text", size="100", name="command", id="command")
Please sign in to comment.
Something went wrong with that request. Please try again.