Last active
August 29, 2015 14:02
-
-
Save feelinc/89c84e613a0e1ff3701d to your computer and use it in GitHub Desktop.
Revisions
-
feelinc revised this gist
Jun 4, 2014 . 2 changed files with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -42,7 +42,7 @@ function aname(models, model, options, callback) { } } /* Define each resource attribute */ async.waterfall([ function(done) { setAttribute('id', model.uniqueCode); This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -42,7 +42,7 @@ function aname(models, model, options, callback) { } } /* Define each resource attribute */ setAttribute('id', model.uniqueCode); setAttribute('name'); setAttribute('slug'); -
feelinc revised this gist
Jun 4, 2014 . 2 changed files with 2 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -42,6 +42,7 @@ function aname(models, model, options, callback) { } } /* Define each resource attributes */ async.waterfall([ function(done) { setAttribute('id', model.uniqueCode); This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -42,6 +42,7 @@ function aname(models, model, options, callback) { } } /* Define each resource attributes */ setAttribute('id', model.uniqueCode); setAttribute('name'); setAttribute('slug'); -
feelinc revised this gist
Jun 4, 2014 . 2 changed files with 4 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -2,7 +2,8 @@ * Module dependencies. */ var async = require('async') , countryTemplate = require('./country') , _ = require('underscore'); function aname(models, model, options, callback) { if ( ! _.isObject(model)) { This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,6 +1,8 @@ /** * Module dependencies. */ var _ = require('underscore'); var defaultOptions = {}; function aname(models, model, options, callback) { -
feelinc revised this gist
Jun 4, 2014 . 4 changed files with 15 additions and 0 deletions.There are no files selected for viewing
File renamed without changes.File renamed without changes.This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,12 @@ /** * Module dependencies. */ var apiTemplates = require('./templates'); /* Use the simple one */ res.send(apiTemplates.aname(model)); /* Use the async one */ res.send(apiTemplates.aname(models, model, function(err, anameTemplate) { res.send(anameTemplate); })); This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,3 @@ module.exports.country = require('./country'); module.exports.city = require('./city'); module.exports.aname = require('./aname'); -
feelinc created this gist
Jun 4, 2014 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,91 @@ /** * Module dependencies. */ var async = require('async') , countryTemplate = require('./country'); function aname(models, model, options, callback) { if ( ! _.isObject(model)) { if (typeof callback != 'undefined') { callback(new Error('Model is undefined')); } else { return null; } } if (typeof options == 'function') { callback = options; options = {}; } options = _.extend(options, defaultOptions); var self = this; Object.defineProperty(this, '__data', { writable: true, enumerable: false, configurable: true, value: {} }); function setAttribute(field, value) { if (typeof value == 'undefined') { if ( ! _.has(model.__data, field)) { self.__data[field] = null; } else { self.__data[field] = model.__data[field]; } } else { self.__data[field] = value; } } async.waterfall([ function(done) { setAttribute('id', model.uniqueCode); done(null); }, function(done) { setAttribute('slug'); done(null); }, function(done) { setAttribute('name'); done(null); }, function(done) { models.countries.findOne({ where: {code: model.countryCode} }, function(err, country) { if (err) { setAttribute('country', null); return done(null); } countryTemplate(country, function(err, countryTemplate) { if (err) { setAttribute('country', null); } else { setAttribute('country', countryTemplate); } done(null); }); }); } ], function() { return callback(null, self.__data); }); return self.__data; } /** * Expose `aname`. */ module.exports = aname; This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,53 @@ /** * Module dependencies. */ var defaultOptions = {}; function aname(models, model, options, callback) { if ( ! _.isObject(model)) { if (typeof callback != 'undefined') { callback(new Error('Model is undefined')); } else { return null; } } if (typeof options == 'function') { callback = options; options = {}; } options = _.extend(options, defaultOptions); var self = this; Object.defineProperty(this, '__data', { writable: true, enumerable: false, configurable: true, value: {} }); function setAttribute(field, value) { if (typeof value == 'undefined') { if ( ! _.has(model.__data, field)) { self.__data[field] = null; } else { self.__data[field] = model.__data[field]; } } else { self.__data[field] = value; } } setAttribute('id', model.uniqueCode); setAttribute('name'); setAttribute('slug'); return self.__data; } /** * Expose `aname`. */ module.exports = aname;