Permalink
Browse files

Major formatting cleanup. Fixed failing travis test.

  • Loading branch information...
1 parent bab386f commit 3c3475e07b54dcb5c2be39a7c40b0f9acabcb5cc @dshaw committed Jun 5, 2012
Showing with 267 additions and 189 deletions.
  1. +6 −0 History.md
  2. +33 −27 blog.js
  3. +44 −23 lib/post.js
  4. +33 −12 lib/posts.js
  5. +39 −14 lib/render.js
  6. +5 −3 package.json
  7. +24 −25 test/blog.test.js
  8. +2 −2 test/fixtures/blog/index.js
  9. +57 −58 test/post.test.js
  10. +24 −25 test/render.test.js
View
@@ -1,4 +1,10 @@
+0.0.3 / 2012-06-05
+==================
+
+ * Major formatting cleanup.
+ * Fixed failing travis test.
+
0.0.2 / 2012-06-04
==================
View
60 blog.js
@@ -1,29 +1,36 @@
+/*!
+ * blogit
+ * Copyright(c) 2012 Daniel D. Shaw <dshaw@dshaw.com>
+ * MIT Licensed
+ */
+
/**
* Module dependencies.
*/
var http = require('http')
- , _ = require('lodash')
, ejs = require('ejs')
, optimist = require('optimist')
, Templar = require('templar')
, posts = require('./lib/posts')
- , defaults = { port: 9000, engine: 'ejs', posts: './posts' , templates: './templates' }
- , options = null;
+ , defaults = { port: 9000, engine: 'ejs', posts: './posts', templates: './templates' }
+ , options = null
/**
* Exports.
*/
if (module.parent) {
- module.exports = function blogit (options) {
- options || (options = {})
- options = _.extend(defaults, options)
- return blog(options)
- }
+ module.exports = function blogit (options) {
+ options || (options = {})
+ Object.keys(defaults).forEach(function (prop) {
+ if (!options[prop]) options[prop] = defaults[prop]
+ })
+ return blog(options)
+ }
} else {
- options = optimist.default(defaults).argv
- blog(options)
+ options = optimist.default(defaults).argv
+ blog(options)
}
/**
@@ -33,21 +40,20 @@ if (module.parent) {
* @return http.Server
*/
-function blog (options) {
- var templarOptions = {
- // lazy load
- engine: require(options.engine),
- folder: options.templates
- }
-
- // preload templates
- Templar.loadFolder(templarOptions.folder)
-
- return http.createServer(function (req, res) {
- posts(req, options, function (err, entries) {
- // note that this causes a sync fs hit the first time if the folder has not been loaded yet.
- res.template = Templar(req, res, templarOptions)
- res.template('layout.ejs', { entries: entries })
- })
- }).listen(options.port)
+function blog(options) {
+ var templarOptions = {
+ engine: require(options.engine) // lazy load
+ , folder: options.templates
+ }
+
+ // preload templates
+ Templar.loadFolder(templarOptions.folder)
+
+ return http.createServer(function (req, res) {
+ posts(req, options, function (err, entries) {
+ // note that this causes a sync fs hit the first time if the folder has not been loaded yet.
+ res.template = Templar(req, res, templarOptions)
+ res.template('layout.ejs', { entries:entries })
+ })
+ }).listen(options.port)
}
View
@@ -1,34 +1,55 @@
-var fs = require("fs"),
- path = require("path"),
- render = require("./render");
+/*!
+ * blogit
+ * Copyright(c) 2012 Daniel D. Shaw <dshaw@dshaw.com>
+ * MIT Licensed
+ */
+
+/**
+ * Module dependencies.
+ */
+
+var fs = require('fs')
+ , path = require('path')
+ , render = require('./render')
+
+/**
+ * Exports.
+ */
module.exports = post;
-function post (options, callback) {
- options || (options = {});
+/**
+ * Post
+ *
+ * @param options
+ * @param callback
+ */
+
+function post(options, callback) {
+ options || (options = {})
- var folder = (typeof options == "string") ? options : options.folder,
- metaFile = path.join(folder, "blog.json");
+ var folder = (typeof options == 'string') ? options : options.folder
+ , metaFile = path.join(folder, 'blog.json');
- fs.readFile(metaFile, "utf8", function (err, metadata) {
- if (err) return callback(err);
+ fs.readFile(metaFile, 'utf8', function (err, metadata) {
+ if (err) return callback(err)
- var entry = JSON.parse(metadata),
- postFile = path.join(folder, entry.file);
+ var entry = JSON.parse(metadata)
+ , postFile = path.join(folder, entry.file)
- fs.readFile(postFile, "utf8", function (err, content) {
- if (err) return callback(err);
+ fs.readFile(postFile, 'utf8', function (err, content) {
+ if (err) return callback(err)
- entry.folder = folder;
- entry.format = "md";
- entry.content = content;
+ entry.folder = folder
+ entry.format = 'md'
+ entry.content = content
- render(content, function (err, html) {
- if (err) return callback(err);
+ render(content, function (err, html) {
+ if (err) return callback(err)
- entry.html = html;
- callback(null, entry)
- });
- });
- });
+ entry.html = html
+ callback(null, entry)
+ })
+ })
+ })
}
View
@@ -1,35 +1,56 @@
-var fs = require("fs")
- , path = require("path")
- , async = require("async")
- , post = require("./post.js")
+/*!
+ * blogit
+ * Copyright(c) 2012 Daniel D. Shaw <dshaw@dshaw.com>
+ * MIT Licensed
+ */
+
+/**
+ * Module dependencies.
+ */
+
+var fs = require('fs')
+ , path = require('path')
+ , async = require('async')
+ , post = require('./post.js')
, debug = console.log
-module.exports = posts;
+/**
+ * Exports.
+ */
+
+module.exports = posts
+
+/**
+ * Posts
+ *
+ * @param req
+ * @param options
+ * @param callback
+ */
function posts (req, options, callback) {
if (typeof callback === 'undefined') {
callback = options
options = {}
}
- var folder = (typeof options == "string") ? options : options.posts,
- metaFile = path.join(folder, "index.json");
+ var folder = (typeof options == 'string') ? options : options.posts
+ , metaFile = path.join(folder, 'index.json')
- fs.readFile(metaFile, "utf8", function (err, metadata) {
- if (err) return callback(err);
+ fs.readFile(metaFile, 'utf8', function (err, metadata) {
+ if (err) return callback(err)
var entryIds = JSON.parse(metadata)
async.map(entryIds, function (id, cb) {
var postDir = path.join(options.posts, id)
-
post(postDir, function (err, entry) {
cb(null, entry)
})
}, function(err, entries) {
if (err) return callback(err)
- //debug("entries", entries)
+ //debug('entries', entries)
callback(null, entries)
})
- });
+ })
}
View
@@ -1,28 +1,53 @@
-var fs = require("fs"),
- path = require("path"),
- marked = require("marked");
+/*!
+ * blogit
+ * Copyright(c) 2012 Daniel D. Shaw <dshaw@dshaw.com>
+ * MIT Licensed
+ */
-module.exports = render;
+/**
+ * Module dependencies.
+ */
+
+var fs = require('fs')
+ , path = require('path')
+ , marked = require('marked')
+
+/**
+ * Exports.
+ */
+
+module.exports = render
+
+/**
+ * Configuration.
+ */
marked.setOptions({
- gfm: true,
- pedantic: false,
- sanitize: true
+ gfm: true
+ , pedantic: false
+ , sanitize: true
// ,
// callback for code highlighter
// highlight: function(code, lang) {
-// if (lang === "js") {
+// if (lang === 'js') {
// return javascriptHighlighter(code);
// }
-// return code;
+// return code
// }
-});
+})
+
+/**
+ * Render
+ *
+ * @param options
+ * @param callback
+ */
function render(options, callback) {
- options || (options = {});
+ options || (options = {})
- var data = (typeof options == "string") ? options : options.data,
- html = marked(data);
+ var data = (typeof options == 'string') ? options : options.data
+ , html = marked(data)
- callback(null, html)
+ callback(null, html)
}
View
@@ -1,10 +1,13 @@
{
"name": "blogit",
- "version": "0.0.2",
+ "version": "0.0.3",
"description": "Node.js git based blog engine.",
"keywords": [
"blog",
- "git"
+ "blogging",
+ "git",
+ "md",
+ "markdown"
],
"author": "Daniel D. Shaw <dshaw@dshaw.com> (http://dshaw.com)",
"repository": {
@@ -24,7 +27,6 @@
"marked": "~0.2.5",
"optimist": "~0.3.4",
"ejs": "~0.7.1",
- "lodash": "~0.2.2",
"async": "~0.1.22"
},
"devDependencies": {
View
@@ -1,29 +1,28 @@
-var assert = require("assert"),
- mocha = require("mocha"),
- request = require("request"),
- Blog = require("../blog"),
- debug = console.log;
+var assert = require('assert')
+ , mocha = require('mocha')
+ , request = require('request')
+ , blogit = require('../blog')
+ , debug = console.log
-describe("Blog", function () {
- var port = 9000,
- blog;
+describe('Blog', function () {
+ var port = 9000
+ , blog
- before(function (done) {
- blog = Blog({ port: port, posts: "./test/fixtures/blog/posts", templates: "./test/fixtures/blog/templates" });
+ before(function (done) {
+ blog = blogit({ port: port, posts: './test/fixtures/blog/posts', templates: './test/fixtures/blog/templates' })
- blog.on('listening', function () {
- //debug("Blog listening.")
- done()
- })
- });
+ blog.on('listening', function () {
+ //debug('Blog listening.')
+ done()
+ })
+ })
- it("should serve up the blog", function(done) {
- request("http://localhost:9000", function (err, res, body) {
- //debug(body);
- assert.equal(typeof body, "string");
- assert.equal(body.slice(0, 15), "<!DOCTYPE html>");
- done();
- })
- });
-
-});
+ it('should serve up the blog', function (done) {
+ request('http://localhost:9000', function (err, res, body) {
+ //debug(body);
+ assert.equal(typeof body, 'string')
+ assert.equal(body.slice(0, 15), '<!DOCTYPE html>')
+ done()
+ })
+ })
+})
Oops, something went wrong.

0 comments on commit 3c3475e

Please sign in to comment.