Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
stevenschobert committed Aug 7, 2014
1 parent 1f773c4 commit 5108eda
Show file tree
Hide file tree
Showing 6 changed files with 172 additions and 0 deletions.
18 changes: 18 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
default: install build start

install:
@npm install

clean:
@echo "clean task not implemented"

build:
@echo "build task not implemented"

start:
@npm start

test:
@npm test

.PHONY: install clean build start test
8 changes: 8 additions & 0 deletions example/http.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
var Pimm = require('../'),
repl = require('repl'),
prompt = repl.start({prompt: '> '}),

http = new Pimm({dir: __dirname});

prompt.context.Pimm = Pimm;
prompt.context.http = http;
39 changes: 39 additions & 0 deletions lib/pimm.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
(function() {
'use strict';

var keylime = require('keylime'),
mach = require('mach'),
_ = require('lodash'),
p = require('path'),

Directory = require('./pimm/support/directory'),
Path = require('./pimm/support/path'),

Pimm = keylime('Pimm');

Pimm
.attr('dir', '.' + p.sep)
.attr('port', 3000)

.attr('_stack', mach.stack)

.method('_loadControllers', function loadControllers() {
var controllerPath = new Path({value: this.dir}).resolve('controllers'),
controllerDir = new Directory({path: controllerPath});

console.log(controllerPath);
return controllerDir.load()
.then(function() {
_.forIn(controllerDir.files, function(path, Controller) {
console.log(path);
console.log(Controller);
});
});
})

.method('start', function start() {
mach.serve(this._stack, this.port);
});

module.exports = Pimm;
}());
42 changes: 42 additions & 0 deletions lib/pimm/support/directory.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
(function() {
'use strict';

var keylime = require('keylime'),
Promise = require('bluebird'),
fs = require('fs'),
recursiveReaddir = require('recursive-readdir'),
Path = require('./path'),
readdir = Promise.promisify(recursiveReaddir),
readfile = Promise.promisify(fs.readFile),

Directory = keylime('Directory');

Directory
.attr('path', './')
.attr('files', {})

.method('load', function load() {
var path = new Path({value: this.path});

return Promise.bind(this)
.then(function() {
return readdir(path.resolve());
})
.map(function processFile(file) {
var filePath = new Path({value: file}),
filePiece = filePath.relative(this.path),
fileContent = (filePath.hasExtension('js')) ? require(filePath.resolve()) : readfile(filePath.resolve());
return Promise.join(filePiece, fileContent, function(name, content) {
return {
name: name,
content: content
};
});
})
.each(function populateFile(file) {
this.files[file.name] = file.content;
});
});

module.exports = Directory;
}());
32 changes: 32 additions & 0 deletions lib/pimm/support/path.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
(function() {
'use strict';

var keylime = require('keylime'),
p = require('path'),
_ = require('lodash'),

Path = keylime('Path');

Path
.attr('value', '')

.method('resolve', function resolve() {
return p.resolve(_.partial(p.join, this.value).apply(this, arguments));
})

.method('relative', function relative() {
var from = '.' + p.sep,
prefix = '.' + p.sep;
return prefix + p.relative(from, _.partial(p.join, this.value).apply(this, arguments));
})

.method('extension', function extension() {
return p.extname(this.value);
})

.method('hasExtension', function hasExtension(val) {
return (new RegExp(val, 'i').test(this.extension()));
});

module.exports = Path;
}());
33 changes: 33 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"name": "pimm",
"version": "0.0.0",
"homepage": "https://github.com/stevenschobert/pimm",
"description": "An easy-going web framework for Node.",
"main": "lib/pimm.js",
"scripts": {
"test": "./node_modules/.bin/jshint --reporter ./node_modules/jshint-stylish/stylish.js lib/** test/** && ./node_modules/.bin/mocha -R spec test/**"
},
"repository": {
"type": "git",
"url": "git://github.com/stevenschobert/pimm.git"
},
"author": "Steven Schobert <[email protected]>",
"license": "MIT",
"bugs": {
"url": "https://github.com/stevenschobert/pimm/issues"
},
"dependencies": {
"bluebird": "^2.2.2",
"keylime": "git+ssh://[email protected]:ovenbits/keylime",
"lodash": "^2.4.1",
"mach": "^0.12.0",
"recursive-readdir": "^1.1.3"
},
"devDependencies": {
"assert": "^1.1.1",
"mocha": "^1.21.4",
"jshint-stylish": "^0.4.0",
"jshint": "^2.5.2",
"supertest": "^0.13.0"
}
}

0 comments on commit 5108eda

Please sign in to comment.