Comparing version 0.2.12 to 0.2.13
24
index.js
@@ -15,3 +15,3 @@ /*! | ||
// lib | ||
// Import lib | ||
var fs = require('fs'); | ||
@@ -24,7 +24,8 @@ var path = require('path'); | ||
// variable declaration | ||
// Variable declaration | ||
var CWD = process.cwd(); | ||
/** | ||
* file exists sync | ||
* File exists sync | ||
* | ||
* @param src | ||
@@ -50,3 +51,4 @@ * @returns {boolean} | ||
/** | ||
* assert port | ||
* Assert port | ||
* | ||
* @param port | ||
@@ -60,3 +62,4 @@ * @returns {boolean} | ||
/** | ||
* format watch | ||
* Format watch | ||
* | ||
* @param watch | ||
@@ -83,3 +86,4 @@ * @returns {Array} | ||
/** | ||
* run | ||
* Run | ||
* | ||
* @param port | ||
@@ -90,5 +94,5 @@ */ | ||
// file config | ||
// File config | ||
if (fileExistsSync(yml)) { | ||
// parse yaml | ||
// Parse yaml | ||
var source = fs.readFileSync(yml); | ||
@@ -101,3 +105,3 @@ | ||
// format options | ||
// Format options | ||
yml.root = CWD; | ||
@@ -111,4 +115,4 @@ yml.layout = yml.layout || null; | ||
// run fengine | ||
// Run fengine | ||
new Fengine(yml); | ||
}; |
@@ -15,231 +15,165 @@ /*! | ||
// events | ||
// ----------------- | ||
// thanks to: | ||
// - https://github.com/documentcloud/backbone/blob/master/backbone.js | ||
// - https://github.com/joyent/node/blob/master/lib/events.js | ||
// Array slice | ||
var slice = Array.prototype.slice; | ||
// Regular expression used to split event strings | ||
var eventSplitter = /\s+/; | ||
// helpers | ||
/** | ||
* object keys | ||
* @param object | ||
* @returns {Array} | ||
* Faster apply | ||
* | ||
* @param {Function} func | ||
* @param {any} context | ||
* @param {Array} args | ||
* call is faster than apply, optimize less than 6 args | ||
* https://github.com/micro-js/apply | ||
* http://blog.csdn.net/zhengyinhui100/article/details/7837127 | ||
*/ | ||
var keys = Object.keys ? Object.keys : function(object) { | ||
var result = []; | ||
for (var name in object) { | ||
if (object.hasOwnProperty(name)) { | ||
result.push(name); | ||
} | ||
function apply(func, context, args) { | ||
switch (args.length) { | ||
// Faster | ||
case 0: | ||
return func.call(context); | ||
case 1: | ||
return func.call(context, args[0]); | ||
case 2: | ||
return func.call(context, args[0], args[1]); | ||
case 3: | ||
return func.call(context, args[0], args[1], args[2]); | ||
default: | ||
// Slower | ||
return func.apply(context, args); | ||
} | ||
return result; | ||
}; | ||
/** | ||
* execute callbacks | ||
* @param list | ||
* @param args | ||
* @param context | ||
* @returns {boolean} | ||
*/ | ||
function triggerEvents(list, args, context) { | ||
var pass = true; | ||
if (list) { | ||
var i = 0; | ||
var a1 = args[0]; | ||
var a2 = args[1]; | ||
var a3 = args[2]; | ||
var l = list.length; | ||
// call is faster than apply, optimize less than 3 argu | ||
// http://blog.csdn.net/zhengyinhui100/article/details/7837127 | ||
switch (args.length) { | ||
case 0: | ||
for (; i < l; i += 2) { | ||
pass = list[i].call(list[i + 1] || context) !== false && pass; | ||
} | ||
break; | ||
case 1: | ||
for (; i < l; i += 2) { | ||
pass = list[i].call(list[i + 1] || context, a1) !== false && pass; | ||
} | ||
break; | ||
case 2: | ||
for (; i < l; i += 2) { | ||
pass = list[i].call(list[i + 1] || context, a1, a2) !== false && pass; | ||
} | ||
break; | ||
case 3: | ||
for (; i < l; i += 2) { | ||
pass = list[i].call(list[i + 1] || context, a1, a2, a3) !== false && pass; | ||
} | ||
break; | ||
default: | ||
for (; i < l; i += 2) { | ||
pass = list[i].apply(list[i + 1] || context, args) !== false && pass; | ||
} | ||
break; | ||
} | ||
} | ||
// trigger will return false if one of the callbacks return false | ||
return pass; | ||
} | ||
/** | ||
* a module that can be mixed in to *any object* in order to provide it | ||
* with custom events. You may bind with `on` or remove with `off` callback | ||
* functions to an event; `trigger`-ing an event fires all callbacks in | ||
* succession. | ||
* var object = new Events(); | ||
* object.on('expand', function(){ alert('expanded'); }); | ||
* object.trigger('expand'); | ||
* Events | ||
* | ||
* @constructor | ||
*/ | ||
function Events() { | ||
// constructor | ||
// Keep this empty so it's easier to inherit from | ||
// (via https://github.com/lipsmack from https://github.com/scottcorgan/tiny-emitter/issues/3) | ||
} | ||
/** | ||
* bind one or more space separated events, `events`, to a `callback` | ||
* function. Passing `"all"` will bind the callback to all events fired. | ||
* @param events | ||
* @param callback | ||
* @param context | ||
* @returns {Events} | ||
*/ | ||
Events.prototype.on = function(events, callback, context) { | ||
var that = this; | ||
var cache, event, list; | ||
Events.prototype = { | ||
/** | ||
* Bind event | ||
* | ||
* @param {any} name | ||
* @param {any} listener | ||
* @param {any} context | ||
* @returns {Events} | ||
*/ | ||
on: function(name, listener, context) { | ||
var self = this; | ||
var events = self.__events || (self.__events = {}); | ||
if (!callback) return that; | ||
context = arguments.length < 3 ? self : context; | ||
events = events.split(eventSplitter); | ||
cache = that.__events || (that.__events = {}); | ||
(events[name] || (events[name] = [])).push({ | ||
fn: listener, | ||
context: context | ||
}); | ||
while (event = events.shift()) { | ||
list = cache[event] || (cache[event] = []); | ||
return self; | ||
}, | ||
/** | ||
* Bind event only emit once | ||
* | ||
* @param {any} name | ||
* @param {any} listener | ||
* @param {any} context | ||
* @returns {Events} | ||
*/ | ||
once: function(name, listener, context) { | ||
var self = this; | ||
list.push(callback, context); | ||
} | ||
function feedback() { | ||
self.off(name, feedback); | ||
apply(listener, this, arguments); | ||
}; | ||
return that; | ||
}; | ||
return self.on(name, feedback, context); | ||
}, | ||
/** | ||
* Emit event | ||
* | ||
* @param {any} name | ||
* @param {any} [...param] | ||
* @returns {Events} | ||
*/ | ||
emit: function(name) { | ||
var context = this; | ||
var data = slice.call(arguments, 1); | ||
var events = context.__events || (context.__events = {}); | ||
var listeners = events[name] || []; | ||
/** | ||
* bind a event only emit once | ||
* @param events | ||
* @param callback | ||
* @param context | ||
*/ | ||
Events.prototype.once = function(events, callback, context) { | ||
var that = this; | ||
var result; | ||
var listener; | ||
var returned; | ||
var cb = function() { | ||
that.off(events, cb); | ||
callback.apply(context || that, arguments); | ||
}; | ||
// Emit events | ||
for (var i = 0, length = listeners.length; i < length; i++) { | ||
listener = listeners[i]; | ||
result = apply(listener.fn, listener.context, data); | ||
return that.on(events, cb, context); | ||
}; | ||
/** | ||
* remove one or many callbacks. If `context` is null, removes all callbacks | ||
* with that function. If `callback` is null, removes all callbacks for the | ||
* event. If `events` is null, removes all bound callbacks for all events. | ||
* @param events | ||
* @param callback | ||
* @param context | ||
* @returns {Events} | ||
*/ | ||
Events.prototype.off = function(events, callback, context) { | ||
var that = this; | ||
var cache, event, list, i; | ||
// no events, or removing *all* events. | ||
if (!(cache = that.__events)) return that; | ||
// remove all events | ||
if (!(events || callback || context)) { | ||
delete that.__events; | ||
return that; | ||
} | ||
events = events ? events.split(eventSplitter) : keys(cache); | ||
// loop through the callback list, splicing where appropriate. | ||
while (event = events.shift()) { | ||
list = cache[event]; | ||
if (!list) continue; | ||
if (!(callback || context)) { | ||
delete cache[event]; | ||
continue; | ||
} | ||
for (i = list.length - 2; i >= 0; i -= 2) { | ||
if (!(callback && list[i] !== callback | ||
|| context && list[i + 1] !== context)) { | ||
list.splice(i, 2); | ||
break; | ||
if (returned !== false) { | ||
returned = result; | ||
} | ||
} | ||
} | ||
return that; | ||
}; | ||
return returned; | ||
}, | ||
/** | ||
* Remove event | ||
* | ||
* @param {any} name | ||
* @param {any} listener | ||
* @param {any} context | ||
* @returns {Events} | ||
*/ | ||
off: function(name, listener, context) { | ||
var self = this; | ||
var length = arguments.length; | ||
var events = self.__events || (self.__events = {}); | ||
/** | ||
* emit one or many events, firing all bound callbacks. Callbacks are | ||
* passed the same arguments as `trigger` is, apart from the event name | ||
* (unless you're listening on `"all"`, which will cause your callback to | ||
* receive the true name of the event as the first argument). | ||
* @param events | ||
* @returns {*} | ||
*/ | ||
Events.prototype.emit = function(events) { | ||
var rest = []; | ||
var that = this; | ||
var returned = true; | ||
var cache, event, all, list, i, len; | ||
switch (length) { | ||
case 0: | ||
self.__events = {}; | ||
break; | ||
case 1: | ||
delete events[name]; | ||
break; | ||
default: | ||
if (listener) { | ||
var listeners = events[name]; | ||
if (!(cache = that.__events)) return that; | ||
if (listeners) { | ||
context = length < 3 ? self : context; | ||
length = listeners.length; | ||
events = events.split(eventSplitter); | ||
var event; | ||
// fill up `rest` with the callback arguments. Since we're only copying | ||
// the tail of `arguments`, a loop is much faster than Array#slice. | ||
for (i = 1, len = arguments.length; i < len; i++) { | ||
rest[i - 1] = arguments[i]; | ||
} | ||
for (var i = 0; i < length; i++) { | ||
event = listeners[i]; | ||
// for each event, walk through the list of callbacks twice, first to | ||
// trigger the event, then to trigger any `"all"` callbacks. | ||
while (event = events.shift()) { | ||
// copy callback lists to prevent modification. | ||
if (all = cache.all) all = all.slice(); | ||
if (event.fn === listener && event.context === context) { | ||
listeners.splice(i, 1); | ||
break; | ||
} | ||
} | ||
if (list = cache[event]) list = list.slice(); | ||
// execute event callbacks except one named "all" | ||
if (event !== 'all') { | ||
returned = triggerEvents(list, rest, that) && returned; | ||
// Remove event from queue to prevent memory leak | ||
// Suggested by https://github.com/lazd | ||
// Ref: https://github.com/scottcorgan/tiny-emitter/commit/c6ebfaa9bc973b33d110a84a307742b7cf94c953#commitcomment-5024910 | ||
if (!listeners.length) { | ||
delete events[name]; | ||
} | ||
} | ||
} | ||
break; | ||
} | ||
// execute "all" callbacks. | ||
returned = triggerEvents(all, [event].concat(rest), that) && returned; | ||
return self; | ||
} | ||
return returned; | ||
}; | ||
// exports | ||
module.exports = Events; |
@@ -13,3 +13,3 @@ /*! | ||
// lib | ||
// Import lib | ||
var os = require('os'); | ||
@@ -28,3 +28,3 @@ var fs = require('fs'); | ||
// variable declaration | ||
// Variable declaration | ||
var CWD = process.cwd(); | ||
@@ -52,2 +52,3 @@ var NUMCPUS = os.cpus().length; | ||
/** | ||
* prototype | ||
* | ||
@@ -165,3 +166,3 @@ * @type {{ | ||
// log | ||
// Show log | ||
console.log(message); | ||
@@ -173,3 +174,3 @@ }, | ||
// file send | ||
// File send | ||
var send = new FileSend(requset, { | ||
@@ -180,6 +181,6 @@ root: options.root | ||
}).on('dir', function(realpath, stats, next) { | ||
// set Content-Type | ||
// Set Content-Type | ||
send.setHeader('Content-Type', 'text/html; charset=UTF-8'); | ||
// read dir | ||
// Read dir | ||
fs.readdir(realpath, function(error, files) { | ||
@@ -189,3 +190,3 @@ if (error) { | ||
} else { | ||
// response | ||
// Response | ||
next(context.dir(files, send.url)); | ||
@@ -196,3 +197,3 @@ } | ||
// send | ||
// Send | ||
return send; | ||
@@ -204,9 +205,9 @@ }, | ||
// set status code | ||
// Set status code | ||
response.statusCode = 200; | ||
// set Content-Type | ||
// Set Content-Type | ||
response.setHeader('Content-Type', mime.lookup(pathname)); | ||
// transform | ||
// Transform | ||
var transform = new Transform(pathname, source, { | ||
@@ -219,3 +220,3 @@ root: options.base, | ||
// data | ||
// Event data | ||
transform.on('data', function(data) { | ||
@@ -225,3 +226,3 @@ response.write(data); | ||
// error | ||
// Event error | ||
transform.on('error', function(event, file, command) { | ||
@@ -251,3 +252,3 @@ var type; | ||
// send message | ||
// Send message | ||
process.send({ | ||
@@ -259,3 +260,3 @@ type: type, | ||
// end | ||
// Event end | ||
transform.on('end', function() { | ||
@@ -265,3 +266,3 @@ response.end(); | ||
// transform | ||
// Transform | ||
return transform; | ||
@@ -273,17 +274,17 @@ }, | ||
// master thread | ||
// Master thread | ||
if (cluster.isMaster) { | ||
// worker | ||
// Worker thread | ||
var worker; | ||
// create thread | ||
// Create thread | ||
for (var i = 0; i < NUMCPUS; i++) { | ||
// fork | ||
// Fork | ||
worker = cluster.fork(); | ||
// listen event | ||
// Listen event | ||
worker.on('message', context.log); | ||
} | ||
} else { | ||
// create server | ||
// Create server | ||
var server = http.createServer(function(requset, response) { | ||
@@ -315,3 +316,3 @@ response.setHeader('Server', 'Fengine/' + pkg.version); | ||
// is file | ||
// Is file | ||
if (stats.isFile()) { | ||
@@ -354,3 +355,3 @@ fs.readFile(pathname, function(error, source) { | ||
// start listening | ||
// Start listening | ||
server.on('listening', function() { | ||
@@ -363,3 +364,3 @@ var server = this.address(); | ||
// message | ||
// Message | ||
process.send({ | ||
@@ -371,5 +372,5 @@ type: 'info', | ||
// error | ||
// Event error | ||
server.on('error', function(error) { | ||
// message | ||
// Message | ||
process.send({ | ||
@@ -380,9 +381,9 @@ type: 'error', | ||
// exit | ||
// Exit | ||
process.exit(); | ||
}); | ||
// close | ||
// Event close | ||
server.on('close', function() { | ||
// message | ||
// Message | ||
process.send({ | ||
@@ -393,7 +394,7 @@ type: 'info', | ||
// exit | ||
// Exit | ||
process.exit(); | ||
}); | ||
// listen | ||
// Listen | ||
if (options.hostname) { | ||
@@ -405,3 +406,3 @@ server.listen(options.port, options.hostname); | ||
// return | ||
// Return server | ||
return server; | ||
@@ -412,3 +413,3 @@ } | ||
// exports | ||
// Exports | ||
module.exports = Fengine; |
@@ -13,3 +13,3 @@ /*! | ||
// lib | ||
// Import lib | ||
var fs = require('fs'); | ||
@@ -20,3 +20,3 @@ var path = require('path'); | ||
// variable declaration | ||
// Variable declaration | ||
var DIRECTIVE = { | ||
@@ -35,3 +35,3 @@ SKIP: 'skip', | ||
var CWD = process.cwd(); | ||
// default options | ||
// Default options | ||
var DEFAULTOPTIONS = { | ||
@@ -62,2 +62,3 @@ root: CWD, | ||
* assert | ||
* | ||
* @type {{ | ||
@@ -72,2 +73,3 @@ * tags: assert.tags, | ||
* tags | ||
* | ||
* @param context | ||
@@ -106,2 +108,3 @@ */ | ||
* data | ||
* | ||
* @param context | ||
@@ -137,2 +140,3 @@ */ | ||
* layout | ||
* | ||
* @param context | ||
@@ -155,2 +159,3 @@ */ | ||
* Transform | ||
* | ||
* @param src | ||
@@ -162,8 +167,8 @@ * @param source | ||
function Transform(src, source, options) { | ||
// buffer | ||
if (source instanceof Buffer) { | ||
// Buffer | ||
if (Buffer.isBuffer(source)) { | ||
source = source.toString(); | ||
} | ||
// src must be a string | ||
// Src must be a string | ||
if (!util.string(src)) { | ||
@@ -173,3 +178,3 @@ throw new TypeError('src must be a file path.'); | ||
// source must be a string | ||
// Source must be a string | ||
if (!util.string(source)) { | ||
@@ -179,6 +184,6 @@ throw new TypeError('source must be a string or buffer.'); | ||
// context | ||
// Context | ||
var context = this; | ||
// property | ||
// Property | ||
context.index = 0; | ||
@@ -194,3 +199,3 @@ context.slot = null; | ||
// path | ||
// Path | ||
context.src = path.resolve(CWD, src); | ||
@@ -202,3 +207,3 @@ context.dirname = path.dirname(context.src); | ||
// transform | ||
// Transform start | ||
context.transform(); | ||
@@ -209,2 +214,3 @@ } | ||
* extend | ||
* | ||
* @type {Events} | ||
@@ -217,3 +223,4 @@ */ | ||
/** | ||
* is same tags | ||
* Is same tags | ||
* | ||
* @returns {boolean} | ||
@@ -230,3 +237,3 @@ */ | ||
/** | ||
* create separator | ||
* Create separator | ||
*/ | ||
@@ -237,3 +244,3 @@ Transform.prototype.createSeparator = function() { | ||
// main file init tags and data | ||
// Main file init tags and data | ||
if (context.isMaster) { | ||
@@ -244,3 +251,3 @@ assert.tags(context); | ||
// tags and directive | ||
// The tags and directive | ||
var unique = {}; | ||
@@ -252,3 +259,3 @@ var dataDirective = []; | ||
// create data directive | ||
// Create data directive | ||
for (var data in options.data) { | ||
@@ -261,3 +268,3 @@ if (options.data.hasOwnProperty(data)) { | ||
// trim data | ||
// Trim data | ||
var trimmed = data.trim(); | ||
@@ -279,3 +286,3 @@ | ||
// separator regexp | ||
// Separator regexp | ||
context.separator = { | ||
@@ -321,2 +328,3 @@ transform: new RegExp( | ||
* resolve | ||
* | ||
* @param url | ||
@@ -337,2 +345,3 @@ * @returns {string} | ||
* write | ||
* | ||
* @param data | ||
@@ -345,6 +354,6 @@ * @param [type] | ||
// data type | ||
// Data type | ||
type = type || 'context'; | ||
// cache slotted | ||
// Cache slotted | ||
if (context.layout && type !== 'layout') { | ||
@@ -354,3 +363,3 @@ context.layout.slotted += data; | ||
// emit data event | ||
// Emit data event | ||
context.emit(EVENTS.DATA, data, type); | ||
@@ -363,2 +372,3 @@ | ||
* end | ||
* | ||
* @param data | ||
@@ -371,3 +381,3 @@ * @param [type] | ||
// write data | ||
// Write data | ||
if (arguments.length) { | ||
@@ -377,3 +387,3 @@ context.write(data, type); | ||
// delete prop | ||
// Delete prop | ||
context.slot = null; | ||
@@ -384,3 +394,3 @@ context.slotted = ''; | ||
// emit end event | ||
// Emit end event | ||
context.emit(EVENTS.END); | ||
@@ -393,2 +403,3 @@ | ||
* next | ||
* | ||
* @param data | ||
@@ -400,3 +411,3 @@ * @param [type] | ||
// write data | ||
// Write data | ||
if (arguments.length) { | ||
@@ -406,5 +417,5 @@ context.write(data, type); | ||
// last match | ||
// Last match | ||
if (!context.exec()) { | ||
// cache slotted | ||
// Cache slotted | ||
if (context.isLayout() && context.layout) { | ||
@@ -414,12 +425,12 @@ context.layout.slotted += context.slotted; | ||
// write end data | ||
// Write end data | ||
context.write(context.source.substring(context.index)); | ||
// set index to end | ||
// Set index to end | ||
context.index = context.source.length; | ||
// finished | ||
// Finished | ||
context.finished = true; | ||
// call layout next or context end | ||
// Call layout next or context end | ||
if (context.layout) { | ||
@@ -435,2 +446,3 @@ context.layout.next(); | ||
* thread | ||
* | ||
* @param src | ||
@@ -444,3 +456,3 @@ * @param source | ||
// reset layout | ||
// Reset layout | ||
options.layout = null; | ||
@@ -450,3 +462,3 @@ | ||
// not main file | ||
// Not main file | ||
thread.isMaster = false; | ||
@@ -459,2 +471,3 @@ | ||
* error | ||
* | ||
* @param type | ||
@@ -470,2 +483,3 @@ * @param context | ||
* io error | ||
* | ||
* @param context | ||
@@ -480,2 +494,3 @@ * @param message | ||
* circle error | ||
* | ||
* @param context | ||
@@ -489,3 +504,4 @@ * @param message | ||
/** | ||
* is skip | ||
* Is skip | ||
* | ||
* @returns {boolean} | ||
@@ -501,3 +517,4 @@ */ | ||
/** | ||
* is layout | ||
* Is layout | ||
* | ||
* @returns {boolean} | ||
@@ -510,3 +527,4 @@ */ | ||
/** | ||
* is cyclic layout | ||
* Is cyclic layout | ||
* | ||
* @param layout | ||
@@ -518,3 +536,3 @@ * @returns {boolean} | ||
// layout is null | ||
// Layout is null | ||
if (!layout) return false; | ||
@@ -528,3 +546,3 @@ | ||
// loop | ||
// Loop | ||
while (slot) { | ||
@@ -542,3 +560,4 @@ if (layout === slot.src) { | ||
/** | ||
* is cyclic include | ||
* Is cyclic include | ||
* | ||
* @param src | ||
@@ -550,3 +569,3 @@ * @returns {boolean} | ||
// src is null | ||
// Src is null | ||
if (!src) return false; | ||
@@ -560,3 +579,3 @@ | ||
// loop | ||
// Loop | ||
while (parent) { | ||
@@ -574,3 +593,4 @@ if (src === parent.src) { | ||
/** | ||
* match layout | ||
* Match layout | ||
* | ||
* @returns {{ | ||
@@ -612,3 +632,4 @@ * src: *, | ||
/** | ||
* set layout | ||
* Set layout | ||
* | ||
* @param command | ||
@@ -619,3 +640,3 @@ * @param src | ||
Transform.prototype.setLayout = function(command, src) { | ||
// read layout | ||
// Read layout | ||
fs.readFile(src, function(error, source) { | ||
@@ -630,12 +651,12 @@ var context = this; | ||
// read layout | ||
// Read layout | ||
var layout = context.thread(src, source); | ||
// set context layout | ||
// Set context layout | ||
context.layout = layout; | ||
// set layout slot | ||
// Set layout slot | ||
layout.slot = context; | ||
// data event | ||
// Data event | ||
layout.on(EVENTS.DATA, function(data) { | ||
@@ -645,3 +666,3 @@ context.write(data, 'layout'); | ||
// circle event | ||
// Circle event | ||
layout.on(EVENTS.ERROR, function(type, file, message) { | ||
@@ -651,3 +672,3 @@ context.error(type, file, message); | ||
// end event | ||
// End event | ||
layout.once(EVENTS.END, function() { | ||
@@ -662,3 +683,3 @@ context.end(); | ||
/** | ||
* skip layout | ||
* Skip layout | ||
*/ | ||
@@ -674,3 +695,4 @@ Transform.prototype.skipLayout = function() { | ||
/** | ||
* include file | ||
* Include file | ||
* | ||
* @param command | ||
@@ -681,3 +703,3 @@ * @param src | ||
Transform.prototype.include = function(command, src) { | ||
// read include | ||
// Read include | ||
fs.readFile(src, function(error, source) { | ||
@@ -693,9 +715,9 @@ var context = this; | ||
// read include | ||
// Read include | ||
var include = context.thread(src, source); | ||
// set parent | ||
// Set parent | ||
include.parent = context; | ||
// data event | ||
// Data event | ||
include.on(EVENTS.DATA, function(data) { | ||
@@ -705,3 +727,3 @@ context.write(data, 'include'); | ||
// circle event | ||
// Circle event | ||
include.on(EVENTS.ERROR, function(type, file, message) { | ||
@@ -711,3 +733,3 @@ context.error(type, file, message); | ||
// end event | ||
// End event | ||
include.once(EVENTS.END, function() { | ||
@@ -722,3 +744,4 @@ context.next(); | ||
/** | ||
* print data | ||
* Print data | ||
* | ||
* @param command | ||
@@ -757,12 +780,12 @@ * @param data | ||
// matched string | ||
// Matched string | ||
match = match[0]; | ||
// write source before match | ||
// Write source before match | ||
context.write(context.source.substring(context.index, index)); | ||
// set index | ||
// Set index | ||
context.index = index + match.length; | ||
// switch type | ||
// Switch type | ||
switch (type) { | ||
@@ -773,6 +796,6 @@ case 'data': | ||
case 'directive': | ||
// ignore case | ||
// Ignore case | ||
var commandIgnoreCase = command.toLowerCase(); | ||
// command switch | ||
// Command switch | ||
switch (commandIgnoreCase) { | ||
@@ -794,3 +817,3 @@ case DIRECTIVE.SLOT: | ||
// cyclic include | ||
// Cyclic include | ||
if (context.isCyclicInclude(src)) { | ||
@@ -803,3 +826,3 @@ context.circle(context, match); | ||
// include | ||
// Include | ||
context.include(match, src); | ||
@@ -824,14 +847,14 @@ } else { | ||
Transform.prototype.transform = function() { | ||
// start transform in next tick | ||
// Start transform in next tick | ||
process.nextTick(function() { | ||
var context = this; | ||
// create separator | ||
// Create separator | ||
context.createSeparator(); | ||
// has skip command | ||
// Has skip command | ||
if (context.isSkip()) { | ||
context.write(context.source); | ||
// set index to end | ||
// Set index to end | ||
context.index = context.source.length; | ||
@@ -842,3 +865,3 @@ | ||
// main file init layout | ||
// Main file init layout | ||
if (context.isMaster) { | ||
@@ -848,3 +871,3 @@ assert.layout(context); | ||
// match layout | ||
// Match layout | ||
var layout = context.matchLayout(); | ||
@@ -861,3 +884,3 @@ var src = layout.src; | ||
// skip layout | ||
// Skip layout | ||
context.skipLayout(); | ||
@@ -868,3 +891,3 @@ } | ||
// exports | ||
// Exports | ||
module.exports = Transform; |
@@ -13,3 +13,3 @@ /*! | ||
// prototype method | ||
// Prototype method | ||
var toString = Object.prototype.toString; | ||
@@ -21,3 +21,3 @@ var getPrototypeOf = Object.getPrototypeOf; | ||
// variable declaration | ||
// Variable declaration | ||
var BACKSLASH_RE = /\\/g; | ||
@@ -31,3 +31,4 @@ var DOT_RE = /\/\.\//g; | ||
/** | ||
* is array | ||
* Is array | ||
* | ||
* @type {Function} | ||
@@ -41,2 +42,3 @@ */ | ||
* type | ||
* | ||
* @param value | ||
@@ -46,3 +48,3 @@ * @returns {*} | ||
function type(value) { | ||
// get real type | ||
// Get real type | ||
var type = toString.call(value).toLowerCase(); | ||
@@ -52,5 +54,5 @@ | ||
// nan and infinity | ||
// Is nan and infinity | ||
if (type === 'number') { | ||
// nan | ||
// Is nan | ||
if (value !== value) { | ||
@@ -60,3 +62,3 @@ return 'nan'; | ||
// infinity | ||
// Is infinity | ||
if (value === Infinity || value === -Infinity) { | ||
@@ -67,3 +69,3 @@ return 'infinity'; | ||
// return type | ||
// Return type | ||
return type; | ||
@@ -73,3 +75,4 @@ } | ||
/** | ||
* is function | ||
* Is function | ||
* | ||
* @param value | ||
@@ -83,3 +86,4 @@ * @returns {boolean} | ||
/** | ||
* is plain object | ||
* Is plain object | ||
* | ||
* @param value | ||
@@ -91,3 +95,3 @@ * @returns {*} | ||
// detect obvious negatives | ||
// Detect obvious negatives | ||
if (!value || type(value) !== 'object') { | ||
@@ -97,6 +101,6 @@ return false; | ||
// proto | ||
// Proto | ||
proto = getPrototypeOf(value); | ||
// objects with no prototype (e.g., `Object.create( null )`) are plain | ||
// Objects with no prototype (e.g., `Object.create( null )`) are plain | ||
if (!proto) { | ||
@@ -106,3 +110,3 @@ return true; | ||
// objects with prototype are plain iff they were constructed by a global Object function | ||
// Objects with prototype are plain iff they were constructed by a global Object function | ||
ctor = hasOwnProperty.call(proto, 'constructor') && proto.constructor; | ||
@@ -115,2 +119,3 @@ | ||
* extend | ||
* | ||
* @returns {*} | ||
@@ -125,10 +130,10 @@ */ | ||
// handle a deep copy situation | ||
// Handle a deep copy situation | ||
if (typeof target === 'boolean') { | ||
deep = target; | ||
// skip the boolean and the target | ||
// Skip the boolean and the target | ||
target = arguments[i++] || {}; | ||
} | ||
// handle case when target is a string or something (possible in deep copy) | ||
// Handle case when target is a string or something (possible in deep copy) | ||
if (typeof target !== 'object' && !isFunction(target)) { | ||
@@ -139,7 +144,7 @@ target = {}; | ||
for (; i < length; i++) { | ||
// only deal with non-null/undefined values | ||
// Only deal with non-null/undefined values | ||
if ((options = arguments[i]) != null) { | ||
// extend the base object | ||
// Extend the base object | ||
for (name in options) { | ||
// only copy own property | ||
// Only copy own property | ||
if (!options.hasOwnProperty(name)) { | ||
@@ -152,3 +157,3 @@ continue; | ||
// prevent never-ending loop | ||
// Prevent never-ending loop | ||
if (target === copy) { | ||
@@ -158,3 +163,3 @@ continue; | ||
// recurse if we're merging plain objects or arrays | ||
// Recurse if we're merging plain objects or arrays | ||
if (deep && copy && (isPlainObject(copy) || (copyIsArray = isArray(copy)))) { | ||
@@ -168,6 +173,6 @@ if (copyIsArray) { | ||
// never move original objects, clone them | ||
// Never move original objects, clone them | ||
target[name] = extend(deep, clone, copy); | ||
} else if (copy !== undefined) { | ||
// don't bring in undefined values | ||
// Don't bring in undefined values | ||
target[name] = copy; | ||
@@ -179,3 +184,3 @@ } | ||
// return the modified object | ||
// Return the modified object | ||
return target; | ||
@@ -185,3 +190,4 @@ } | ||
/** | ||
* string for regex | ||
* String for regex | ||
* | ||
* @param string | ||
@@ -194,3 +200,3 @@ * @returns {void|XML} | ||
// exports | ||
// Exports | ||
module.exports = { | ||
@@ -209,3 +215,4 @@ type: type, | ||
/** | ||
* normalize path | ||
* Normalize path | ||
* | ||
* @param path | ||
@@ -235,7 +242,8 @@ * @returns {string} | ||
// get path | ||
// Get path | ||
return path; | ||
}, | ||
/** | ||
* date format | ||
* Date format | ||
* | ||
* @param date | ||
@@ -253,9 +261,9 @@ * @param format | ||
var map = { | ||
'M': date.getMonth() + 1, // month | ||
'd': date.getDate(), // date | ||
'h': date.getHours(), // hours | ||
'm': date.getMinutes(), // minutes | ||
's': date.getSeconds(), // seconds | ||
'q': Math.floor((date.getMonth() + 3) / 3), // quarter | ||
'S': date.getMilliseconds() // milliseconds | ||
'M': date.getMonth() + 1, // Month | ||
'd': date.getDate(), // Date | ||
'h': date.getHours(), // Hours | ||
'm': date.getMinutes(), // Minutes | ||
's': date.getSeconds(), // Seconds | ||
'q': Math.floor((date.getMonth() + 3) / 3), // Quarter | ||
'S': date.getMilliseconds() // Milliseconds | ||
}; | ||
@@ -283,3 +291,4 @@ | ||
/** | ||
* is out bound | ||
* Is out bound | ||
* | ||
* @param path | ||
@@ -302,3 +311,4 @@ * @param root | ||
/** | ||
* decode uri | ||
* Decode uri | ||
* | ||
* @param uri | ||
@@ -315,4 +325,5 @@ * @returns {*} | ||
/** | ||
* converts a number to a string with | ||
* Converts a number to a string with | ||
* a given amount of leading characters. | ||
* | ||
* @param {number} number Number to convert. | ||
@@ -319,0 +330,0 @@ * @param {number} width Amount of leading characters to prepend. |
{ | ||
"name": "fengine", | ||
"version": "0.2.12", | ||
"version": "0.2.13", | ||
"description": "A development tool for f2e", | ||
@@ -5,0 +5,0 @@ "author": { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
115836
1559