Skip to content
Browse files

Renamed templates to views and rendering properly

  • Loading branch information...
1 parent 3464d82 commit 9bbd168aa055e13bc8da6adc0bcffae003adfdf5 @twolfson committed
View
3 app.js
@@ -5,6 +5,9 @@ app.use(jojo);
app.listen(8080);
+app.set('view engine', 'ejs');
+app.set('jojo article view', 'pages/article');
+
app.get('/abba', function (req, res) {
res.send([
'Hey',
View
46 node_modules/jojo/src/jojo.js
@@ -5,6 +5,10 @@ var fs = require('fs'),
// TODO: What the fuck does this mean???
// TODO: Restore config.callouts (config should not be a local variable?)
+// TODO: Switch over to a static file creator and file watching
+
+// TODO: Implement RSS
+
/**
* jojo - 10 second blog engine for hackers (in javascript)
* @param {Object<ExpressServer>} [app] App to write to
@@ -25,21 +29,24 @@ function jojo(req, res, next) {
basepath = settings['jojo basepath'] || '/',
cwd = process.cwd(),
articleDir = settings['jojo articles'] || path.join(cwd, 'articles'),
- viewEngine = settings['jojo view engine'] || settings['view engine'] || 'jade',
- viewDir = settings['jojo view dir'],
formatEngine = settings['jojo formatter'] || 'showdown',
+ indexView = settings['jojo index view'],
+ articleView = settings['jojo article view'],
baseIndex;
// If we are in the base route
if (url === basepath) {
- // TODO: Index page with articles
- return res.send('Post summary');
+ // and there is an index view
+ if (indexView) {
+ // TODO: Index page with articles
+ return res.render(indexView, 'Post summary');
+ }
} else {
baseIndex = url.indexOf(basepath);
if (baseIndex !== -1) {
// TODO: Abstract this into a jojo.readArticles (and readArticlesSync?) function
// Otherwise, attempt to find a matching article
- fs.readdir(articleDir, function (err, fileNames) {
+ return fs.readdir(articleDir, function (err, fileNames) {
var articleUrl = url.slice(baseIndex + 1);
// If there is an error, log it and continue to the next method
@@ -108,23 +115,34 @@ function jojo(req, res, next) {
rawContent = file.slice(dblLineBreakIndex);
// Render the content via the formatter
- var content = formatter(rawContent);
-
- // Otherwise, interpret and send the article
- res.send(content);
-
- // TODO: Generate and save article object -- don't forget date, summary, content = body
+ var content = formatter(rawContent),
+ // TODO: Allow for non-json parser (e.g. yaml)
+ renderObj = JSON.parse(propsStr);
+
+ // Save the content to the renderObj
+ renderObj.content = content;
+
+ // TODO: Proper config item
+ renderObj.config = app.settings;
+
+ // If there is an articleView, render through it
+ if (articleView !== undefined) {
+ // TODO: Allow for alternative jojo render engine?
+ res.render(articleView, renderObj);
+ } else {
+ // Otherwise, use res.send
+ res.send(content);
+ }
});
} else {
// Otherwise, call the next method
next();
}
});
- } else {
- // Otherwise, call the next method
- next();
}
}
+ // Otherwise, call the next method
+ next();
}
// Sugar method for creating a server
View
2 templates/layout.ejs → views/layout.ejs
@@ -8,7 +8,7 @@
</head>
<body>
<section>
- <%= yield %>
+ <%- body %>
</section>
<footer>
powered by <a href="https://github.com/twolfson/jojo">jojo</a>
View
2 templates/pages/article.ejs → views/pages/article.ejs
@@ -5,7 +5,7 @@
</header>
<section class="content">
- <%= body %>
+ <%- content %>
</section>
<section class="comments">
View
0 templates/pages/index.ejs → views/pages/index.ejs
File renamed without changes.
View
0 templates/xml.ejs → views/xml.ejs
File renamed without changes.

0 comments on commit 9bbd168

Please sign in to comment.
Something went wrong with that request. Please try again.