Last active
December 14, 2015 19:49
-
-
Save isao/5139054 to your computer and use it in GitHub Desktop.
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 characters
// side note: configs and routes can have YUI params, and actions can attach | |
// to a Y instance... | |
var fs = require('fs'), | |
path = require('path'); | |
function appconfig(pathname, way, res) { | |
res.server.configs[way.parts.filename] = loadJson(pathname); | |
} | |
function mojitconfig(pathname, way, res) { | |
var conf = loadJson(pathname); | |
addSubProp(res.server.mojits, way.parts.mojit, way.parts.filename, conf); | |
} | |
function controller(pathname, way, res) { | |
addSubProp(res.client.mojits, way.parts.mojit, 'controller', pathname); | |
console.log(88, res.client.mojits[way.parts.mojit]); | |
// if('server' === way.parts.selector) { | |
// addSubProp(res.server.mojits, way.parts.mojit, 'controller', pathname); | |
// } else { | |
// addSubProp(res.client.mojits, way.parts.mojit, 'controller', pathname); | |
// } | |
} | |
function model(pathname, way, res) { | |
} | |
function view(pathname, way, res) { | |
} | |
function binder(pathname, way, res) { | |
} | |
function staticasset(pathname, way, res) { | |
var fileparts = path.basename(way.parts.subpath).split('.'); | |
res.server.assets[pathname] = { | |
mime: fileparts.pop()// todo: extension => mimetype | |
}; | |
if(fileparts.length > 1) { | |
addSubProp(res.server.selectors, fileparts[1], pathname); | |
} | |
} | |
function other(pathname, way, res) { | |
} | |
function noop(pathname, way, res) { | |
//console.log(pathname, way.parts, way.param); | |
} | |
function loadJson(pathname) { | |
var abspath = path.resolve(pathname), | |
out = false; | |
try { | |
out = require(abspath); | |
} catch(err) { | |
console.error('error loading "%s"', abspath); | |
} | |
return out; | |
} | |
/** | |
* @param {object} must already exist | |
* @param {mixed} property to add | |
* @param {mixed} sub-property to add | |
* @param {mixed} optional value to add | |
*/ | |
function addSubProp(obj, record, key, val) { | |
if(!obj[record]) { | |
obj[record] = {}; | |
} | |
obj[record][key] = undefined !== val ? val : null; | |
} | |
module.exports = { | |
appconfig: appconfig, | |
mojitconfig: mojitconfig, | |
staticasset: staticasset, | |
controller: controller,//controller, | |
model: noop,//model, | |
view: noop,//view, | |
binder: noop,//binder, | |
other: noop | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment