Permalink
Browse files

moving some stuff around a little; starting a test suite; sorting

  • Loading branch information...
1 parent a98ac37 commit 65f291a9334c7865e54800d6d91ffe35b3078743 @brianleroux committed Mar 8, 2011
Showing with 28 additions and 7 deletions.
  1. +3 −1 { → lib}/config.js
  2. +10 −4 { → lib}/post.js
  3. 0 { → lib}/showdown.js
  4. +3 −2 server.js
  5. +12 −0 test/run.js
@@ -1,11 +1,13 @@
var express = require('express')
, app = express.createServer()
+, path = require('path')
+
app.configure(function() {
app.use(express.methodOverride())
app.use(express.bodyDecoder())
app.use(app.router)
- app.use(express.staticProvider(__dirname + '/public'))
+ app.use(express.staticProvider(path.join(__dirname, '..', 'public')))
})
app.configure('development', function(){
View
@@ -3,7 +3,7 @@ var fs = require('fs')
, path = require('path')
, md2html = require('showdown').md2html
, prettyfy = require('highlight').Highlight
-, postsPath = path.join(__dirname, '/posts');
+, postsPath = path.join(__dirname, '../posts');
var Post = function (filename) { this.filename = filename }
@@ -15,9 +15,15 @@ Post.all = function (files) {
}
Post.page = function (page) {
+ var sorter = function(a,b) {
+ var a = a.substr(0,10).replace(/-/g,'')
+ , b = b.substr(0,10).replace(/-/g,'')
+ return b-a
+ }
+
var self = this
- , files = fs.readdirSync(postsPath)
- , posts = Post.all(files).reverse()
+ , files = fs.readdirSync(postsPath).sort(sorter)
+ , posts = Post.all(files)
, count = 5
, max = Math.ceil(posts.length/count)
, cur = ~~page || 1
@@ -88,7 +94,7 @@ Post.prototype = {
},
html: function() {
// read in the post text
- var p = path.join(__dirname, "posts", this.filename)
+ var p = path.join(__dirname, "../posts", this.filename)
, t = fs.readFileSync(p).toString()
// replace the raw code blocks with prettyfied html
File renamed without changes.
View
@@ -1,4 +1,4 @@
-require.paths.unshift('.')
+require.paths.unshift('./lib')
require.paths.unshift('node_modules')
var Post = require('post').Post
@@ -13,7 +13,7 @@ app.get('/', function(req, res) {
// GET "/page/2" - lists 5 posts for the page passed
app.get("/page/:n", function(req, res) {
- res.render('index.ejs', {locals:Post.page(req.params['n'])})
+ res.render('index.ejs', {locals:Post.page(req.params.n)})
})
// GET "/2010/05/10/title-of-article" - post permalink
@@ -32,6 +32,7 @@ app.get("/rss", function(req, res) {
res.send(Post.rss())
})
+// FIXME ooooh sync method BaaaaaaAAAAAAaaaad!
// GET "/license" - diplays the WTFPL
app.get('/license', function(req, res) {
res.send(fs.readFileSync(path.join(__dirname, 'LICENSE')))
View
@@ -0,0 +1,12 @@
+require.paths.unshift(__dirname + '/../lib')
+
+var testrunner = require('nodeunit').testrunner
+, Post = require('post').Post
+
+exports['tests post'] = function(test){
+ test.ok(Post, 'post exists')
+ test.equals(Post.page(1).posts.length, 5, '5 post per page')
+ test.done()
+}
+
+testrunner.run(['test']);

0 comments on commit 65f291a

Please sign in to comment.