Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: goliatone/fakeful
base: 2542943956
...
head fork: goliatone/fakeful
compare: c29adad421
Checking mergeability… Don't worry, you can still create the pull request.
  • 5 commits
  • 5 files changed
  • 0 commit comments
  • 1 contributor
View
22 README.md
@@ -1,7 +1,23 @@
## TODO:
-- Output templates
-- Files: Format conversion library. Support CSV, JSON
-- Error handling
+- TODO Output JSON templates
+- TODO FileDB metadata: indexing, count
+- TODO Resources: list and details
+- TODO Routes: restful list, take in where/params
+- TODO Sanitize output file name
+- TODO Take in filename parameter!
+- DONE ~~Files: Format conversion library. Support CSV, JSON~~
+- TODO Error handling
+- TODO Uploader: provide html form
+
+## Template:
+Context, gathered from FileDB metadata and results.
+* Total count: Number
+* Results count: Number
+* Action: String
+* Action message: String
+* Result data: Array|Object
+* success: boolean
+
## Resources
- [Browser library][1]
View
3  package.json
@@ -24,6 +24,7 @@
"debug": "~0.7.4",
"multer": "^0.1.2",
"node-csv-json": "^0.2.1",
- "faker": "^1.0.0"
+ "faker": "^1.0.0",
+ "handlebars": "^2.0.0-alpha.4"
}
}
View
35 routes/restful.js
@@ -4,21 +4,43 @@ var db = require('../libs/filedb'),
express = require('express'),
router = express.Router();
+/***************************************
+ * Template handling, move to file
+ ****************************************/
+
+var Template = require('handlebars');
+Template.registerHelper('data', function(options) {
+ return JSON.stringify(options.data.root.data);
+});
+
+Template.precompileAction = function(action) {
+ var tsrc = fs.readFileSync('views/restful/' + action + '.jtpl', 'utf8');
+ Template[action] = Template.compile(tsrc);
+};
+Template.precompileAction('list');
db.idAttribute = '_index';
db.resourcesPath = 'resources/';
var routes = {};
+routes.resultHandler = function(action, res, err, result) {
+ var out = Template.list({
+ count: result.length || 1,
+ data: result
+ });
+
+ res.set('Content-Type', 'application/json');
+ res.send(200, out);
+};
+
// GET /:resource
routes.list = function(req, res, next) {
// var where = JSON.parse(req.param('where'));
// console.log(where);
// console.log('HERE')
- db(req.params.resource).find(function(err, resources) {
- res.jsonp(resources);
- });
+ db(req.params.resource).find(routes.resultHandler.bind(routes, 'list', res));
};
// POST /:resource
@@ -31,12 +53,7 @@ routes.create = function(req, res, next) {
// GET /:resource/:id
routes.read = function(req, res, next) {
// res.send('read=> resource:' + req.params.resource + ' id: ' + req.params.id);
- db(req.params.resource).findOne(+req.params.id, function(err, resource) {
- if (err) return res.json(500, {
- message: 'Error'
- });
- res.json(resource);
- });
+ db(req.params.resource).findOne(+req.params.id, routes.resultHandler.bind(routes, 'read', res));
};
// PUT /:resource/:id
View
7 routes/uploader.js
@@ -1,6 +1,7 @@
var fs = require('fs'),
Converter = require('../convert'),
express = require('express'),
+ // flattener = require('../libs/flattener'),
router = express.Router();
var DEFAULTS = {
@@ -9,7 +10,7 @@ var DEFAULTS = {
outputExtension: 'json',
uploadInputName: 'convertFile',
sanitizeFilename: function(filename) {
-
+ return filename.replace(/[^a-z0-9]/gi, '_').toLowerCase();
}
};
@@ -83,9 +84,10 @@ function _getFile(req, options) {
function _outputPath(req, file, options) {
filename = req.param(options.filenameParam, file.originalname);
+ filename = filename.replace(file.extension, options.outputExtension);
filename = options.sanitizeFilename(filename);
//TODO: WATCH OUT FOR MALFORMED PATHS!!!!!
- return options.outputDir + '/' + filename.replace(file.extension, options.outputExtension);
+ return options.outputDir + '/' + filename;
}
function _mkdirp(path) {
@@ -100,5 +102,4 @@ function _mkdirp(path) {
});
}
});
-
}
View
5 views/restful/list.jtpl
@@ -0,0 +1,5 @@
+{
+ "succes": true,
+ "count": {{count}},
+ "data": {{{data}}}
+}

No commit comments for this range

Something went wrong with that request. Please try again.